This article is mainly to explain how to use the Vs.net 2008 generation, for both. NET programs and C + + programs to use the DLL (for the time being called it perfect dll good), plainly, is to put the managed code and unmanaged Code is created in an assembly through an assembly linker (Al.exe).
Best Practices:
1. Create a C + + Win32 DLL project, for example, call Asmproject.
2. In Asmproject.cpp, add an Add method, which is so simple that I can write it in ASM, well, then the old man is good.
extern "C" __declspec(dllexport) int add(int a, int b)
{
int c;
__asm
{
mov eax, a;
add eax, b;
mov c, eax;
}
return c;
}
3. Create another C # class library project, called Asmlibrary Bar, add a static class
public static class asmlibrary
{
[DllImport("asmlibrary.dll")]
public static extern int add(int a, int b);
}
Note that the DllImport, is the reference of the self Oh.