R
Ryanivanka
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(dllexport) WCHAR* __stdcall getWNameOfComponnet();
}
WCHAR name[100];
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
WCHAR* getWNameOfComponnet(){
return name;
}
************************************************
*********************the win32 .def file************
EXPORT
getWNameOfComponnet @1
*****************************************************
and I try to use the export in c#,but I can not get anything from
getprocaddress(,.)
**************import the prototype of api**
[DllImport ("kernel32.dll",EntryPoint="LoadLibraryW",
CharSet=CharSet.Unicode,CallingConvention=CallingConvention.StdCall,
SetLastError =true)]
public extern static IntPtr LoadLibrary(String lpFileName);
[DllImport("Kernel32", EntryPoint = "GetProcAddress",
CharSet=CharSet.Unicode ,CallingConvention =
CallingConvention.StdCall,
SetLastError = true)]
public extern static IntPtr GetProcAddress(
IntPtr handle,
[MarshalAs(UnmanagedType.LPWStr)]string funcname);
**********************
**************get the export from my dll***
public delegate string getwname();
private static Delegate GetAddress(IntPtr dllModule, string
functionname, Type t)
{
IntPtr addr = GetProcAddress(dllModule, functionname);
//addr is always zero.why?
if (addr == IntPtr.Zero )
return null;
else
return Marshal.GetDelegateForFunctionPointer(addr, t);
}
public String callGetWname()
{
IntPtr huser32 =IntPtr.Zero ;
huser32 = LoadLibrary("my.dll");//the huser32 is ok,the
dll is loaded.
getwname mygetw = (getwname)GetAddress(huser32,
"getWNameOfComponnet",
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(dllexport) WCHAR* __stdcall getWNameOfComponnet();
}
WCHAR name[100];
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
WCHAR* getWNameOfComponnet(){
return name;
}
************************************************
*********************the win32 .def file************
EXPORT
getWNameOfComponnet @1
*****************************************************
and I try to use the export in c#,but I can not get anything from
getprocaddress(,.)
**************import the prototype of api**
[DllImport ("kernel32.dll",EntryPoint="LoadLibraryW",
CharSet=CharSet.Unicode,CallingConvention=CallingConvention.StdCall,
SetLastError =true)]
public extern static IntPtr LoadLibrary(String lpFileName);
[DllImport("Kernel32", EntryPoint = "GetProcAddress",
CharSet=CharSet.Unicode ,CallingConvention =
CallingConvention.StdCall,
SetLastError = true)]
public extern static IntPtr GetProcAddress(
IntPtr handle,
[MarshalAs(UnmanagedType.LPWStr)]string funcname);
**********************
**************get the export from my dll***
public delegate string getwname();
private static Delegate GetAddress(IntPtr dllModule, string
functionname, Type t)
{
IntPtr addr = GetProcAddress(dllModule, functionname);
//addr is always zero.why?
if (addr == IntPtr.Zero )
return null;
else
return Marshal.GetDelegateForFunctionPointer(addr, t);
}
public String callGetWname()
{
IntPtr huser32 =IntPtr.Zero ;
huser32 = LoadLibrary("my.dll");//the huser32 is ok,the
dll is loaded.
getwname mygetw = (getwname)GetAddress(huser32,
"getWNameOfComponnet",
typeof(getwname));
}
********************************
the getProcAddress(..) doesn't work.Where am i wrong?