2012-04-02 255 views
1

我已經看到了發生的截圖並保存爲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") 

回答

2

這些函數在gdi32.lib中聲明 - 不是gdiplus.lib - 有些可能在user32.lib中。

+0

謝謝,我包含了gdi32.lib和user32.lib,代碼完美無缺! – 2012-04-02 12:55:39

0

這些錯誤消息意味着你的代碼(或者說'screenshooter'代碼)使用了'symbols'(例如可能是函數名或變量),沒有代碼鏈接到最終的二進制文件中。

要解決這個問題,請查找每個符號需要鏈接的庫。例如,GetDC似乎是在user32.lib中定義的,所以請確保與該鏈接相關聯(可能通過使用#pragma指令,就像您對GdiPlus.lib所做的那樣)。