-1
有在本機代碼以下,需要在託管代碼編寫:如何P /調用一個可能不存在的函數?
HINSTANCE hUser = LoadLibrary("user32.dll"); /* Can't fail -- it's already loaded */
BOOL (*dpi)() = (BOOL (*)())GetProcAddress(hUser, "SetProcessDPIAware");
if(dpi) dpi();
功能SetProcessDPIAware沒有最低端的平臺,我們支持上存在的,所以我們會碰到裝載機問題簡單地聲明函數並試圖稱它。
但是,我必須根據除操作系統版本以外的條件調用SetProcessDPIAware來做出運行時決定,所以我不能使用清單。
的解決方案是讓'GetProcAddress'爲P/Invoke的功能以及,並調用從託管代碼。 – Dai 2014-10-29 21:46:01
重複標記不正確,因爲重複問題沒有我可以使用的答案。 – Joshua 2014-10-29 22:16:16
不要這樣做,使用清單。總是更好。 – 2014-10-29 22:51:03