'C# DLL'에 해당되는 글 1건
2007/08/26 21:33
How to call Visual C/C++ implemented DLL functions in C# - Simple DLLImport
2007/08/26 21:33 in C#

Let's look some code. Our DLL exports some function, in CDecl convention, that sums two integers:
extern "C" __declspec(dllexport) __cdecl int sum(int a,int b);
And, of course, we want reuse this code in C#. We must recall, that it is no "direct" way to call unmanaged code, but we must inform the compiler, what we want to call, how, and where is needed code located.
and now we can call it like normal C# function.[DllImport("TestDll.dll", EntryPoint="sum",
ExactSpelling=false,CallingConvention=CallingConvention.Cdecl)]
static extern int sum(int a,int b);
x=5;
y=7;
z=sum(x,y); // z will receive 12
Prev

Rss Feed