我不知道如何解決這個問題,並且我已經在兩小時的最佳時間內撞擊到了我的頭頂磚牆。我在下列文檔的非託管DLL的函數:由於指針不平衡堆棧
BOOL ZLNET_QueryDeviceTime(LONG lLoginID, LPZLNET_TIME pDeviceTime, int waittime=2000);
我假定pDeviceTime
是一個指針,因此我在C#代碼傳遞出,以便作爲參考使用。 在我的C#項目,我有以下聲明:
[StructLayout(LayoutKind.Sequential)]
public struct ZLNET_TIME
{
public Int32 dwYear;
public Int32 dwMonth;
public Int32 dwDay;
public Int32 dwHour;
public Int32 dwMinute;
public Int32 dwSecond;
} ;
[DllImport("zlnetsdk.dll")]
unsafe public static extern bool ZLNET_QueryDeviceTime(long lLoginID, out ZLNET_TIME pDeviceTime, int waittime);
的我把我的功能:
ZLNET_TIME t = new ZLNET_TIME();
ZLNET_QueryDeviceTime(loginResult, out t, 2000);
然而,當我跑我的項目,我得到的錯誤:
Managed Debugging Assistant
PInvokeStackImbalance
has detected a problem in (MY APP EXE).Additional Information: A call to
PInvoke
functionVP::ZLNET_QueryDeviceTime
has unbalanced the stack. This is likely because the managedPInvoke
signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature."
然後我在ZLNET_TIME
變量中沒有得到任何回報。誰能幫我這個?
兩側看起來都像是在使用指針。 C++端的'LPZLNET_TIME'的定義是什麼?它是一個typedef? –
爲什麼而不是參考? – doctorlove
第一個參數不是* long *,它是* int *。你可能需要使用CallingConvention屬性。描述是模糊的,但如圖所示,它應該是Cdecl。 –