這個dll中有一個類,類裡面有幾個函數:
// This class is exported from the testdrv.dll
class TESTDRV_API CDeviceManage {
public:
ULONG GetDevHandle(ULONG para1,ULONG para2,ULONG para3);
int GetDeviceState(char Volume);
bool UnloadDeviceDriver();
bool LoadDeviceDriver();
char * GetDevicesByType(int devtype);
char * GetAllDevices(void);
bool SetDeviceState(char Volume,int State);
CDeviceManage(void);
private:
HANDLE lphDevice;
};
我現在在c#裡面調用,寫成如下的樣子:
public class DeviceManager
{
[DllImport("testdrv.dll", EntryPoint="?LoadDeviceDriver@CDeviceManage@@QAE_NXZ")]
public static extern bool LoadDeviceDriver(); [DllImport("testdrv.dll", EntryPoint="?UnloadDeviceDriver@CDeviceManage@@QAE_NXZ")]
public static extern bool UnloadDeviceDriver();
[DllImport("testdrv.dll", EntryPoint="?GetDevHandle@CDeviceManage@@QAEKKKK@Z")]
public static extern ulong GetHandle(ulong i,ulong j,ulong k);
//...
}
EntryPoint是我通過工具Dependency Walker來看到的函數名字.-----------------------------
現在的問題是:
1.我給GetHandle傳入值1,2,3,但debug vc的代碼發現得到的值卻變成了1,0,2 這真是讓人費解.
2.我掉用了LoadDeviceDriver來load一個diver 程序,返回的結果表示load成功了,但是這個時候我掉用
GetHandle(這個方法只是簡單地返回一個變量的值而已),就會報錯:未將對象引用到實例.
c#代碼:
bool success = DeviceManager.LoadDeviceDriver();
Assert.IsTrue(success, "Load Device Driver Failed");
ulong l = DeviceManager.GetHandle(1,2,3);
DeviceManager.UnloadDeviceDriver();哪位能告訴我這是怎麼回事? 我已經快被折磨死了!!!
// This class is exported from the testdrv.dll
class TESTDRV_API CDeviceManage {
public:
ULONG GetDevHandle(ULONG para1,ULONG para2,ULONG para3);
int GetDeviceState(char Volume);
bool UnloadDeviceDriver();
bool LoadDeviceDriver();
char * GetDevicesByType(int devtype);
char * GetAllDevices(void);
bool SetDeviceState(char Volume,int State);
CDeviceManage(void);
private:
HANDLE lphDevice;
};
我現在在c#裡面調用,寫成如下的樣子:
public class DeviceManager
{
[DllImport("testdrv.dll", EntryPoint="?LoadDeviceDriver@CDeviceManage@@QAE_NXZ")]
public static extern bool LoadDeviceDriver(); [DllImport("testdrv.dll", EntryPoint="?UnloadDeviceDriver@CDeviceManage@@QAE_NXZ")]
public static extern bool UnloadDeviceDriver();
[DllImport("testdrv.dll", EntryPoint="?GetDevHandle@CDeviceManage@@QAEKKKK@Z")]
public static extern ulong GetHandle(ulong i,ulong j,ulong k);
//...
}
EntryPoint是我通過工具Dependency Walker來看到的函數名字.-----------------------------
現在的問題是:
1.我給GetHandle傳入值1,2,3,但debug vc的代碼發現得到的值卻變成了1,0,2 這真是讓人費解.
2.我掉用了LoadDeviceDriver來load一個diver 程序,返回的結果表示load成功了,但是這個時候我掉用
GetHandle(這個方法只是簡單地返回一個變量的值而已),就會報錯:未將對象引用到實例.
c#代碼:
bool success = DeviceManager.LoadDeviceDriver();
Assert.IsTrue(success, "Load Device Driver Failed");
ulong l = DeviceManager.GetHandle(1,2,3);
DeviceManager.UnloadDeviceDriver();哪位能告訴我這是怎麼回事? 我已經快被折磨死了!!!
试试看吧.DeviceManager dm =new DeviceManage();
ulong l = dm.GetHandle(1,2,3);
http://www.pinvoke.net