views:

769

answers:

1

I made a static library in Visual C++ 2008 Express Edition. It compiles to Win32 code in a file called static.lib. The functions in this library call SetLastError() to indicate errors or success.

I have already succeeded in including this static.lib in a C++ Win32 DLL, and calling the DLL from C# using p/invoke and DllImport and SetLastError=true, and I was able to call Marshal.GetLastWin32Error() to get the error code.

But I ALSO want to include static.lib directly in a managed C++ .NET project. I figured out how to do that and call the functions in static.lib, but I am unable to access the error codes. Both GetLastError() and Marshall::GetLastWin32Error() usually return the "Invalid Parameter" error code.

So how do I call unmanaged code in a static library from a managed C++ .NET project in such a way that GetLastError() works? I'm looking for something equivalent to "SetLastError=true" from p/invoke.

A: 

hi,

I would like to know how you include the unmanaged lib directly into your .NET application. How is it done?

thx

ChristianWimmer
It was a long time ago, I forget now.
David Grayson
Yes, very helpful!
ChristianWimmer