|
I've been reading some messages and articles, but I haven't found any example of using a DLL to store classes and then use them linking it dynamically in an exe.
At present, I'm using Delay Load to create instances of my classes, but I don't want to use .lib and .h files.
Is it possible to do that?
Thanks in advance.
|
|
|
|
|
|
Cedric,
I think you might be overshooting the target here. COM is one thing, but you might also simply export a C++ coded class with the __declspec(dllexport) statement in MSDEV, and import it with __declspec(dllimport). Of course that technique requires C++ to be used on both sides (unlike COM).
Bernd
|
|
|
|
|
Yep, that's rigtht, but in this case, you'll have to include the .h and the .cpp files from all your classes in the project then!
If you use a 'kindof' COM model, you'll just have to include the .h file from the interface (just virtual functions), and then use a global function from the dll that returns a pointer to the base class that is in fact 'a pointer to a specific child class'. So, in that way, you don't have to include .h and .cpp files from all your derived classes. The client program doesn't even know the existence of the derived classes: he just call virtual functions from the base class that are redirected to functions from the derived class.
Or, I perhaps misunderstood the question ?
|
|
|
|
|
You didn't misunderstand the question, but the DLL export statement...
You have to include header files in both sides (there is no type library query or so), but the code stays on the server side (DLL). Just look at the whole thing as if it were a good old function library, only with dynamic linking, classes, C++, and so forth.
This is not a "kindof COM", this is a C++ class library. Plain, simple, and useful.
Bernd
|
|
|
|
|
But I think, that exporting anything C++ means that the another compiler might not be able to import it (due to different non-standard name mangling) and you must use the same compiler then. But I can be wrong.
|
|
|
|
|
Agreed. Exporting a class from a DLL does not allow for multi-language use, or multi-compiler use.
I agree COM is the more powerful tool in places, but it also is an overkill in many others.
Bernd
|
|
|
|
|
Thanks for all the answers, but I'm not looking for a COM interface. Instead of that, I'd like to use plain DLL's, but as I've just read, I'd have to include .cpp files on both sides and that's what I don't want to do.
All I want is to give a DLL without giving even the header files. I don't want any .h or .lib.
Hope I've explained better this time.
Thanks in advance!!
__________________________
Fernando de Francisco Cano
__________________________
|
|
|
|
|
Fernando,
if you want to ship a library, then you must allow clients to connect to that library. One technique is to use static linkage. To do that, you will ship a .lib file and a header file. Another technique is dynamic linkage, for which you will ship a .DLL and a header file. Finally, you could ship COM controls, which come in the physical form of .DLL or .OCX files. You don't need to include header files because COM provides query mechanisms, but essentially in any case you cannot just ship something without letting your user's compiler know what it is.
You seek the impossible unless you don't wish your DLL to be of any use - in which case you could just ship a DLL without a header file
Bernd
|
|
|
|
|
... oh, and in order to get this clarified: you do not ship source code (except header files), unless you wish to. None of the three techniques I listed requires distribution of .cpp files, no whatsoever.
B.
|
|
|
|
|
First of all, thanks a lot for your soon answer .
I have to ship .DLL + .h file if I want to use Dynamic linking (as you wrote earlier) but... am I able to use classes from this .DLL? I mean without using COM.
Another question: Must I ship the whole .h file? I mean, do I have to ship private, protected and public zones? I'd like to hide private data at least.
Thanks in advance.
__________________________
Fernando de Francisco Cano
__________________________
|
|
|
|
|
I used extended style LVS_EX_HEADERDRAGDROP.
So, I can drag-drop a header.
How to get notification of drag-drop of headers in CListCtrl
whenever it was changed?
Thanks.
|
|
|
|
|
Derive a class from CListCtrl and handle the notifications in the derived class.
|
|
|
|
|
Hi,
Did any one know how to get a message in Visual C++ when a smart card was inserted or removed ?
Thanks Very much
|
|
|
|
|
The CPropertyPage constructor looks like this
CPropertyPage( UINT nIDTemplate, UINT nIDCaption = 0 );
Now the second argument (the UINT nIDCaption) comes from the string table. What if I wanna create multiple tabs from code without knowing how many I'm gonna open. I can't make a string table entry for every tab I wanna make cause I don't know how many I'm going to create. So how can I modify the string that I give to an ID from code ???? Is that possible ?
|
|
|
|
|
It is 0 by default, so only use the first parameter, and the dialog name will be used.
Then, once you have created the property page, do :
CPropertyPage mypage;
mypage.pszTitle="My Title";
And you're done.
~RaGE();
|
|
|
|
|
You don't have to specify a value for the second argument (default will be 0). In this case, the title will be taken from the dialog template title!
|
|
|
|
|
Hi all, does anyone know how can i test(by code of course) if the computer supports the Power-off (ATX board) feature, or only the Shutdown ("Its now safe to turn off your computer") Feature?
|
|
|
|
|
I would like to write a dll that can be used with VC, VB, Delphi, and Java. The thing is that I can write the source code only with VC or Win32 API, and I don't know how these other languages work. Could I get some feedback on this topic?
By the way, I do know that MFC based dlls work only for MFC based programs.
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
You probably want to write a COM DLL. COM is the standard way of letting any language talk to a software component. Depending on what you need to do you might get away with writing a C# assembly (? I think)
For better information on COM check out that message board or check out Mike Dunn's article "Introduction to COM - What It Is and How to Use It.".
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
Thank you very much for your quick reply. I was hoping that I didn't have to write a COM DLL but if there is no other way to do it then COM DLL it is.
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
It depends also of what kind of stuff you want the Dll to do! If you need the dll to generate classes, then you have to write a COM dll. But if the dll just hold some functions, you can use a normal dll (and you can also use MFC dll). It works with Visual Basic but I'm not sure for the other language (I suppose that works too). You have to be aware of calling conventions !!
|
|
|
|
|
Actually I just want to use some normal functions. Is there a website where I can read about the calling conventions?
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
Hmmmm, yes, it must probably exist some but I don't know where ! Perhaps make a search on this site and on google!
In fact, the calling convention (stdcall, cdecl, ...) is the way the stack is cleared (by the client or by the dll). If you call a function from an executable that has not the same calling convention from the function inside the dll, you will have some problems! But you can change this calling convention within the client program (or within the dll) so they can match.
|
|
|
|
|
thank you Cedric.
// Afterall I realized that even my comment lines have bugs
|
|
|
|