gpt4 book ai didi

c++ - 外部 "C"错误 DirectX

转载 作者:太空狗 更新时间:2023-10-29 23:17:41 27 4
gpt4 key购买 nike

我一直在尝试使用 DirectX 进行一般游戏编程,并一直在遵循 Microsoft 网站 (http://msdn.microsoft.com/en-us/library/windows/apps/hh452790.aspx) 上的教程。但是,每当我尝试做任何事情时,它都会吐出运行时错误。这是我的代码:

#pragma comment (lib, "d2d1.lib")

#include<iostream>
#include<d2d1.h>
#include<Windows.h>


using namespace std;

int main()
{
HWND hwnd;
ID2D1Factory* pD2DFactory = NULL;
HRESULT hr = D2D1CreateFactory(
D2D1_FACTORY_TYPE_SINGLE_THREADED,
&pD2DFactory
);

//Obtain the size of the drawing
RECT rc;
GetClientRect(hwnd, &rc);
//Create a Direct2D rendertarget
ID2D1HwndRenderTarget* pRT = NULL;
HRESULT hr2 = pD2DFactory->CreateHwndRenderTarget(
D2D1::RenderTargetProperties(),
D2D1::HwndRenderTargetProperties(
hwnd,
D2D1::SizeU(
rc.right - rc.left,
rc.bottom - rc.top)
),
&pRT
);
cout << "TEST" << endl;
}

这是我遇到的错误:

        1>------ Build started: Project: Game, Configuration: Debug Win32 ------
1> Main.cpp
1>c:\users\will\documents\visual studio 2010\projects\game\game\main.cpp(21): warning C4700: uninitialized local variable 'hwnd' used
1>Main.obj : error LNK2028: unresolved token (0A00036A) "extern "C" int __stdcall GetClientRect(struct HWND__ *,struct tagRECT *)" (?GetClientRect@@$$J18YGHPAUHWND__@@PAUtagRECT@@@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>Main.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall GetClientRect(struct HWND__ *,struct tagRECT *)" (?GetClientRect@@$$J18YGHPAUHWND__@@PAUtagRECT@@@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>C:\Users\Will\Documents\Visual Studio 2010\Projects\Game\Debug\Game.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

最佳答案

您缺少带有您使用的链接器的库(或者您使用的库中的代码需要它):

在这种情况下,缺少 GetClientRect

Right-Click on Project -> Linker -> Input -> Add Dependencies  
Add "User32.lib" to what is there.

在类似情况下,在 MSDN 上查找函数名称,您将看到所需的库名称(对于 GetClientRect,为 here)。

关于c++ - 外部 "C"错误 DirectX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17070372/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com