MFC中引入POCO库之后找不到API的问题

问题说明

在MFC项目中加入POCO库,导致MFC中的部分方法找不到。
比如:
error C3861: “GetObject”: 找不到标识符
“CreateFile”: 找不到标识符

这个问题困扰了我好久,在网上偶然看到有人提了一句说“是因为POCO库用到的一个头文件unwindows.h把这些函数都#undef了”,这时才想到去找POCO库中的UnWindows.h文件去看。

UnWindows.h

#ifndef Foundation_UnWindows_INCLUDED
#define Foundation_UnWindows_INCLUDED


// Reduce bloat
#if defined(_WIN32)
    #if !defined(WIN32_LEAN_AND_MEAN) && !defined(POCO_BLOATED_WIN32)
        #define WIN32_LEAN_AND_MEAN
    #endif
#endif



#if !defined(_WIN32_WCE)
#if defined(_WIN32_WINNT)
    #if (_WIN32_WINNT < 0x0501)
        #error Unsupported Windows version.
    #endif
#elif defined(NTDDI_VERSION)
    #if (NTDDI_VERSION < 0x05010100)
        #error Unsupported Windows version.
    #endif
#elif !defined(_WIN32_WINNT)
    // Define minimum supported version.
    // This can be changed, if needed.
    // If allowed (see POCO_MIN_WINDOWS_OS_SUPPORT
    // below), Platform_WIN32.h will do its
    // best to determine the appropriate values
    // and may redefine these. See Platform_WIN32.h
    // for details.
    #define _WIN32_WINNT 0x0501
    #define NTDDI_VERSION 0x05010100
#endif
#endif

#include <windows.h>

#if !defined(POCO_NO_UNWINDOWS)
// A list of annoying macros to #undef.
// Extend as required.
#undef GetBinaryType
#undef GetShortPathName
#undef GetLongPathName
#undef GetEnvironmentStrings
#undef SetEnvironmentStrings
#undef FreeEnvironmentStrings
#undef FormatMessage
#undef EncryptFile
#undef DecryptFile
#undef CreateMutex
#undef OpenMutex
#undef CreateEvent
#undef OpenEvent
#undef CreateSemaphore
#undef OpenSemaphore
#undef LoadLibrary
#undef GetModuleFileName
#undef CreateProcess
#undef GetCommandLine
#undef GetEnvironmentVariable
#undef SetEnvironmentVariable
#undef ExpandEnvironmentStrings
#undef OutputDebugString
#undef FindResource
#undef UpdateResource
#undef FindAtom
#undef AddAtom
#undef GetSystemDirectory
#undef GetTempPath
#undef GetTempFileName
#undef SetCurrentDirectory
#undef GetCurrentDirectory
#undef CreateDirectory
#undef RemoveDirectory
#undef CreateFile
#undef DeleteFile
#undef SearchPath
#undef CopyFile
#undef MoveFile
#undef ReplaceFile
#undef GetComputerName
#undef SetComputerName
#undef GetUserName
#undef LogonUser
#undef GetVersion
#undef GetObject
#endif // POCO_NO_UNWINDOWS

#endif // Foundation_UnWindows_INCLUDED

该文件中有很多注释说明,这里不再拷贝,有兴趣的去找下这个文件看一下。

解决方法

在UnWindows.h文件中的注释部分已经说明。
方法1、使用对应方法的Unicode变体(e.g., GetUserNameA)和ASCII变体(GetUserNameW)
方法2、使用POCO_NO_UNWINDOWS的宏定义(#define POCO_NO_UNWINDOWS)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值