Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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 shares 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.
Posted
Updated 11-May-11 22:40pm
v2
Comments
Oshtri Deka 11-May-11 15:30pm    
I've linked it to dxguid.lib in properties and it works, but I can't figure out how it works in other project without it?! I've re-checked it.
Originally It was linked to dxguid.lib via #pragma comment, but during my adaptation work I've commented it.
Albert Holguin 11-May-11 16:15pm    
You know, commenting here doesn't alert people who provided solutions...
Oshtri Deka 12-May-11 5:31am    
Usually interested people pay attention here. I'm counting on that ;).
And I think it's silly to copy same comment to each solution.
Albert Holguin 12-May-11 9:36am    
I'm not that interested in your problems... so I may or may not revisit your post... whereas if you post a comment to me directly, I get an e-mail and will likely revisit.
Albert Holguin 11-May-11 20:44pm    
if your problem was solved, please accept a solution...

Most likely you forgot to provide the corresponding .lib file in the Link tab of your project properties.
Find out which .lib you need for this interface and just fill it in the Link tab.

Otherwise, it might be a version issue: check that the version of DirectX you use in your code matches the DirectX SDK installed on your system.

---------------------------------------

This problem comes from a library problem. There is somehow i .lib missing somewhere or incorrect version:
- Check that both projects use the same version of DirectX (check the included .h directories and .lib files provided in the linker)
- Check the Additionnal Include Directories under C/C++ in project options
- Check the Additionnal Library Directories under Link in project options
- I even recommand to keep only one version (remove all remaining .h, .lib, or .dll files from the old versions)
- If you are working with different versions of Visual Studio, check that all default directories are the same: Menu Tools, Options, Projects and Solutions, VC++ Directories, Library files and Include files
- As Albert suggested check wether your code reference the .lib files directly through a #pragma comment
 
Share this answer
 
v2
Comments
Oshtri Deka 11-May-11 10:17am    
It uses latest version of DirectX SDK. Same class (files) is used in another project and it works fine (same linker properties).
Albert Holguin 11-May-11 10:36am    
obviously not the same, otherwise it'd be working wouldn't it?
Albert Holguin 11-May-11 16:16pm    
Looks like OP posted a comment to himself in his question, it was a pragma comment...
Olivier Levrey 12-May-11 3:20am    
Ok good then, your suggestion was the good one ;)
Here's a post with someone who had the same problem:
http://www.gamedev.net/topic/7112-linking-error--iid_idirectdraw2/[^]

It mentions what .libs you may be missing.
 
Share this answer
 
Comments
Albert Holguin 11-May-11 10:38am    
its obvious you're missing a library... maybe included though a pragma comment
Olivier Levrey 12-May-11 3:22am    
Have my 5 for the pragma
Oshtri Deka 12-May-11 5:27am    
I knew wich lib was missing, I've googled it to be sure. It's the same file shared between several projects, originally it was linked to ddraw.lib from properties and to dxguid.lib with #pragma comment. As said, I've changed code and it worked nice, but to my surprise that wasn't the case in another project.
I didn't use #pragma comment to fix it.
Both of you received my 5's for answers, but I like to think I solved it myself.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900