Original Post
Hi, I have some errors with my coding, but I don’t know what the problem is, wish anyone could give me some advice. Below is the error message, please give me any suggestion. DuckHunting2006 error LNK2001: unresolved external symbol _c_dfDIMouse DuckHunting2006 error LNK2019: unresolved external symbol _DirectInput8Create@20 referenced in function "long __cdecl InitDirectInput(struct HWND__ *)" (?InitDirectInput@@YAJPAUHWND__@@@Z) [\b] Global declaration
Quote:
LPDIRECTINPUT8 g_pDI = NULL; LPDIRECTINPUTDEVICE8 g_pMouse;
Quote:
HRESULT InitDirectInput(HWND hwnd) { HRESULT hr; if( FAILED( hr = DirectInput8Create ( GetModuleHandle(NULL),DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&g_pDI, NULL ) ) ) return hr; // Obtain an interface to the system Mouse device. if( FAILED( hr = g_pDI->CreateDevice( GUID_SysMouse, &g_pMouse, NULL ) ) ) return hr; // This tells DirectInput that we will be passing a DIMOUSESTATE structure // IDirectInputDevice8::GetDeviceState(). Even though we won't actually do // it in this sample. But setting the data format is important so that the // DIJOFS_* values work properly. if( FAILED( hr = g_pMouse -> SetDataFormat( &c_dfDIMouse ) ) ) return hr; // Set the cooperative level to let DInput know how this device should // interact with the system and with other DInput applications. // Exclusive access is required in order to perform force feedback. if( FAILED( hr = g_pMouse->SetCooperativeLevel( hwnd, DISCL_EXCLUSIVE | DISCL_BACKGROUND ) ) ) { return hr; } // Acquire the newly created device g_pMouse->Acquire(); // Set a timer to go off 12 times a second, to read input // Note: Typically an application would poll the Mouse // much faster than this, but this slow rate is simply // for the purposes of demonstration SetTimer( hwnd, 0, 1000 / 12, NULL ); return S_OK; }
Quote:
HRESULT UpdateInputState( IDirect3DDevice9* pd3dDevice, HWND hwnd ) { HRESULT hr; DIMOUSESTATE dims; // DirectInput Mouse state structure if( NULL == g_pMouse ) return S_OK; // Get the input's device state, and put the state in dims ZeroMemory( &dims, sizeof(dims) ); hr = g_pMouse->GetDeviceState( sizeof(DIMOUSESTATE), &dims ); if( FAILED(hr) ) { // DirectInput may be telling us that the input stream has been // interrupted. We aren't tracking any state between polls, so // we don't have any special reset that needs to be done. // We just re-acquire and try again. // If input is lost then acquire and keep trying hr = g_pMouse->Acquire(); while( hr == DIERR_INPUTLOST ) hr = g_pMouse->Acquire(); return S_OK; } return S_OK; }
Quote:
void CALLBACK OnDestroyDevice() { Xxxx xxxx if( g_pMouse ) g_pMouse->Unacquire(); // Release any DirectInput objects. SAFE_RELEASE( g_pMouse ); SAFE_RELEASE( g_pDI ); }