hi ,everyone ,please check my codes,i am really confused.
the codes of win32 dll is as follows:
*************** ********the win32 DLL writen in c++************ *****
extern "C"
{
__declspec(dlle xport) WCHAR* __stdcall getWNameOfCompo nnet();
}
WCHAR name[100];
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_c all,
LPVOID lpReserved
)
{
return TRUE;
}
WCHAR* getWNameOfCompo nnet(){
return name;
}
*************** *************** *************** ***
*************** ******the win32 .def file*********** *
EXPORT
getWNameOfCompo nnet @1
*************** *************** *************** ********
and I try to use the export in c#,but I can not get anything from
getprocaddress( ,.)
**************i mport the prototype of api**
[DllImport ("kernel32.dll" ,EntryPoint="Lo adLibraryW",
CharSet=CharSet .Unicode,Callin gConvention=Cal lingConvention. StdCall,
SetLastError =true)]
public extern static IntPtr LoadLibrary(Str ing lpFileName);
[DllImport("Kern el32", EntryPoint = "GetProcAddress ",
CharSet=CharSet .Unicode ,CallingConvent ion =
CallingConventi on.StdCall,
SetLastError = true)]
public extern static IntPtr GetProcAddress(
IntPtr handle,
[MarshalAs(Unman agedType.LPWStr )]string funcname);
*************** *******
**************g et the export from my dll***
public delegate string getwname();
private static Delegate GetAddress(IntP tr dllModule, string
functionname, Type t)
{
IntPtr addr = GetProcAddress( dllModule, functionname);
//addr is always zero.why?
if (addr == IntPtr.Zero )
return null;
else
return Marshal.GetDele gateForFunction Pointer(addr, t);
}
public String callGetWname()
{
IntPtr huser32 =IntPtr.Zero ;
huser32 = LoadLibrary("my .dll");//the huser32 is ok,the
dll is loaded.
getwname mygetw = (getwname)GetAd dress(huser32,
"getWNameOfComp onnet",
typeof(getwname ));
}
*************** *************** **
the getProcAddress( ..) doesn't work.Where am i wrong?
the codes of win32 dll is as follows:
*************** ********the win32 DLL writen in c++************ *****
extern "C"
{
__declspec(dlle xport) WCHAR* __stdcall getWNameOfCompo nnet();
}
WCHAR name[100];
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_c all,
LPVOID lpReserved
)
{
return TRUE;
}
WCHAR* getWNameOfCompo nnet(){
return name;
}
*************** *************** *************** ***
*************** ******the win32 .def file*********** *
EXPORT
getWNameOfCompo nnet @1
*************** *************** *************** ********
and I try to use the export in c#,but I can not get anything from
getprocaddress( ,.)
**************i mport the prototype of api**
[DllImport ("kernel32.dll" ,EntryPoint="Lo adLibraryW",
CharSet=CharSet .Unicode,Callin gConvention=Cal lingConvention. StdCall,
SetLastError =true)]
public extern static IntPtr LoadLibrary(Str ing lpFileName);
[DllImport("Kern el32", EntryPoint = "GetProcAddress ",
CharSet=CharSet .Unicode ,CallingConvent ion =
CallingConventi on.StdCall,
SetLastError = true)]
public extern static IntPtr GetProcAddress(
IntPtr handle,
[MarshalAs(Unman agedType.LPWStr )]string funcname);
*************** *******
**************g et the export from my dll***
public delegate string getwname();
private static Delegate GetAddress(IntP tr dllModule, string
functionname, Type t)
{
IntPtr addr = GetProcAddress( dllModule, functionname);
//addr is always zero.why?
if (addr == IntPtr.Zero )
return null;
else
return Marshal.GetDele gateForFunction Pointer(addr, t);
}
public String callGetWname()
{
IntPtr huser32 =IntPtr.Zero ;
huser32 = LoadLibrary("my .dll");//the huser32 is ok,the
dll is loaded.
getwname mygetw = (getwname)GetAd dress(huser32,
"getWNameOfComp onnet",
typeof(getwname ));
}
*************** *************** **
the getProcAddress( ..) doesn't work.Where am i wrong?