Link to home
Start Free TrialLog in
Avatar of pratish
pratish

asked on

Importing Classes from DLLs

Hi all!
I want to define a class and its members in a DLL and then export the class so that I may use the class in another application. I have exported the class using __declspec(dllexport) macro in a regular DLL(not extension DLL - the class is not derived from any of the MFC classes).
Now, I link the the DLL in a different application thru its .lib file and import the class using the __declspec(dllimport) macro. The catch is, I am not able to create objects of the imported class unless I dont include the header file from the dll in which the class is defined. How do I create objects of a class exported from a DLL without using the .h file? - u see, i only want to ship the DLL and the LIB file for the exported class.

-thanx
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jasonclarke
jasonclarke

jkr, aren't you missing the point, the question says without shipping the header file.

the only way to do this that I know of without supplying the header file is to use a .def file.  This is extremely unpleasant for C++ classes because you must put mangled names into the .def file.

You should maybe think about why you don't want to ship the .h file.  It is by far the easiest thing to do, using the approach jkr describes.

You can make use of the Proxy class technique to just provide a public interface and hide all implementation details if you need to.
Avatar of pratish

ASKER

Maybe u r correct Jason,

I'll give the .def approach a try(if thats the only way out) and if things go very ugly, then i think i'll settle down with jkr's approach and ship the header file as well.

Thanx
Avatar of pratish

ASKER

Maybe u r correct Jason,

I'll give the .def approach a try(if thats the only way out) and if things go very ugly, then i think i'll settle down with jkr's approach and ship the header file as well. Lemme know if there's any other way out.

Thanx
>>i only want to ship the DLL and the
>>LIB file for the exported class

Using a .def file only makes the import names available - but if you actually want to access methods of these classes, you *have* to ship the header file, as the parameter lists etc. have to be known to the calling program as well... a C++ DLL without a header file is almost unusable...