Jeg ved ikke hvor meget du faar ud af det, men her er noget kode.
test.cpp (bare et test program til at teste med):
#include <iostream>
using namespace std;
#include <windows.h>
typedef void (*VF)();
int main()
{
HINSTANCE glue = LoadLibrary("driver.dll");
VF f = (VF)GetProcAddress(glue, "f");
cout << "test main says hi from C++" << endl;
f();
return 0;
}
driver.cpp - native DLL med DllMain (man kan ikke bruge DllMain i en mixed mode DLL):
#include <iostream>
using namespace std;
#include <windows.h>
typedef void (*VF)();
static VF realf;
extern "C"
{
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved);
__declspec(dllexport) void f();
}
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
if(ul_reason_for_call == DLL_PROCESS_ATTACH)
{
cout << "driver DlLMain says hi from C++" << endl;
HINSTANCE glue = LoadLibrary("glue.dll");
realf = (VF)GetProcAddress(glue, "f");
}
return TRUE;
}
__declspec(dllexport) void f()
{
cout << "driver f says hi from C++" << endl;
realf();
}
glue.cpp - mixed mode DLL som binder native og managed sammen:
#include <iostream>
using namespace std;
#include <windows.h>
#using <mscorlib.dll>
#using <demo.dll>
using namespace E;
extern "C"
{
__declspec(dllexport) void f();
}
__declspec(dllexport) void f()
{
cout << "glue f says hi from C++" << endl;
Demo^ o = gcnew Demo();
o->F();
}
demo.vb - managed DLL:
Imports System
Namespace E
Public Class Demo
Public Sub F()
Console.WriteLine("Demo.F says hi from VB.NET")
End Sub
End Class
End Namespace
build.bat:
vbc /t:library demo.vb
cl /LD /CLR glue.cpp
cl /EHsc /LD driver.cpp
cl /EHsc test.cpp