• Advertisement
Sign in to follow this  

Mysterious PInvoke error

This topic is 2168 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm building a library in C++. One of the methods that I've exported is functioning properly, until it exits and throws the following error:

"A call to PInvoke function 'myapp!WindowsApplication1.mylib::TextSet' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature."

In C++, the method is delared as:
void __clrcall TextSet(TextClass *p, System::String ^text, int X, int Y, D3DCOLOR color)

And in my VB.Net test app:
<DllImport("mylib.dll")> Public Sub TextSet(ByVal TextClassPtr As IntPtr, ByVal text As String, ByVal X As Integer, ByVal Y As Integer, ByVal color As Long)
End Sub


TextSet(textClassPtr, "Test string", 10, 10, &HFFFFFFFF)

The funny thing is... if I empty out the procedure in C++ (to where the only thing it does is return), I still get this error.
And yet, as far as I can tell, the signatures match. Right?
So what's up with this mysterious error?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement