我使用了一段使用直接繪製的遺留代碼,我處於相當尷尬的境地。 不久前我更新了我的系統,不得不適應新的情況(加載ddraw.dll),一切正常。 今天我探索了另一個傳統的解決方案,它也使用我已經改變的類(文件),但我堅持上面提到的鏈接錯誤。我檢查並比較了項目屬性,並且它們縫合良好。錯誤LNK2001:無法解析的外部符號_IID_IDirectDraw2
這是DirectX初始化的代碼,「麻煩」的代碼是粗體。
typedef int (__stdcall *DirectDrawCreateFunc)(GUID FAR* a ,LPDIRECTDRAW FAR* b, IUnknown FAR* c);
/* init_directx:
* Low-level DirectDraw initialization routine.
*/
int CDCUtils::init_directx(HWND allegro_wnd)
{
LPDIRECTDRAW directdraw1;
HRESULT hr;
LPVOID temp;
HINSTANCE ddraw = LoadLibrary("%WINDIR%\system32\ddraw.dll");
if(ddraw== NULL)
{
return -1;
}
_ddrawLib =ddraw;
DirectDrawCreateFunc ddFunc = (DirectDrawCreateFunc)GetProcAddress(ddraw,"DirectDrawCreate");
if(ddFunc)
{
/* first we have to set up the DirectDraw1 interface... */
hr = ddFunc(NULL, &directdraw1, NULL);
if (FAILED(hr))
return -1;
}
///* first we have to set up the DirectDraw1 interface... */
//hr = DirectDrawCreate(NULL, &directdraw1, NULL);
//if (FAILED(hr))
// return -1;
//...then query the DirectDraw2 interface
//This is the only place where IID_IDirectDraw2 is mentioned in entire solution
hr=directdraw1->QueryInterface(IID_IDirectDraw2, &temp);
if (FAILED(hr))
return -1;
_directdraw = (LPDIRECTDRAW2)temp;
directdraw1->Release();
/* set the default cooperation level */
hr = IDirectDraw2_SetCooperativeLevel(_directdraw, allegro_wnd, DDSCL_NORMAL);
if (FAILED(hr))
return -1;
/* get capabilities */
_ddcaps.dwSize = sizeof(_ddcaps);
hr = IDirectDraw2_GetCaps(_directdraw, &_ddcaps, NULL);
if (FAILED(hr)) {
TRACE("Can't get driver caps\n");
return -1;
}
_dxHwnd=allegro_wnd;
return 0;
}
任何想法? 爲什麼它在一個解決方案而不是在這個解決方案?噢連接器我厭惡你。
我使用相同文件的其他項目沒有鏈接在項目輸入,它工作正常。它也沒有通過#pragma註釋鏈接。 – Deka 2011-05-11 15:33:59
@Deka:那麼,您是否將它添加到鏈接器輸入中?如果沒有,嘗試一下。 – ildjarn 2011-05-11 15:45:22
我已經鏈接它,它的工作原理,但爲什麼我沒有在其他項目中鏈接它? – Deka 2011-05-11 19:12:00