Re: How do I export a class?
a way to do this is to use dllexport / dllimport.
for example:
class __declspec(dllimport) CMyEdit: public CEdit{...} //used in your main program
class __declspec(dllexport) CMyEdit: public CEdit{...} // used in your DLL.
Don't forget to add the lib file of your DLL in the setting of your main project.
dllimport / dllexport "loads" and "unloads" the DLL implicitly in your main prog., so you don't have to care about this.
you may find more infos in the docs.
HTH.
K.
Ash to ash and clay to clay, if the enemy doesn't get you, your own folk may.
Re: How do I export a class?
To expand a little on what Karl wrote, I often do this in DLLs.
#define DllExport __declspec(dllexport)
#define DllImport __declspec(dllimport)
#ifdef MY_LIBRARY_CODE // define this in project of DLL
#define DllClass DllExport
#else
#define DllClass DllImport
#endif
class DllClass CMyClass
{
...
};
When MY_LIBRARY_CODE is defined, which should only be in the library's
project, then DllClass is exported. All other times it is imported.
Also, check out post 1286 on this board. It was on page 44 for me.
You can then use the class just like any other class.
Re: How do I export a class?
I had the same question about Importing Classes from a DLL. Thanks!
Now my question is: Can this import be done explicitly (i.e. using GetProcAddress etc...) and not requiring the .LIB file?
Thanks,
Jeff
Re: How do I export a class?
Technically, yes but it is far from easy.
Each member of the class will usually be exported individually
and if you throw in name-mangling things get very difficult.
Try "dumpbin /exports SomeLibrary.dll" to see what I mean.
There have been several posts and a few KB articles on this
topic. They might be more encouraging than I am.
prescribed way to export a class
extern "C" AFX_EXT_API void WINAPI YourDllName();
class AFX_EXT_CLASS CYourClassName : public xxxx
{
}
Then in your main program, you include the .lib from the dll,
include the header for the class taht you are exporting and just use it as normal.
Rate this post if helped.
You can export a class from an *.exe just as....
well as a *.dll.
#ifdef YOUR_EXE_BUILD
#define YOUR_EXPORT_API __declspec(dllexport) // works with *.exe's too
#else
#define YOUR_EXPORT_API __declspec(dllimport)
#endif // YOUR_EXE_BUILD
class YOUR_EXPORT_API CExample
{
// normal
};
And an import library will be made for your *.exe just like one for a *.dll. You can also export from an *.exe using a .def file, just like a *.dll as well.