Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2006

Tip: Looking for answers? Try searching our database.

Export / Import C++ Managed Classes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
amirbehzadan@hotmail.com - 26 May 2006 20:07 GMT
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] - 26 May 2006 20:33 GMT
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
[quoted text clipped - 3 lines]
> "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.

Signature

Greetings
  Jochen

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

amirbehzadan@hotmail.com - 26 May 2006 20:43 GMT
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] - 27 May 2006 07:59 GMT
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).

Signature

Greetings
  Jochen

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.