|
-
Sep 27th, 2002, 03:35 PM
#1
Thread Starter
New Member
C++ Class in windows dll
Is it possible to put a c++ class into a windows dll and use it outside of the dll? If it is possible, how?
-
Sep 27th, 2002, 04:33 PM
#2
It is possible by using __declspec(dllexport) or __declspec(dllimport) respectively. But a dll created with e.g. VC++ can only be used by VC++ again.
You must use implicit linking for this (list the .lib file that is generated during compilation of the DLL in the import library list of the project where you want to use the class).
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 27th, 2002, 06:15 PM
#3
Fanatic Member
Or just create a static library and use the pragma in the file or project that uses it, like this:
PHP Code:
#pragma comment(lib, "library.lib")
on MSVC++
-
Sep 28th, 2002, 07:02 AM
#4
Put that pragma into the class header file, that's the way MFC does it, it's quite useful.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 28th, 2002, 07:48 PM
#5
Fanatic Member
but wouldnt that be a problem, i mean when you are compiling the the .lib? hmm, i do that too but I dont understand it very well, so to be safe, I started putting it in the .cpp of my main file. I guess I was right at first, I didnt see this in MFC or anywhere, I wanted a way to make sure a lib file was included automatically when you #include a header, so I searched google and found that MSVC has that pragma, and I was like WOWWWW... lol. But that tip didnt say where to put it, so I experimented and it was like everything worked but there where some weird things going on. So which way is the safe and correct way? The way MFC does it or the way I did it, and do you know of a pragma tutorial?
Thanks,
MoMad
-
Sep 29th, 2002, 01:02 PM
#6
Since you usually have a special symbol defined when you compile a dll (that turns all DLLAPI or whatever macros into __declspec(dllexport) instead of import etc.) you can say
#ifdef DLL_INTERNAL_COMPILE
#define DLLAPI __declspec(dllexport)
#else
#define DLLAPI __declspec(dllimport)
#pragma comment(lib, "mylib.lib")
#endif
Put it in some central header file that it is included by each and every file of your dll.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 29th, 2002, 01:06 PM
#7
Fanatic Member
O cool, but I never use the pragma with the dll, I almost always use dynamic linking (LoadLibrary) when dealing with dynamic link libraries, I only use the pragma with the static link libraries.
-
Sep 29th, 2002, 01:46 PM
#8
#ifndef LIB_INTERNAL_COMPILE
#pragma comment(lib, "mylib.lib")
#endif
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 29th, 2002, 01:52 PM
#9
Fanatic Member
Originally posted by CornedBee
#ifndef LIB_INTERNAL_COMPILE
#pragma comment(lib, "mylib.lib")
#endif
Huh? WHats LIB_INTERNAL_COMPILE??
-
Sep 29th, 2002, 04:54 PM
#10
A symbol you define via a /d switch when compiling your static library. The name is up to you of course.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|