Hi,
I have to use a 3rd party C++ DLL say (3PDLL)
It comes with a header file that declares its interface.
The interface is a structure say (3PStruct) that has a member for each
exposed function.
We (not I)have made a C++ dll say (MyInterface)that attaches to this DLL
and exposes its public functions.
MyInterface is then used by the main VB app.
I thought it might be possible to do the same thing in C# .
The essential MyInterface C++ code is:
HINSTANCE pDll;
Blah dllAttach;
3PStruct *pMainDllRec = NULL;
pDll = LoadLibrary("3PDLL.dll");
dllAttach = (Blah)GetProcAddress(pDll, "_dll_Attach");
if(!dllAttach(&pMainDllRec, ver_number))
{
wrong version clean up and exit
}
else
{
right version, pMainRecDll is now a pointer to 3pStruct that can be
dereferenced to any of the exposed functions.
}
So now MyInterface can now:
bool MYINTERFACE ThisFunction(bool lglResult)
{
return pMainDllRec->ThatFunction(lglResult);
}
Back to the C# world:
I have managed to Loadlibrary and GetProcAddress using IntPtrs for pDLL
and dllAttach but I come unstuck after this.
MyInterface has the advantage of the provided header file so it can
declare dllAttach to be of type Blah which is a function call that takes
pMainDllRec's address and a version string.
It seems that I am stuck with declaring dllAttach as an IntPtr.
So although I can retrieve dllAttach, I can't see how make to further
use of it to set pMainDllRec.
my C# attempt:
IntPtr p = new IntPtr(0);
IntPtr dllAttach = new IntPtr(0);
IntPtr pMainDllRec = new IntPtr(0);
p=LoadLibrary(Library);
dllAttach = GetProcAddress(p,"_dll_Attach");
So far so good..
The following is what I would like to achieve next.
I guess that this functionality if possible, would be in an unsafe
procedure .
IntPtr pMainDllRec = new IntPtr(0);
string version = "1.0.0"
if (dllAttach(&pMainDllRec, version))
{
success, we have a pointer to the functions
}
else
{
failure, wrong version message etc.
}
Is this possible in C# or should I just stick with the C++ 'MyInterface'.
Thanks
Bob