from VC6 dll
-
Hi, everyone 1. When I call a function imported from a VC6 dll, it returns 42949672970 when it is supposed to return -1. Anyone knows why? 2. There's another function in this VC6 dll like this loginDlg(LPCTSTR Name, long NameLength). This function will return the login name by the first parameter, 2nd parameter is tell the function how long the buffer is. How to import and use this kind of functions properly? Thanks in advance.
-
Hi, everyone 1. When I call a function imported from a VC6 dll, it returns 42949672970 when it is supposed to return -1. Anyone knows why? 2. There's another function in this VC6 dll like this loginDlg(LPCTSTR Name, long NameLength). This function will return the login name by the first parameter, 2nd parameter is tell the function how long the buffer is. How to import and use this kind of functions properly? Thanks in advance.
Looks like the address of a return value is being returned. How are you declaring the native function to be P/Invoked?
Microsoft MVP, Visual C# My Articles
-
Looks like the address of a return value is being returned. How are you declaring the native function to be P/Invoked?
Microsoft MVP, Visual C# My Articles
Here is how the function declare in the VC6 dll head file
#ifndef LONG typedef long LONG; /* 32 bit */ #endif LONG _stdcall SelectChildProjects ( LONG lProjectId /* i Number of parent project */ );
Here is how I declare the function in my .Net code[DllImport("dcli.dll", EntryPoint="SelectChildProjects")] public static extern long SelectChildProjects(long lProjectId);
Thanks. -
Here is how the function declare in the VC6 dll head file
#ifndef LONG typedef long LONG; /* 32 bit */ #endif LONG _stdcall SelectChildProjects ( LONG lProjectId /* i Number of parent project */ );
Here is how I declare the function in my .Net code[DllImport("dcli.dll", EntryPoint="SelectChildProjects")] public static extern long SelectChildProjects(long lProjectId);
Thanks.A
LONG
(long
) in C++ is a 32-bit integer. Along
(Int64
) is a 64-bit integer. You're marshaling is all wrong which might explain why you're getting extra data from overflow. You should declare it as:[DllImport("dcli.dll")]
public static extern int SelectChildProjects(int lProjectId);Notice I also dropped the
EntryPoint
property, which you only need in cases where your declared method differs in name from the entry point exported by the native DLL.Microsoft MVP, Visual C# My Articles
-
A
LONG
(long
) in C++ is a 32-bit integer. Along
(Int64
) is a 64-bit integer. You're marshaling is all wrong which might explain why you're getting extra data from overflow. You should declare it as:[DllImport("dcli.dll")]
public static extern int SelectChildProjects(int lProjectId);Notice I also dropped the
EntryPoint
property, which you only need in cases where your declared method differs in name from the entry point exported by the native DLL.Microsoft MVP, Visual C# My Articles