外部"C"错误 DirectX
Extern "C" Error DirectX
我一直在尝试使用DirectX进行一般游戏编程,并一直遵循微软网站(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:userswilldocumentsvisual studio 2010projectsgamegamemain.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:UsersWillDocumentsVisual Studio 2010ProjectsGameDebugGame.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)。
相关文章:
- C++ Visual Studio 错误:名称后跟'::'必须是类或命名空间名称 (DirectX 11)
- DirectX 10 IDXGISWAPCHAIN :: GetBuffer多线程CTD错误
- DirectX C++的链接器错误
- DirectX 11和G 编译错误
- DirectX 11 错误等同于 DirectX 9
- DirectX 11 CreateSwapChain() 失败,错误DXGI_ERROR_INVALID_CALL
- 如何检索 DirectX 9 的错误字符串
- WinRT XAML DirectX 通用应用生成的文件中的错误
- DirectX 9 着色器未显示错误
- DirectX 11.2 错误: X3501: 找不到'main'入口点
- DirectX HLSL 着色器隐式截断矢量类型错误
- PIX DirectX 11 调试像素错误
- 使用 C++ 在 directX 11 中的 VS 2013 中获取 LNK 2019 错误
- LNK2001和LNK2019错误 - DirectX 未解析的外部符号
- C++和 directx 11 错误,没有为 dxgi.dll 加载符号
- 渲染自定义模型时出现c++Directx 11设备上下文错误
- C++DirectX11:使用DirectX工具包时出现NullPtr错误
- DirectX SDK的C++链接器错误
- 初始化directX 11时出现未处理的异常错误
- Directx错误DrawTextA和LPCSTR和HDC