B
bclegg
Hi,
I am a VB.net programmer who has to make use of a 3rd party Borland C++ dll.
We have a successful VC++ wrapper that presents a number of functions
that can be declared and called in VB.net
I now want to translate the wrapper to C#.
I can find my around C# in a (pardon the pun) basic fashion.
I am looking to translate the Main routine below.
I am at the first stage of emulating getting the pointer from LoadLibrary.
I have successfully used:
[DllImport ("KERNEL32.DLL")]
public static extern long LoadLibrary(string lpLibFileName);
This passed back a large number when I fed it the dll name and it
passed back a smaller number when I fed a nonexistent name.
But the C++ code below gets a null back when passed a nonexistent name
so I figured I had to use a HINSTANCE like the C++ .
This led me to use a module and marshal.getHinstance
But I can't see how to assign the module to the dll I am interested in.
public long bcLoadLibrary(string Library)
{
long lngResult;
Module m;
//m.Name=Library; /READONLY!!
IntPtr p = new IntPtr(0);
p=Marshal.GetHINSTANCE(m);
lngResult=(long)p;
return lngResult;
}
Am I close or deep in the weeds?
Thanks
Bob
The C++ Code snippet is
HINSTANCE pScadaDll;
TfAttach dllAttach;
TsSimAPIFuncs *pMainDllRec = NULL;
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID
lpReserved)
{
DWORD dwResult = 0;
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
pScadaDll = LoadLibrary("TheDLL.dll");
if(pScadaDll != NULL)
{
char sMsg[500];
wsprintf(sMsg, "attached TheDLL.dll Result: ");
MessageBox(NULL, sMsg, "Success", MB_OK);
dllAttach = (TfAttach)GetProcAddress(pScadaDll, "_dll_Attach");
I am a VB.net programmer who has to make use of a 3rd party Borland C++ dll.
We have a successful VC++ wrapper that presents a number of functions
that can be declared and called in VB.net
I now want to translate the wrapper to C#.
I can find my around C# in a (pardon the pun) basic fashion.
I am looking to translate the Main routine below.
I am at the first stage of emulating getting the pointer from LoadLibrary.
I have successfully used:
[DllImport ("KERNEL32.DLL")]
public static extern long LoadLibrary(string lpLibFileName);
This passed back a large number when I fed it the dll name and it
passed back a smaller number when I fed a nonexistent name.
But the C++ code below gets a null back when passed a nonexistent name
so I figured I had to use a HINSTANCE like the C++ .
This led me to use a module and marshal.getHinstance
But I can't see how to assign the module to the dll I am interested in.
public long bcLoadLibrary(string Library)
{
long lngResult;
Module m;
//m.Name=Library; /READONLY!!
IntPtr p = new IntPtr(0);
p=Marshal.GetHINSTANCE(m);
lngResult=(long)p;
return lngResult;
}
Am I close or deep in the weeds?
Thanks
Bob
The C++ Code snippet is
HINSTANCE pScadaDll;
TfAttach dllAttach;
TsSimAPIFuncs *pMainDllRec = NULL;
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID
lpReserved)
{
DWORD dwResult = 0;
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
pScadaDll = LoadLibrary("TheDLL.dll");
if(pScadaDll != NULL)
{
char sMsg[500];
wsprintf(sMsg, "attached TheDLL.dll Result: ");
MessageBox(NULL, sMsg, "Success", MB_OK);
dllAttach = (TfAttach)GetProcAddress(pScadaDll, "_dll_Attach");