C++ DirectX和C++;
我在以下CPP代码方面遇到问题: 我收到以下错误:C++ DirectX和C++;,c++,C++,我在以下CPP代码方面遇到问题: 我收到以下错误: (1) Warning 1 warning LNK4042: object specified more than once; extras ignored c:\Users\jabbott\documents\visual studio 2010\Projects\DirectX9_Tutorial\DirectX9_Tutorial\Debug\WinMain.obj 1 (2) Error
(1) Warning 1 warning LNK4042: object specified more than once; extras ignored c:\Users\jabbott\documents\visual studio 2010\Projects\DirectX9_Tutorial\DirectX9_Tutorial\Debug\WinMain.obj 1
(2) Error 2 error LNK1561: entry point must be defined c:\Users\jabbott\documents\visual studio 2010\Projects\DirectX9_Tutorial\DirectX9_Tutorial\LINK
未设置任何入口点设置。我试着把它设为WinMain,但运气不好
// WinMain.h
#ifndef APP_HPP_
#define APP_HPP_
#include <Windows.h> // Windows API Library
#include <d3d9.h> // Include DirectX 9 Library
#include <d3d10_1.h> // Include DirectX 10 Library
#include <d3d11.h> // Include DirectX 11 Library
/* Global Functions */
// Handle any messages from MS Windows
LRESULT CALLBACK WndProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam);
// Main Entry Point
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd);
/* Global Variables */
IDirect3D9 *g_pD3D; // DirectX 3D v9 Instance
IDirect3DDevice9 *g_pD3DDevice; // DX3D9: Representation of Graphics Card
LPCTSTR ClsName = "g_szInterfaceClass";
//IDirect3D10 *g_pD3D10; // DirectX 3D v10 Instance
//IDirect3DDevice10 *g_pD3DDevice10; // DX3D10: Representation of Graphics Card
//IDirect3D11 *g_pD3D11; // DirectX 3D v11 Instance
//IDirect3DDevice11 *g_pD3DDevice11; // DX3D11: Representation of Graphics Card
#define WINDOW_WIDTH 200
#define WINDOW_HEIGHT 200
/* Error Macro for Debugging */
//#define ERROR(msg) { MessageBox(NULL, msg, L"Error", MB_OK|MB_ICONEXCLAMATION); }
#endif // WINMAIN_H
您的第一个问题可以通过删除此行来解决:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); /* Predeclaration of WinProc() */
您已经在它的正上方实现了该函数。如果函数的实现发生在调用该函数的时间点之后,或者实现位于不同的翻译单元(源文件)中,则仅需要上述内容。通常,尽量避免函数的“预声明”,如果可以的话,使用函数本身作为声明,这将减少所需的维护量
第二个问题可能是因为您正在编译控制台应用程序(入口点main
),而不是windows应用程序(入口点WinMain
)。这是正确答案(+1)。另外,我想补充一点,您已经在头文件中声明了函数原型,因此即使在WinMain中调用函数之前没有定义该函数,它仍然可以正确编译。
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); /* Predeclaration of WinProc() */