D
dushkin
Hi all,
I have a 3rd party DLL written in C or C++. I don't have the code and
have no idea about the calling convention.
What I do know, is that the function prototype is:
int func(char *servername, int portnum, int options);
Everything I tried brought me the following message:
-------------------------------------------------
When I tried:
[DllImport("kernel32.dll")]
static extern IntPtr LoadLibrary(string dllName);
[DllImport("kernel32.dll", CharSet=CharSet.Ansi)]
static extern IntPtr GetProcAddress(IntPtr hModule, string
procName);
delegate int FuncDelegate(
string Ip,
int port,
int options);
private static IntPtr userApi;
public void CallFunc(string servername, int portnum, int
options)
{
userApi = LoadLibrary("mydll.dll");
IntPtr procAddress = GetProcAddress(userApi, Func");
FuncDelegate f =
(VtcConnectDelegate)Marshal.GetDelegateForFunctionPointer(procAddress,
typeof(FuncDelegate));
f("localhost", 8888, 1);
}
the development web server crashed and this message appeared:
"Managed Debugging Assistant 'PInvokeStackImbalance' has detected a
problem in 'C:\Program Files\Common Files\microsoft shared\DevServer
\10.0\WebDev.WebServer40.EXE'.
Additional Information: A call to PInvoke function 'App_Code.4avp4bfg!
FuncNs.XXXWrapper+FuncDelegate::Invoke' has unbalanced the stack. This
is likely because the managed PInvoke signature does not match the
unmanaged target signature. Check that the calling convention and
parameters of the PInvoke signature match the target unmanaged
signature."
-----------------------------------------------------------------
When I tried to use:
[DllImport("mydll.dll", CharSet = CharSet.Ansi)]
public static extern int func(string servername, int portnum,
int options);
and
func("localhost", 8888, 1);
I got the message :
"An unhandled exception of type
'System.ServiceModel.FaultException`1' occurred in mscorlib.dll
Additional information: Unable to load DLL 'mydll.dll': The specified
module could not be found. (Exception from HRESULT: 0x8007007E)"
Many thanks!
I have a 3rd party DLL written in C or C++. I don't have the code and
have no idea about the calling convention.
What I do know, is that the function prototype is:
int func(char *servername, int portnum, int options);
Everything I tried brought me the following message:
-------------------------------------------------
When I tried:
[DllImport("kernel32.dll")]
static extern IntPtr LoadLibrary(string dllName);
[DllImport("kernel32.dll", CharSet=CharSet.Ansi)]
static extern IntPtr GetProcAddress(IntPtr hModule, string
procName);
delegate int FuncDelegate(
string Ip,
int port,
int options);
private static IntPtr userApi;
public void CallFunc(string servername, int portnum, int
options)
{
userApi = LoadLibrary("mydll.dll");
IntPtr procAddress = GetProcAddress(userApi, Func");
FuncDelegate f =
(VtcConnectDelegate)Marshal.GetDelegateForFunctionPointer(procAddress,
typeof(FuncDelegate));
f("localhost", 8888, 1);
}
the development web server crashed and this message appeared:
"Managed Debugging Assistant 'PInvokeStackImbalance' has detected a
problem in 'C:\Program Files\Common Files\microsoft shared\DevServer
\10.0\WebDev.WebServer40.EXE'.
Additional Information: A call to PInvoke function 'App_Code.4avp4bfg!
FuncNs.XXXWrapper+FuncDelegate::Invoke' has unbalanced the stack. This
is likely because the managed PInvoke signature does not match the
unmanaged target signature. Check that the calling convention and
parameters of the PInvoke signature match the target unmanaged
signature."
-----------------------------------------------------------------
When I tried to use:
[DllImport("mydll.dll", CharSet = CharSet.Ansi)]
public static extern int func(string servername, int portnum,
int options);
and
func("localhost", 8888, 1);
I got the message :
"An unhandled exception of type
'System.ServiceModel.FaultException`1' occurred in mscorlib.dll
Additional information: Unable to load DLL 'mydll.dll': The specified
module could not be found. (Exception from HRESULT: 0x8007007E)"
Many thanks!