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++ / October 2005

Tip: Looking for answers? Try searching our database.

unmanged libs and /clr

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kilroytrout@gmail.com - 08 Oct 2005 07:50 GMT
When trying to use some unmanged C++ libs in a VS 2005 Release
Candidate Windows Forms (/clr) project, I found that any dynamic
initialization in the lib's global STL objects (perhaps other C++
objects as well) create an exception at startup. Has anyone seen this
or know a workaround?

For example create a simple /clr C++ console app:

#include "unmanaged.h"

int main(array<System::String ^> ^args)
{
   unmanaged_foo(); // empty func. to get linker to include library
globals
   return 0;
}

Then create an unmanaged static lib with the header...

// unmanaged.h

 void unmanaged_foo();

And the cpp file...

// unmanaged.cpp

 #include <vector>

 std::vector<int> stlVect;
 void unmanaged_foo(){}

Compile the lib, and then compile and link the console app with the
unmanaged lib using /MDd (or /MD) and run. You'll get an exception in
the dynamic initializer for stlVect. I know in VS 03 there were some
issues with the and mixed mode C++ DLL's, but this is an EXE.

Tell me I'm missing something. It seems likely that various static libs
developers might use will have this problem if they're native and
linked into /clr projects. Recompiling them to /clr is not always an a
viable option.

--jeff
Holger Grund - 08 Oct 2005 09:52 GMT
> When trying to use some unmanged C++ libs in a VS 2005 Release
> Candidate Windows Forms (/clr) project, I found that any dynamic
> initialization in the lib's global STL objects (perhaps other C++
> objects as well) create an exception at startup. Has anyone seen this
> or know a workaround?

IIRC, this is due to the signature of your main function. The
managed signature, __clrcall (array<String^>^) that is, doesn't
really work right with mixed mode yet.

Just use the ordinary (int,char*[]) signature for now.

-hg
kilroytrout@gmail.com - 08 Oct 2005 18:02 GMT
Indeed that worked for a console /clr app, and I would have never
guessed that was the culprit. But I still get the exception when
linking this unmanaged lib to a Windows forms app.

For Windows Forms, I couldn't make it (int,char*[]) without a linker
error (invalid /clr entry point), but I tried main(void) and I still
get the exception. Do you have any suggestion for a WinForms app in
this scenario?

--thanks,

jeff
kilroytrout@gmail.com - 08 Oct 2005 18:15 GMT
Ok I answered my follup question to you about Winforms. I changed the
signature to int __stdcall WinMain(int,char*[]) and no more exception
the the unmanged lib's initializers.

Many thanks.

jeff

Rate this thread:







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.