c++ - DirectInput linking error
First off, this is the first time I've posted here so sorry if I've posted to the wrong forum or otherwise not followed protocol. I did see a win32 forum but it doesn't look very active and also my guess is this is not specifically a win32 issue. The page title says "D Programming Language Forums" which threw me, but then under that it says "C++" . . . I am using DMC with DirectX SDK 8. I have run into a problem with a constant that is used to set the data format on a keyboard device. The method call is LPDIRECTINPUTDEVICE7->SetDataFormat. The constant, which supposedly defines a standard data format so that you don't have to fill out values in a structure (of type DIDATAFORMAT I believe), is called c_dfDIKeyboard. It is defined in dinput.h using the extern keyword, and I'm not familiar with what that keyword does, but I cannot find the value of the constant. The code compiles, but the linker says symbol undefined (Error 42). I am linking to dinput.lib and dinput8.lib and including dinput.h and objbase.h. These seem to be the required files. I am also using #define INITGUID and #define DIRECTINPUT_VERSION 0x0700. I have a guess as to what the problem might be. The dinput.lib and dinput8.lib that I am linking to were run through coffimplib. It appears that coffimplib has stripped out the definition of the constant c_dfDIKeyboard -- that word is in the original lib but not the lib produced by coffimplib. Another guess is, some research indicates that dxguid.lib *possibly* also needs to be linked. So far I've never needed it for any DirectDraw code. But, I did try running it through coffimplib but it says it's not an import library. I searched that file and there was no match on the constant so I doubt that's it, but I'm not experienced enough with C++ yet to know all the ways these files link to each or depend on each other. Here is the line from dinput.h: extern const DIDATAFORMAT cd_fDIKeyboard; Here is my line of code that produces the error, which is from a tutorial that has otherwise worked for me: lpKeyboard->SetDataFormat(&c_dfDIKeyboard); Thanks for any help, Erik
Aug 28 2010
I found a solution to the problem and thought I would share it for the sake of anyone who is a Java programmer trying to learn about linking, like me, and for the sake of the archives. I figured out that if I commented out the "extern" modifier from the declaration of c_dfDIKeyboard in dinput.h the linker was satisfied. Obviously the code didn't work at runtime but this gave me a clue. The definition of that constant is in dinput.lib, but as I stated, that definition disappears when the lib is converted with coffimplib. I'm supposing this has something to do with static libraries vs. import libraries but I don't have my head around that just yet. Regardless it seems that it was up to me to supply the definition or else find a compatible lib that does. I found that Borland C++ compiler also uses OMF format, and there are some converted libs out there produced by Borland users. Unfortunately it appears that they are mostly incompatible with DMC. However, it's obvious that someone ran into the very same problem and was kind enough to supply a cpp file with the definition source for c_dfDIKeyboard as well as the other standard Direct Input devices! You can find it here: http://realmike.org/blog/projects/directx-8-borland-libs-download- page/ The contents of c_dinput.cpp compiled fine for me and at runtime I was pleased to finally see "Keyboard acquired OK", whereas before I couldn't get past SetDataFormat. Cheers. No commandment from God ever is obsolete. All scripture is 100 percent backwards-compatible.
Aug 29 2010