| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 790 人关注过本帖
标题:[求助]VS2003下VC++的一个错误,请大家帮忙看下(不欢迎灌水)
只看楼主 加入收藏
黑蝙蝠中队
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-3-4
收藏
 问题点数:0 回复次数:0 
[求助]VS2003下VC++的一个错误,请大家帮忙看下(不欢迎灌水)
键盘输入的一段代码的错误大家帮我看下
错误如下:
------ 已启动生成: 项目: smb, 配置: Debug Win32 ------

正在编译...
Input.cpp
C:\DXSDK\Include\dinput.h: DIRECTINPUT_VERSION undefined. Defaulting to version 0x0800
Input.cpp(41) : error C3861: “DirectInputCreate”: 即使使用参数相关的查找,也未找到标识符

生成日志保存在“file://e:\游戏移植\smb\smb\Debug\BuildLog.htm”中
smb - 1 错误,0 警告


---------------------- 完成 ---------------------

生成: 0 已成功, 1 已失败, 0 已跳过


代码如下:
#include "input.h"

extern HINSTANCE g_hInst;
extern HWND g_hWnd;

#define SAFE_RELEASE(x) if(x) { x->Release(); x = NULL; }

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CInput::CInput()
{
m_pDI = NULL;
m_pdevKeyboard = NULL;
m_pdevJoystick = NULL;
}



BOOL CInput::Create()
{
HRESULT hr;

// Create DirectInput object
hr = DirectInputCreate( g_hInst, DIRECTINPUT_VERSION, &m_pDI, NULL );
if( FAILED(hr) )
return FALSE;

// Initialize keyboard...
hr = m_pDI->CreateDevice( GUID_SysKeyboard, &m_pdevKeyboard, NULL );
if( FAILED(hr) )
{
Destroy();
return FALSE;
}

m_pdevKeyboard->SetDataFormat( &c_dfDIKeyboard );

m_pdevKeyboard->SetCooperativeLevel( g_hWnd,
DISCL_FOREGROUND | DISCL_NONEXCLUSIVE );

// acquire keyboard
m_pdevKeyboard->Acquire();



// enum joystick devices
m_pDI->EnumDevices( NULL, EnumJoystickCB,
(LPVOID)this, DIEDFL_ATTACHEDONLY );

if( m_pdevJoystick )
{
m_pdevJoystick->SetDataFormat( &c_dfDIJoystick );

m_pdevJoystick->SetCooperativeLevel( g_hWnd,
DISCL_FOREGROUND | DISCL_EXCLUSIVE );

// Set the range of the joystick axes tp [-1000,+1000]
DIPROPRANGE diprg;
diprg.diph.dwSize = sizeof(DIPROPRANGE);
diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
diprg.diph.dwHow = DIPH_BYOFFSET;
diprg.lMin = -10;
diprg.lMax = +10;

diprg.diph.dwObj = DIJOFS_X; // Set the x-axis range
m_pdevJoystick->SetProperty( DIPROP_RANGE, &diprg.diph );

diprg.diph.dwObj = DIJOFS_Y; // Set the y-axis range
m_pdevJoystick->SetProperty( DIPROP_RANGE, &diprg.diph );

// Set the dead zone for the joystick axes (because many joysticks
// aren't perfectly calibrated to be zero when centered).
DIPROPDWORD dipdw;
ZeroMemory( &dipdw, sizeof(dipdw) );
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.dwData = 5000; // Here, 5000 = 50%

dipdw.diph.dwObj = DIJOFS_X; // Set the x-axis deadzone
m_pdevJoystick->SetProperty( DIPROP_DEADZONE, &dipdw.diph );

dipdw.diph.dwObj = DIJOFS_Y; // Set the y-axis deadzone
m_pdevJoystick->SetProperty( DIPROP_DEADZONE, &dipdw.diph );

// acquire joystick
m_pdevJoystick->Acquire();
}

return TRUE;
}


void CInput::Destroy()
{
if( m_pdevKeyboard )
m_pdevKeyboard->Unacquire();
if( m_pdevJoystick )
m_pdevJoystick->Unacquire();
SAFE_RELEASE( m_pdevKeyboard );
SAFE_RELEASE( m_pdevJoystick );
SAFE_RELEASE( m_pDI );
}


void CInput::SetAcquire( BOOL active )
{
if( active )
{
if( m_pdevKeyboard )
m_pdevKeyboard->Acquire();
if( m_pdevJoystick )
m_pdevJoystick->Acquire();
}
else
{
if( m_pdevKeyboard )
m_pdevKeyboard->Unacquire();
if( m_pdevJoystick )
m_pdevJoystick->Unacquire();
}
}



BOOL CInput::GetKey( BYTE& input )
{
#define KEYDOWN(key) (buffer[key] & 0x80)

// Read keyboard data...
HRESULT hr;
char buffer[256];

// We have not read any data yet
input = 0;

hr = m_pdevKeyboard->GetDeviceState( sizeof(buffer), &buffer );
if( FAILED(hr) )
{
if( hr == DIERR_INPUTLOST )
hr = m_pdevKeyboard->Acquire();

return FALSE;
}

if( KEYDOWN( DIK_LEFT ) )
input |= KEY_LEFT;
else if( KEYDOWN( DIK_RIGHT ) )
input |= KEY_RIGHT;
if( KEYDOWN( DIK_UP ) )
input |= KEY_UP;
else if( KEYDOWN( DIK_DOWN ) )
input |= KEY_DOWN;
if( KEYDOWN( DIK_LSHIFT ) )
input |= KEY_ACC;
if( KEYDOWN( DIK_LCONTROL ) )
input |= KEY_JUMP;


if( m_pdevJoystick )
{
DIJOYSTATE js;

// poll the joystick to read the current state
m_pdevJoystick->Poll();

// get data from the joystick
hr = m_pdevJoystick->GetDeviceState( sizeof(js), &js );
if( FAILED(hr) )
{
// did the read fail because we lost input for some reason?
// if so, then attempt to reacquire. If the second acquire
// fails, then the error from GetDeviceData will be
// DIERR_NOTACQUIRED, so we won't get stuck an infinite loop.
if( hr = DIERR_INPUTLOST )
hr = m_pdevJoystick->Acquire();

return FALSE;
}

if( js.lX > 0 )
input |= KEY_RIGHT;
else if( js.lX < 0 )
input |= KEY_LEFT;
if( js.lY < 0 )
input |= KEY_UP;
else if( js.lY > 0 )
input |= KEY_DOWN;

if( js.rgbButtons[0] & 0x80 )
input |= KEY_ACC;
if( js.rgbButtons[1] & 0x80 )
input |= KEY_JUMP;
}


return TRUE;
}



BOOL CALLBACK EnumJoystickCB( LPCDIDEVICEINSTANCE pdinst,
LPVOID pvRef )
{
CInput* p = (CInput*)pvRef;
LPDIRECTINPUTDEVICE pdev;

if( FAILED(p->m_pDI->CreateDevice( pdinst->guidInstance, &pdev, NULL)) )
return DIENUM_CONTINUE;

pdev->QueryInterface( IID_IDirectInputDevice2, (LPVOID *)&p->m_pdevJoystick );
return DIENUM_STOP;
}

[此贴子已经被作者于2006-5-26 21:47:30编辑过]

搜索更多相关主题的帖子: 灌水 欢迎 
2006-05-26 21:46
快速回复:[求助]VS2003下VC++的一个错误,请大家帮忙看下(不欢迎灌水)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016605 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved