4

I work with piece of legacy code which uses direct draw and I'm in rather embarrassing situation. Not long ago I've updated my system and had to adapt to the new situation (loading ddraw.dll) and everything worked fine. Today I explored another legacy solution which also uses classes (files) I've changed, but I'm stuck with above mentioned linking error. I've checked and compared project properties and they seam fine.

This is code for directX initialization, "troublesome" code is bold.

 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;
    } 

Any ideas? Why it works in one solution and not in this one? Oh linker I loathe thee.

Deka
  • 131
  • 1
  • 4
  • 12

2 Answers2

8

Did you add dxguid.lib to your project's linker inputs?

ildjarn
  • 62,044
  • 9
  • 127
  • 211
  • My other project which uses the same files doesn't have linked in project inputs and it works fine. It isn't linked via #pragma comment either. – Deka May 11 '11 at 15:33
  • @Deka : So, did you add it to your linker inputs or not? If not, try it. – ildjarn May 11 '11 at 15:45
  • I've linked it and it works, but why I didn't have to linked it in other project?! – Deka May 11 '11 at 19:12
  • @Deka : The only rational explanation is that the other project does in fact link it somehow or it defines the value itself internally somewhere. In any case, linking `dxguid.lib` is the proper solution. – ildjarn May 11 '11 at 19:24
0

Make sure you add Dxguid.lib in your project.

João Augusto
  • 2,285
  • 24
  • 28
  • Ummm... isn't it linked automatically with Additional Lib Directories -> [My_DirectX_SDK_Location\Lib\x86]? – Deka May 11 '11 at 15:27
  • @Deka : No -- telling the linker where some .lib files exist is not the same as telling it to actually link a given .lib file. – ildjarn May 11 '11 at 15:44