我已經看到了發生的截圖並保存爲JPG格式的following code,我已經成功地編譯並運行它作爲Win32控制檯應用程序,屏幕截圖的C++ CLI
但是,當我嘗試使用以下代碼放在一個windowsForm/CLI(也就是應該採取截圖按鈕)項目中,我得到了以下錯誤:
1>screenshoter.obj : warning LNK4248: unresolved typeref token (0100002C) for 'Gdiplus.GpCachedBitmap'; image may not run
1>screenshoter.obj : error LNK2028: unresolved token (0A000017) "extern "C" int __stdcall ReleaseDC(struct HWND__ *,struct HDC__ *)" ([email protected]@[email protected]@[email protected]@@Z) referenced in function "private: void __clrcall screenshoter::Form1::gdiscreen(void)" ([email protected]@[email protected]@$$FA$AAMXXZ)
1>screenshoter.obj : error LNK2028: unresolved token (0A000018) "extern "C" int __stdcall DeleteObject(void *)" ([email protected]@[email protected]) referenced in function "private: void __clrcall screenshoter::Form1::gdiscreen(void)" ([email protected]@[email protected]@$$FA$AAMXXZ)
1>screenshoter.obj : error LNK2028: unresolved token (0A000019) "extern "C" int __stdcall BitBlt(struct HDC__ *,int,int,int,int,struct HDC__ *,int,int,unsigned long)" ([email protected]@[email protected]@[email protected]) referenced in function "private: void __clrcall screenshoter::Form1::gdiscreen(void)" ([email protected]@[email protected]@$$FA$AAMXXZ)
1>screenshoter.obj : error LNK2028: unresolved token (0A00001A) "extern "C" void * __stdcall SelectObject(struct HDC__ *,void *)" ([email protected]@[email protected]@[email protected]) referenced in function "private: void __clrcall screenshoter::Form1::gdiscreen(void)" ([email protected]@[email protected]@$$FA$AAMXXZ)
1>screenshoter.obj : error LNK2028: unresolved token (0A00001B) "extern "C" struct HBITMAP__ * __stdcall CreateCompatibleBitmap(struct HDC__ *,int,int)" ([email protected]@[email protected]@[email protected]@[email protected]) referenced in function "private: void __clrcall screenshoter::Form1::gdiscreen(void)" ([email protected]@[email protected]@$$FA$AAMXXZ)
1>screenshoter.obj : error LNK2028: unresolved token (0A00001C) "extern "C" struct HDC__ * __stdcall CreateCompatibleDC(struct HDC__ *)" ([email protected]@[email protected]@[email protected]@Z) referenced in function "private: void __clrcall screenshoter::Form1::gdiscreen(void)" ([email protected]@[email protected]@$$FA$AAMXXZ)
1>screenshoter.obj : error LNK2028: unresolved token (0A00001D) "extern "C" int __stdcall GetSystemMetrics(int)" ([email protected]@[email protected]) referenced in function "private: void __clrcall screenshoter::Form1::gdiscreen(void)" ([email protected]@[email protected]@$$FA$AAMXXZ)
1>screenshoter.obj : error LNK2028: unresolved token (0A00001E) "extern "C" struct HDC__ * __stdcall GetDC(struct HWND__ *)" ([email protected]@[email protected]@[email protected]@@Z) referenced in function "private: void __clrcall screenshoter::Form1::gdiscreen(void)" ([email protected]@[email protected]@$$FA$AAMXXZ)
1>screenshoter.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall ReleaseDC(struct HWND__ *,struct HDC__ *)" ([email protected]@[email protected]@[email protected]@@Z) referenced in function "private: void __clrcall screenshoter::Form1::gdiscreen(void)" ([email protected]@[email protected]@$$FA$AAMXXZ)
1>screenshoter.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall DeleteObject(void *)" ([email protected]@[email protected]) referenced in function "private: void __clrcall screenshoter::Form1::gdiscreen(void)" ([email protected]@[email protected]@$$FA$AAMXXZ)
1>screenshoter.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall BitBlt(struct HDC__ *,int,int,int,int,struct HDC__ *,int,int,unsigned long)" ([email protected]@[email protected]@[email protected]) referenced in function "private: void __clrcall screenshoter::Form1::gdiscreen(void)" ([email protected]@[email protected]@$$FA$AAMXXZ)
1>screenshoter.obj : error LNK2019: unresolved external symbol "extern "C" void * __stdcall SelectObject(struct HDC__ *,void *)" ([email protected]@[email protected]@[email protected]) referenced in function "private: void __clrcall screenshoter::Form1::gdiscreen(void)" ([email protected]@[email protected]@$$FA$AAMXXZ)
1>screenshoter.obj : error LNK2019: unresolved external symbol "extern "C" struct HBITMAP__ * __stdcall CreateCompatibleBitmap(struct HDC__ *,int,int)" ([email protected]@[email protected]@[email protected]@[email protected]) referenced in function "private: void __clrcall screenshoter::Form1::gdiscreen(void)" ([email protected]@[email protected]@$$FA$AAMXXZ)
1>screenshoter.obj : error LNK2019: unresolved external symbol "extern "C" struct HDC__ * __stdcall CreateCompatibleDC(struct HDC__ *)" ([email protected]@[email protected]@[email protected]@Z) referenced in function "private: void __clrcall screenshoter::Form1::gdiscreen(void)" ([email protected]@[email protected]@$$FA$AAMXXZ)
1>screenshoter.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall GetSystemMetrics(int)" ([email protected]@[email protected]) referenced in function "private: void __clrcall screenshoter::Form1::gdiscreen(void)" ([email protected]@[email protected]@$$FA$AAMXXZ)
1>screenshoter.obj : error LNK2019: unresolved external symbol "extern "C" struct HDC__ * __stdcall GetDC(struct HWND__ *)" ([email protected]@[email protected]@[email protected]@@Z) referenced in function "private: void __clrcall screenshoter::Form1::gdiscreen(void)" ([email protected]@[email protected]@$$FA$AAMXXZ)
注:我已經列入需要
的所有文件我擡頭一看MSDN,但我真的不明白錯誤信息。此外,我過去曾遇到過類似的消息,我解決了這個問題,但是添加的.lib文件
這一次我嘗試添加,但它並沒有解決問題
#pragma comment(lib, "GdiPlus.lib")
謝謝,我包含了gdi32.lib和user32.lib,代碼完美無缺! – 2012-04-02 12:55:39