c++ - writing unmanaged DLL consumable by C#/.NET code -


I need to apply a small part of my application logic in native code. To test PInvoke capabilities, I have created a simple solution with an unmanaged C ++ Win32 Dll and a WPF project that uses the DLF function using PInvoke. The problem I am running is that I get an exception about "stack imbalance" and "possible signature mismatch"

Here's my code:

1) C + + (DLL)

#include & lt; Stdio.h & gt; #include & lt; Windows.h & gt; Extern "c" {__declspec (dllexport) int plus (int a, int b) {return a + b; }}

2) C #:

  public partial square main window: window {[DllImport ("MyLibrary.dll")) static extern int add (Int a, int b); Public Manvindo () {Initialization (); } Private Zero btnVersion_Click (Object Sender, RoutedEventArgs e) {var res = add (3,2); Code  

throws an exception stating the code " This is possible because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling conference and PInvoke signature parameters

p> resolve) I think __stdcall keyword c ++ function definition It had to be forgotten: __dillexport int __stdcall add (int a, int b)


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -