Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Could I get return handle from DllImport?

Status
Not open for further replies.

morequester

Programmer
Jul 26, 2004
6
0
0
CA
Hi buddy,

I used LoadLibrary in C++. Now I changed it to C#.
C++ codes:
hKernelLib = LoadLibrary("kernel32.dll");
C# codes:
[DllImport("kernel32.dll")]

The problem is I need hKernelLib (which is the return value from invoking LoadLibrary), and it will be a parameter for the next API.
How could I get this return value from DllImport?

Thanks
 
Code:
public class LibWrap

{

	// Declares a managed prototype for the unmanaged function.
	[ DllImport( "Kernel32.dll" )]
	public static extern IntPtr LoadLibrary(string libname);

}
IntPtr h = LibWrap.LoadLibrary("MSVCIRTD.DLL");
if (h != IntPtr.Zero)
{
// Library loaded
}
obislavu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top