473,378 Members | 1,498 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

unmanged libs and /clr

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

Nov 17 '05 #1
3 1092
<ki*********@gmail.com> wrote
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
Nov 17 '05 #2
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

Nov 17 '05 #3
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

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: P Reddy | last post by:
Hi All, Greetings!!! I have a question. Please respond.... I am trying to write a C# component that need to inherit some of the the interfaces from unmanged code(VC). I think one way to...
2
by: Paul Sneddon | last post by:
Hi, I'm using VS.NET 2005 RC to create Windows Mobile apps. I'm trying to call the following shell function which is new on Windows Mobile 5. SNDGETSND...
5
by: Maxwell | last post by:
Hello, Newbie question here. I have a VS.NET 2003 MC++ (not C++/cli) project where I have a managed class reference in a unmanaged class...simple enough. To keep things short I am for the most...
7
by: brian_harris | last post by:
I have a string object that I need to convert into an unmanged char * to be used by several unmnaged 3rd party functions. I have tried to use: (Marshal::StringToHGlobalAuto (Profname)) This would...
1
by: mschuck | last post by:
Here is the scenario I'm trying to make work. I've got 2 managed C++ classes, each of which wrappes an unmanaged C++ class, kind of like so: __nogc class UnmanagedClassA { public: void...
6
by: B. | last post by:
my small project has two files, umg.cpp (unmanaged c++) and mged.cpp (MC++), and unmanged code will call managed code. However, I cannot debug from unmanged code into managed code. Can anyone help...
1
by: sonic1981 | last post by:
Hi Everyone I'm trying to access an unmanged dll from ASP.Net (C#). I'm basically calling a logon method within the dll but when I get to this method call the system hangs? I've checked all the...
1
by: Raman | last post by:
Hi All, I have two libs (libFirst.a and libSecond.a). Both libs contains a common function func(). Now I want to link an application "app" with these two libs as gcc -o app libFirst.a...
1
by: tvnaidu | last post by:
I have windows code to port to Linux, there are some static libraries like xyz.lib, also shared libs ABC.dll, I have to convert those static and shared libs (basically static will be used to make...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.