Atlbase无法正确包含在虚幻引擎4中

Atlbase won't include properly in Unreal Engine 4

本文关键字:引擎 包含 Atlbase      更新时间:2023-10-16

我正在使用VS2013的完整版本,并试图将atlbase包含到一个类中,以及sphelper,但我得到了各种类型的错误。

我正在使用一个新生成的类,它可以在没有这些包含的情况下干净地编译,并且里面几乎没有其他东西。

编译器正在寻找库并似乎加载它们,但随后我得到大约20个错误,这些错误都几乎就像这样(我省略了其余的,但它们都像这些错误)

1>E:ProgramsMicrosoft Visual Studio 12.0VCATLMFCINCLUDEatlcore.h(630): warning C4191: 'reinterpret_cast' : unsafe conversion from 'FARPROC' to 'BOOL (__cdecl *)(DWORD)'
1>          Calling this function through the result pointer may cause your program to fail
1>E:ProgramsMicrosoft Visual Studio 12.0VCATLMFCINCLUDEatltransactionmanager.h(271): warning C4191: 'type cast' : unsafe conversion from 'FARPROC' to 'PFNCREATETRANSACTION'
1>          Calling this function through the result pointer may cause your program to fail
1>E:ProgramsMicrosoft Visual Studio 12.0VCATLMFCINCLUDEatltransactionmanager.h(321): warning C4191: 'type cast' : unsafe conversion from 'FARPROC' to 'PFNCOMMITTRANSACTION'
1>          Calling this function through the result pointer may cause your program to fail
1>E:ProgramsMicrosoft Visual Studio 12.0VCATLMFCINCLUDEatltransactionmanager.h(427): error C2039: 'DeleteFile' : is not a member of '`global namespace''
1>E:ProgramsMicrosoft Visual Studio 12.0VCATLMFCINCLUDEatltransactionmanager.h(448): warning C4191: 'type cast' : unsafe conversion from 'FARPROC' to 'PFNMOVEFILETRANSACTED'
1>          Calling this function through the result pointer may cause your program to fail
1>E:ProgramsMicrosoft Visual Studio 12.0VCATLMFCINCLUDEatltransactionmanager.h(460): error C2039: 'MoveFile' : is not a member of '`global namespace''
1>E:ProgramsMicrosoft Visual Studio 12.0VCATLMFCINCLUDEatltransactionmanager.h(487): warning C4191: 'type cast' : unsafe conversion from 'FARPROC' to 'PFNGETFILEATTRIBUTESTRANSACTED'
1>E:ProgramsMicrosoft Visual Studio 12.0VCATLMFCINCLUDEatlbase.h(5766): warning C4191: 'type cast' : unsafe conversion from 'FARPROC' to 'LSTATUS (__cdecl *)(HKEY,LPCWSTR,REGSAM,DWORD)'
1>          Calling this function through the result pointer may cause your program to fail
1>C:Program Files (x86)Windows Kits8.1includeumsphelper.h(1333): warning C4191: 'type cast' : unsafe conversion from 'FARPROC' to 'LPFN_RegLoadMUIStringW'
1>          Calling this function through the result pointer may cause your program to fail

这些错误只有在包含了atlbase.h和/或sphelper.h之后才会出现。一半来自第一组,另一半来自第二组。

它们包含如下(在我的项目和类头包含之下):

#include <stdio.h>
#include <Windows.h>
#include "AllowWindowsPlatformTypes.h" 
#include <atlbase.h>
#include "sphelper.h"
#include "HideWindowsPlatformTypes.h"

我把它们放在这个"平台类型"块中,因为atlbase和sphelper库各自抛出了大量的错误,这些错误与任意声明或其他东西有关。

我没有以任何方式编辑库文件,并且完全删除了所有的库并从头重新安装。

这可能是由于我的疏忽或其他原因,但是有人能解释为什么atl和sphelper库不能正确包含吗?

编辑:

澄清一下,我在"解决"导致这个问题的问题的解决方案,我在"https://answers.unrealengine.com/questions/27560/trouble-using-windows-includes-with-dword-int.html"

上找到了。

我在一个更具体的网站上发布了我的问题,并在那里得到了答案。

用户Jamie Dale在UE4 AnswerHub上发布了以下内容

#include "AllowWindowsPlatformTypes.h"

#pragma warning(push)
#pragma warning(disable: 4191) // warning C4191: 'type cast' : unsafe conversion
#pragma warning(disable: 4996) // error C4996: 'GetVersionEx': was declared deprecated
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
// atltransactionmanager.h doesn't use the W equivalent functions, use this workaround
#ifndef DeleteFile
    #define DeleteFile DeleteFileW
#endif
#ifndef MoveFile
    #define MoveFile MoveFileW
#endif
#include <atlbase.h>
#undef DeleteFile
#undef MoveFile
#include <sphelper.h>
#pragma warning(pop)
#include "HideWindowsPlatformTypes.h"

这个工作取代了我使用的包含,并完全解决了我遇到的所有问题。这是Jamie Dale的功劳