Reputation: 28345
I have a C
library code, in which extern
method is defined:
typedef unsigned int U32;
extern U32 iw(U32 b, U32 p);
I also have the Assembler
code, in which this method is defined.
How can I call this C
(or may be even Assembler
) method from C# code?
Can I use the DllImport
attribute?
Upvotes: 0
Views: 1707
Reputation: 14757
Just be aware that you need to consider calling conventions. Most Win32 APIs are written to use stdcall
, so P/Invoke
uses stdcall
by the default. However VC++ uses CDecl
by default.
If you run into problems you can either modify your exported function to be stdcall
, or you can modify your P/Invoke
declaration (I think there's an optional CallingConvention
argument to the DllImport
attribute)
Upvotes: 2
Reputation: 38434
Yes, you can use something like the following to call your C dll function:
[DllImport("your.dll", EntryPoint="iw")]
public static extern UInt32 NiceNameFunc(UInt32 niceNameA, UInt32 niceNameP);
Upvotes: 1