链接问题求救~!!!!
以下是我从老师那里复制的代码~但是为什么到了我机子上就不能执行了~~我的编译环境是VS2008英文版~ 而且我不是很熟练~所以麻烦大家写解决方法写清楚点哈~~谢谢谢谢~!!
一共有以下两个错误~~
error LNK2019: unresolved external symbol _D3DXCreateSprite@8 referenced in function _wWinMain@16 MyGame.obj MyGame
error LNK1120: 1 unresolved externals F:\MyGame\Debug\MyGame.exe 1 MyGame
// MyGame.cpp : Defines the entry point for the application.
#include "stdafx.h"
#include <d3d9.h>
#include <d3dx9.h>
#include <D3dx9core.h>
#include "MyGame.h"
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE g_hInst; // current instance
HWND g_hWnd;
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// TODO: Place code here.
MSG msg;
// Initialize global strings
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
// 在此处对绘图设备进行初始化
IDirect3D9* pD3D9 = NULL;
pD3D9 = Direct3DCreate9(D3D_SDK_VERSION);
// 此处创建了一个D3D9(不是设备!)
// 下面要创建一个用于绘制的设备
IDirect3DDevice9 *pD3DDevice = NULL;
// 初始化设备需要的一些参数
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = true;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
pD3D9->CreateDevice(
0, //D3DADAPTER_DEFAULT·,
D3DDEVTYPE_HAL,
g_hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp,
&pD3DDevice);
// 创建绘制贴图的工具
LPD3DXSPRITE pSprite = NULL;
D3DXCreateSprite(pD3DDevice, &pSprite);
// Main message loop:
bool bGameOver = false;
while (bGameOver == false)
{
// 去消息队列中看一下有没有新消息
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
bGameOver = (msg.message == WM_QUIT);
}
// 处理游戏逻辑与绘制任务
// 处理游戏逻辑的代码全部放在一个函数中
//Update();
// 处理绘制任务的代码全部集中于此
// 用什么设备(硬件、软件)进行绘制?
// 使用设备之前需要对设备进行初始化
// 问题是在哪里进行初始化比较合理
//Render();
pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);
// Begin the scene
if(SUCCEEDED(pD3DDevice->BeginScene()))
{
// 在此绘制
// 2D游戏
//pSprite->Begin(D3DXSPRITE_ALPHABLEND);
// 在这里绘制2D图片
// ......
//pSprite->End();
pD3DDevice->EndScene();
}
pD3DDevice->Present(NULL, NULL, NULL, NULL);
}
pD3D9->Release();
pD3DDevice->Release();
return (int) msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage are only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYGAME));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = TEXT("MyGameWnd");
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(&wcex);
}
//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
g_hInst = hInstance; // Store instance handle in our global variable
g_hWnd = CreateWindow(TEXT("MyGameWnd"), TEXT("My Game"), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!g_hWnd)
{
return FALSE;
}
ShowWindow(g_hWnd, nCmdShow);
UpdateWindow(g_hWnd);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint tmhe main window
// WM_DESTROY - post a quit message and return
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_KEYUP:
if (wParam == VK_ESCAPE)
{
PostQuitMessage(0);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}