请教error C3646: 未知重写说明符

wy0222 2010-04-09 11:00:21
1>------ 已启动生成: 项目: FramesPerSecond, 配置: Release Win32 ------
1>正在编译...
1>main.cpp
1>.\main.cpp(25) : error C3646: “chuanLPDIRECT3D9”: 未知重写说明符
1>.\main.cpp(25) : error C3646: “g_D3D”: 未知重写说明符
1>.\main.cpp(25) : error C2072: “GetFPS”: 函数的初始化
1>.\main.cpp(25) : error C2440: “初始化”: 无法从“int”转换为“void (void)”
1> 没有转换为函数类型,但有转换为函数的引用或指针
1>.\main.cpp(106) : error C2065: “g_D3D”: 未声明的标识符
1>.\main.cpp(111) : error C2227: “->GetAdapterDisplayMode”的左边必须指向类/结构/联合/泛型类型
1> 类型是“'unknown-type'”
1>.\main.cpp(131) : error C2227: “->CreateDevice”的左边必须指向类/结构/联合/泛型类型
1> 类型是“'unknown-type'”
1>.\main.cpp(266) : error C2227: “->Release”的左边必须指向类/结构/联合/泛型类型
1> 类型是“'unknown-type'”
1>生成日志保存在“file://c:\Documents and Settings\Administrator\桌面\FPS1\FPS\Release\BuildLog.htm”
1>FramesPerSecond - 8 个错误,0 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========
...全文
3692 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
silingde 2011-11-18
  • 打赏
  • 举报
回复
4楼正解 我也遇到同样的问题
cumthyw 2011-11-18
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 junx1989 的回复:]
void RenderScene();
void Shutdown();
void GetFPS()


最后那个GetFPS()没有加分号. 嘿嘿.
[/Quote]正解
Junx1989 2010-07-26
  • 打赏
  • 举报
回复
void RenderScene();
void Shutdown();
void GetFPS()


最后那个GetFPS()没有加分号. 嘿嘿.
heiheizh618 2010-04-09
  • 打赏
  • 举报
回复
chuanLPDIRECT3D9 这个类型是哪定义的?
你对这个变量点右键然后go to definition,如果不能看到这个类型声明的头文件那应该就是你没包含这个头文件了
vann1982 2010-04-09
  • 打赏
  • 举报
回复
chuanLPDIRECT3D9 未定义,
看看 chuanLPDIRECT3D9 定义成啥了
wy0222 2010-04-09
  • 打赏
  • 举报
回复
这是代码


/*
Demo Name: Direct3D Frames Per Second
Author: Allen Sherrod
Chapter: Chapter 5
*/


#include<d3d9.h>
#include<d3dx9.h>
#include<stdio.h>

#define WINDOW_CLASS "UGPDX"
#define WINDOW_NAME "D3D FPS Demo"
#define WINDOW_WIDTH 640
#define WINDOW_HEIGHT 480

// Function Prototypes...
bool InitializeD3D(HWND hWnd, bool fullscreen);
bool InitializeObjects();
void RenderScene();
void Shutdown();
void GetFPS()

// Direct3D object and device.
chuanLPDIRECT3D9 g_D3D = NULL;
LPDIRECT3DDEVICE9 g_D3DDevice = NULL;

// DirectX font object.
// 用于创建和显示文本的D3D字体对象
LPD3DXFONT g_Font = NULL;

// RECT used to position the font.
// 用于确定文本在屏幕上显示的位置的RECT对象
RECT g_FontPosition = {0, 0, 0, 0};


LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
break;

case WM_KEYUP:
if(wp == VK_ESCAPE) PostQuitMessage(0);
break;
}

return DefWindowProc(hWnd, msg, wp, lp);
}


int WINAPI WinMain(HINSTANCE h, HINSTANCE ph, LPSTR cmd, int show)
{
// Register the window class
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc,
0L, 0L, GetModuleHandle(NULL), NULL, NULL,
NULL, NULL, WINDOW_CLASS, NULL };
RegisterClassEx(&wc);

// Create the application's window
HWND hWnd = CreateWindow(WINDOW_CLASS, WINDOW_NAME,
WS_OVERLAPPEDWINDOW, 100, 100, WINDOW_WIDTH,
WINDOW_HEIGHT, GetDesktopWindow(), NULL,
wc.hInstance, NULL);

// Initialize Direct3D
if(InitializeD3D(hWnd, false))
{
// Show the window
ShowWindow(hWnd, SW_SHOWDEFAULT);
UpdateWindow(hWnd);

// Enter the message loop
MSG msg;
ZeroMemory(&msg, sizeof(msg));

while(msg.message != WM_QUIT)
{
if(PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
RenderScene();
}
}

// Release any and all resources.
Shutdown();

// Unregister our window.
UnregisterClass(WINDOW_CLASS, wc.hInstance);
return 0;
}


bool InitializeD3D(HWND hWnd, bool fullscreen)
{
D3DDISPLAYMODE displayMode;

// Create the D3D object.
g_D3D = Direct3DCreate9(D3D_SDK_VERSION);
if(g_D3D == NULL) return false;

// Get the desktop display mode.
if(FAILED(g_D3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,
&displayMode))) return false;

// Set up the structure used to create the D3DDevice
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));

if(fullscreen)
{
d3dpp.Windowed = FALSE;
d3dpp.BackBufferWidth = WINDOW_WIDTH;
d3dpp.BackBufferHeight = WINDOW_HEIGHT;
}
else
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = displayMode.Format;

// Create the D3DDevice
if(FAILED(g_D3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING |
D3DCREATE_PUREDEVICE, &d3dpp, &g_D3DDevice)))
{
return false;
}

// Initialize any objects we will be displaying.
if(!InitializeObjects()) return false;

return true;
}


bool InitializeObjects()
{
// Create the font.
// 创建字体
if(FAILED(D3DXCreateFont(g_D3DDevice, 18, 0, 0, 1, 0,
DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE, "Dotum",
&g_Font))) return false;
//18, 0, // 字体字符的宽高
//0, // 是否加粗
//1, // Mipmap级别
//0, // 是否为斜体
//DEFAULT_CHARSET, // 设置默认字符集
//OUT_DEFAULT_PRECIS, // 输出精度,使用默认值
//DEFAULT_QUALITY, // 文本质量
//DEFAULT_PITCH | FF_DONTCARE,
//"Dotum", // 字体类型名称
//&g_Font // 要填充的LPD3DXFONT字体对象

// Here we are setting the position of the font.
// 设置字体对象将会使用的位置信息
g_FontPosition.top = 0;
g_FontPosition.left = 0;
g_FontPosition.right = WINDOW_WIDTH; // 获取窗口的宽度
g_FontPosition.bottom = WINDOW_HEIGHT; // 获取窗口的高度

return true;
}


void RenderScene()
{
// Clear the backbuffer.
g_D3DDevice->Clear(0, NULL, D3DCLEAR_TARGET,
D3DCOLOR_XRGB(0,0,0), 1.0f, 0);

// Begin the scene. Start rendering.
g_D3DDevice->BeginScene();

// Set next position and draw text.
//显示
g_FontPosition.top = 150;
// 在g_FontPosition位置绘制文本
g_Font->DrawText(NULL, "好好学习!",
-1, &g_FontPosition, DT_CENTER,
D3DCOLOR_XRGB(255,255,255));

// Set next position and draw text.
g_FontPosition.top = 180;
g_Font->DrawText(NULL, "天天向上.",
-1, &g_FontPosition, DT_CENTER,
D3DCOLOR_XRGB(255,255,255));

// Set next position and draw text.
g_FontPosition.top = 210;
g_Font->DrawText(NULL, "王洋.",
-1, &g_FontPosition, DT_CENTER,
D3DCOLOR_XRGB(255,255,255));

// Set next position and draw text.
g_FontPosition.top = 240;
g_Font->DrawText(NULL, "作业.",
-1, &g_FontPosition, DT_CENTER,
D3DCOLOR_XRGB(255,255,255));

// Set next position and draw text.
g_FontPosition.top = 270;
g_Font->DrawText(NULL, "26号!",
-1, &g_FontPosition, DT_CENTER,
D3DCOLOR_XRGB(255,255,255));

// End the scene. Stop rendering.
g_D3DDevice->EndScene();

// Display the scene.
g_D3DDevice->Present(NULL, NULL, NULL, NULL);

// FPS info.
// FPS相关变量
int g_fps = 0; // FPS帧率值
char g_fpsStr[16] = {0}; // 存放帧率值
float g_time = 0.0f; // 系统运行时间
float g_lastTime = 0.0f; // 持续的时间


// 计算帧率

{

// Get the second in millisecond then multiply it to convert to seconds.
// g_time获取操作系统启动到现在所经过的毫秒数,乘以0.001f得到秒数
g_time = GetTickCount() * 0.001f;


// If time - last time is > than 1, save fpt.
// 持续时间是否大于1秒
if(g_time - g_lastTime > 1.0f)
{
// Record last time.
// 记录新的持续时间
g_lastTime = g_time;

// Save FPS.
// 把整数g_fps格式化为一个字符串保存在g_fpsStr中,并输出该字符串
sprintf(g_fpsStr, "FPS: %d", g_fps);

// Reset the FPS counter.
// 重置帧率值为0
g_fps = 0;
}
else
{
// Add to the frames per second.
// 帧率值递增
g_fps++;
}
}
}


void Shutdown()
{
if(g_D3DDevice != NULL) g_D3DDevice->Release();
if(g_D3D != NULL) g_D3D->Release();
//销毁内存
if(g_Font) g_Font->Release(); // 释放字体对象

g_D3DDevice = NULL;
g_D3D = NULL;
g_Font = NULL; // 该指针指向为空
}

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧