C2065未声明的标识符 [英] C2065 undeclared identifier
问题描述
我遇到了问题,但我不知道为什么.我不愿此来学习DirectX.我使用了此来配置解决方案.
I have got a problem but I don't know why. I'm fallowing this to learn DirectX. I used this to configure the solution.
这是我的代码:
标题:
#include <d3d11.h>
#include <d3dx11.h>
#include <d3d10.h>
#include <d3dx10.h>
#include <dxgi.h>
#include <Windows.h>
#include <windowsx.h>
#pragma comment (lib, "d3d11.lib")
#pragma comment (lib, "d3dx11.lib")
#pragma comment (lib, "d3dx10.lib")
class HelloWorld
{
private:
IDXGISwapChain* swapchain;
ID3D11Device* dev;
ID3D11DeviceContext* devcon;
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
public:
void InitD3D(HWND hWnd);
void CleanD3D(void);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);
};
}
和cpp:
#include "HelloWorld.h"
void InitD3D(HWND hWnd)
{
DXGI_SWAP_CHAIN_DESC scd;
ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));
scd.BufferCount = 1;
scd.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
scd.OutputWindow = hWnd;
scd.SampleDesc.Count = 4;
scd.Windowed = TRUE;
D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE,
NULL, NULL, NULL, NULL,
D3D11_SDK_VERSION, &scd, &swapchain, &dev, NULL, &devcon);
}
void CleanD3D(void)
{
swapchain->Release();
dev->Release();
devcon->Release();
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HWND hWnd;
WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = "WindowClass1";
RegisterClassEx(&wc);
RECT wr = {0, 0, 400, 400};
AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);
hWnd = CreateWindowEx(NULL,
"WindowClass1",
"First windowed program",
WS_OVERLAPPEDWINDOW,
300,
300,
wr.right - wr.left,
wr.bottom - wr.top,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd, nCmdShow);
MSG msg = {0};
while(true)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if(msg.message == WM_QUIT)
{
break;
}
}
else
{
}
}
return msg.wParam;
}
但是在编译过程中,我在swapchain,dev和devcon上遇到了C2065错误.
But during compilation I have got a C2065 error on : swapchain, dev and devcon.
我尝试了几件事,但没有任何效果.
I have tried several thing but nothing worked.
如果有人可以帮助我,将不胜感激!
If somebody could help my, it will be appreciate !
PuK
推荐答案
考虑将类限定符添加到您的 Init3D
函数中.
Consider adding a class-qualifier to your Init3D
function.
void InitD3D(HWND hWnd)
{
...
应该是:
void HelloWorld::InitD3D(HWND hWnd)
{
...
注意:其他功能也存在类似的问题,您很快就会发现WndProc需要进行一些特殊处理才能连接到C ++对象.
Note: similar problem exists for other functions, and you'll find out soon enough your WndProc will need some special handling to wire up to your C++ object.
这篇关于C2065未声明的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!