Connecting Tech Pros Worldwide Help | Site Map

Export / Import C++ Managed Classes

amirbehzadan@hotmail.com
Guest
 
Posts: n/a
#1: May 26 '06
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

Jochen Kalmbach [MVP]
Guest
 
Posts: n/a
#2: May 26 '06

re: Export / Import C++ Managed Classes


Hi amirbehzadan!
[color=blue]
> 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.[/color]

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/
amirbehzadan@hotmail.com
Guest
 
Posts: n/a
#3: May 26 '06

re: Export / Import C++ Managed Classes


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

Jochen Kalmbach [MVP]
Guest
 
Posts: n/a
#4: May 27 '06

re: Export / Import C++ Managed Classes


Hi amirbehzadan!
[color=blue]
> 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"[/color]

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/
Closed Thread