Setting up this DLL o' mine

Started by
1 comment, last by Zipster 23 years, 6 months ago
Lets see, I have a dll that i made. it compiles fine. I have all the functions int the DLL files declared as follows: void __declspec(dllexport) blahblahblah()... int __declspec(dllexport) more_blah(void** pointer).... etc. So, for me to use this DLL, ill have to create a header file (not included in the DLL), that looks like this: void __declspec(dllimport) blahblahblah()... int __declspec(dllimport) more_blah(void** pointer).... is this correct, the way i have it set up? Also, how would I create a data abstraction (such as a class) and be able to export it without having to actually define an instance of it to export (from within a DLL/Import Library)?
Advertisement
Yep, that''s the way to do it for functions.

For classes, just put the _declspec(dllexport) macro inbetween class and class name in your headers, i.e:

class _declspec(dllexport) myClass
{
...etc
}

However, this would then require two sets of headers - one for internal use, and one for use in import. So, do something like this:

#ifdef MYDLL_EXPORT
#define MYDLL_API _declspec(dllexport)
#else
#define MYDLL_API _declspec(dllimport)
#endif

And then declare your classes thus:

class MYDLL_API myClass
{
}

And only #define MYDLL_EXPORT when you are building your dll.

Hope this helps,

Henry
Actually, I just have

#define DllExport __declspec(dllexport)
#define DllImport __declspec(dllimport)

But thx anyway. I can''t use __declspec(dllexport) on a constant initialized value tho, which kinda sucks, like:

const int __declspec(dllexport) ON = 1;

This topic is closed to new replies.

Advertisement