Passing STL parameter from managed code to native DLL member function

M

matthew breedlove

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
 
M

matthew breedlove

matthew said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top