Search results for 'DLL Import'. 1 post(s) found.

  1. 2007/08/26 How to call Visual C/C++ implemented DLL functions in C# - Simple DLLImport
2007/08/26 21:33

How to call Visual C/C++ implemented DLL functions in C# - Simple DLLImport


Managed world is beautiful, I have all classes I want in FrameWork.. But what if I want call some unmanaged code? For instance, I have DLL written in C++, and want use it from 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.

[DLLImport("TestDll.dll", EntryPoint="sum",
ExactSpelling=false,CallingConvention=CallingConvention.Cdecl)]
static extern int sum(int a,int b);

and now we can call it like normal C# function.
x=5;
y=7;
z=sum(x,y); // z will receive 12

Another posts included in "C#"

Create PDF Files On the Fly In C Sharp (0)2007/08/27
Queue Tutorial In C# (0)2007/08/27
Stack Tutorial In C# (0)2007/08/27
Send Email Using C# (0)2007/08/26
How To Read And Write A Cookie (0)2007/08/26
Using C# With Cookies (0)2007/08/26
Trackback 4 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject different money making ideas

    Tracked from moneyideas 2010/01/25 08:44 delete

    moneyideas

  2. Subject different money making ideas

    Tracked from moneyideas 2010/01/28 22:05 delete

    moneyideas

  3. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 06:30 delete

    moneyideas

  4. Subject different money making ideas

    Tracked from moneyideas 2010/01/31 16:43 delete

    moneyideas