Export / Import C++ Managed Classes

A

amirbehzadan

Hello,

I am writing some C++ classes and want to export them as .dll files so
other users can import them and use the methods I have provided in
those classes. I have two types of classes : unmanaged (or regular
classes) and managed (__gc classes). I already know how to use
"__declspec(dllexport)" to export and "__declspec(dllimport)" to import
"unmanaged" classes. However I dont know how to export "managed"
classes since this method doesnt work for them.

Can anyone help me with this ?

Regards,
Amir
 
J

Jochen Kalmbach [MVP]

Hi amirbehzadan!
I am writing some C++ classes and want to export them as .dll files so
other users can import them and use the methods I have provided in
those classes. I have two types of classes : unmanaged (or regular
classes) and managed (__gc classes). I already know how to use
"__declspec(dllexport)" to export and "__declspec(dllimport)" to import
"unmanaged" classes. However I dont know how to export "managed"
classes since this method doesnt work for them.

Just declare it as "public" and put it into a namespace. That´s it.

Any other managed programming language can simply reference the DLL and
use your class.

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
A

amirbehzadan

Hi Jochen,

Thanks a lot. That solved the problem of creating the DLL file. Now
when I am using the corresponding header and library file in a test
application to use that DLL file, I get a number of "unresolved tokens"
that most of them point to the functions inside the imported managed
class. Examples are :

Test error LNK2020: unresolved token (0600000B) TCM::.ctor
Test error LNK2020: unresolved token (0600000C) TCM::Finalize
Test error LNK2020: unresolved token (0600000E) TCM::Start
Test error LNK2020: unresolved token (0600000F) TCM::Stop
Test error LNK2020: unresolved token (06000010) TCM::BytesInRQ
Test error LNK2020: unresolved token (06000011) TCM::stdString
Test fatal error LNK1120: 6 unresolved externals

the last four functions are functions inside the imported managed class
TCM.

Thanks,
Amir
 
J

Jochen Kalmbach [MVP]

Hi amirbehzadan!
Thanks a lot. That solved the problem of creating the DLL file. Now
when I am using the corresponding header and library file in a test
application to use that DLL file, I get a number of "unresolved tokens"

You *must not* use header and lib-files!!!

Just add (VC2003):
#using <MyManagedDll.dll>


Or in VS2005, add the reference to your project properties
(Common|References).


--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top