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++ / June 2006

Tip: Looking for answers? Try searching our database.

Passing STL parameter from managed code to native DLL member function

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
matthew breedlove - 28 Jun 2006 19:49 GMT
I have a Managed VC++ WinForms app in VC8 calling a member function of a
class in a native DLL.

My managed code is similar to this:

System::Void btnTest_Click(System::Object^  sender, System::EventArgs^  e) {
    Receiver r;

    std::vector<char> v;
    v.push_back('A');

    r.DoTest(v, 50);
}

The implementation of the method in my native DLL looks like this:

void DoTest(std::vector<char> test, int test2) { };

When I call the method, the vector looks to be corrupted when I break
the debugger in the native DLL, and the int parameter has an incorrect
value as well.

I've also tried this with std::string instead of std::vector. The string
ends up populated with garbage, and any other parameters of the method
are corrupted.

If I pass the first argument by reference (string or vector), it will
still appear corrupted, but the remaining parameters of the method
remain intact.

Any ideas what could be causing this?  I doubt it's an issue with
calling convention, as changing the first parameter to a non-STL type
works as expected, and the remaining parameters are intact.

Thanks,
-Matthew
matthew breedlove - 29 Jun 2006 16:26 GMT
> When I call the method, the vector looks to be corrupted when I break
> the debugger in the native DLL, and the int parameter has an incorrect
> value as well.

After much research, I found that in my debug configuration I was
linking to the non-debug runtime library.  Once I changed this,
everything functioned as expected.

-Matthew

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.