The solution is simple. Just declare the constructor for CMyClass private so that anyone cannot use it without CMyInterface::CreateMe.
Unfortunately you cannot declare a destructor private so you still can use : delete pCMyClassObj.
Normally I have exported only function from my dlls, so I have used .def file,.lib file and the include file of my exported functions to make it.
But if I use def file I have to use a particular sintax to export a class?
It's enough to provide to client application the include file where I had declared my class?
If I use your indications, could I use .def file or I have to use LoadLibrary() function to load my dll which export my class?
Thank you in advance.
sorry for my English.
well, i'm new to this topic and tried to write a simple dll that exports a class via static functions as described in the tutorial, but i have trouble importing them into the client app. (linker errors for CreateMe() and DestroyMe()) i guess that's because i'm not very experienced with Dlls, i'd really appreciate if someone could help me there, maybe writing a very simple DLL + client app and then posting it here or maybe mail it to me.
This is my problem....
The ActiveX control i wrote, in MFC, returns false from InitInstance() when user selects 'no' to a message box; i'm planning to replace this later with End User License Agreement.
Whenever InitInstance returns FALSE, it will be called by NTDLL again. Which means, InitInstance() is called twice and the message box is displayed twice in the event user select 'no' at the first time.
My test SDI/MDI/Dialog does not exhibit this behaviour; seems to me that this is a special case for ActiveX controls only.
Any info on that?
I have read all your 3 articles with big interrests.
I use Dll's a lot by myself, but I have one problem.
Because that I uses Dll's a lot in my program, I have arranged the things in this way:
Developer Studio copies the lib file, to C:\Program Files\Microsoft Visual Studio\VC98\Lib.
Developer Studio copies the header file, to C:\Program Files\Microsoft Visual Studio\VC98\Include.
Developer Studio copies the dll file, to C:\WINDOWS\SYSTEM32. In this way, all my upcomming programs can find the dll's on my computer, and they are always updated.
But now we comes to the problem I have...... I want the name, on the dll in the release version, to be called FileName.dll and FileNamed.dll in the Debug Version. But I have terrible problems. I have tried to change the Output Filename in the linker settings, but then I got a LNK4070 error, which tells me, that the filename mentioned in .EXP file, is different than the filename gaved to the linker. It is a rather simple problem/qustion, but so far, I haven't found a soloution yet.
Does anybody have a answer to me, or are you doing this debug/release handling in another way
there is an issue using the dll. Actually, my requirement goes like this:
One MDI application with a splitter window.
The left view is there in the exe and it has also a user defined class
class Splitter:public CSplitterWnd
Now, the right views have to be added by the dll by using the SplitterWnd::CreateView() function by querying CRuntimeClass* information about the views that dll contains say
Now this view has to be loaded once the view is stored in a Map varibale which is there with the exe. The view is also stored. This is the case when exe knows when the view has to be loaded.
If suppose, the dll view contains a Button clicking which there should be another view loaded on the right pane of the splitter window. Now, since the map of views is there with the exe, dll can again give the info about the new view and then the exe can create a view for the dll.
The problem is:
There is a callback function with the exe.
The exe registers this callback with the dll.
the dll calls this function when it needs to load the view on the right pane of splitter window because the splitter window object is also there with the exe and the createview functionality is also there with the exe. But, the callback function which is already decalred static in the exe can't use the non-static member functions i.e. neither the splitterwindow object nor any other function so the view can't be created. there is some design issues here. Can you suggest me some way out..