我编写了一个C ++程序来验证Windows用户,当没有包含Poco Library(Event)时,它可以无缝地工作。我有一个无限的while循环(while(true)),当没有来自serer应用程序的请求时需要暂停。套接字读取在一个单独的线程中独立运行。
编译器:MingW 7.2
C ++标准:C ++ 14
包管理器:Msys2
架构:x64
我收到错误:
g++ -c -g -D__DEBUG -I/C/msys64/mingw64/include/boost -I/C/msys64/mingw64/include `pkg-config --cflags libconfig++` `pkg-config --cflags gnutls` -std=c++14 -MMD -MP -MF "build/Debug/MinGW-Windows/Authenticate.o.d" -o build/Debug/MinGW-Windows/Authenticate.o Authenticate.cpp
In file included from C:/msys64/mingw64/include/Poco/Foundation.h:102:0,
from C:/msys64/mingw64/include/Poco/Event.h:23,
from Common.hpp:41,
from Authenticate.hpp:19,
from Authenticate.cpp:14:
C:/msys64/mingw64/include/Poco/Platform_WIN32.h:179:92: note: #pragma message: Compiling POCO on Windows without #define POCO_WIN32_UTF8 is deprecated.
#pragma message("Compiling POCO on Windows without #define POCO_WIN32_UTF8 is deprecated.")
^
Authenticate.cpp: In member function 'bool Authenticate::authenticateUserCommandLine(std::__cxx11::string, std::__cxx11::string, std::__cxx11::string, std::__cxx11::string&)':
Authenticate.cpp:30:26: error: 'LogonUser' was not declared in this scope
logonReturnVal = LogonUser(userName.c_str(), domain.c_str(), NULL, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &token);
^~~~~~~~~
Authenticate.cpp:30:26: note: suggested alternative: 'LogonUserW'
logonReturnVal = LogonUser(userName.c_str(), domain.c_str(), NULL, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &token);
^~~~~~~~~
LogonUserW
Authenticate.cpp:32:26: error: 'LogonUser' was not declared in this scope
logonReturnVal = LogonUser(userName.c_str(), domain.c_str(), password.c_str(), LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &token);
^~~~~~~~~
Authenticate.cpp:32:26: note: suggested alternative: 'LogonUserW'
logonReturnVal = LogonUser(userName.c_str(), domain.c_str(), password.c_str(), LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &token);
^~~~~~~~~
LogonUserW
Authenticate.cpp: In member function 'bool Authenticate::authenticateUserCommandLine(std::__cxx11::string, std::__cxx11::string, std::__cxx11::string&)':
Authenticate.cpp:54:26: error: 'LogonUser' was not declared in this scope
logonReturnVal = LogonUser(userName.c_str(), domain.c_str(), NULL, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &token);
^~~~~~~~~
Authenticate.cpp:54:26: note: suggested alternative: 'LogonUserW'
logonReturnVal = LogonUser(userName.c_str(), domain.c_str(), NULL, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &token);
^~~~~~~~~
LogonUserW
Authenticate.cpp:56:26: error: 'LogonUser' was not declared in this scope
logonReturnVal = LogonUser(userName.c_str(), domain.c_str(), password.c_str(), LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &token);
^~~~~~~~~
Authenticate.cpp:56:26: note: suggested alternative: 'LogonUserW'
logonReturnVal = LogonUser(userName.c_str(), domain.c_str(), password.c_str(), LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &token);
^~~~~~~~~
LogonUserW
如果我删除#include <Poco/Event.h>
程序正常运行而没有错误。
如果我添加#define POCO_WIN32_UTF8
,我必须将LogonUser
替换为LogonUserW
。添加#define POCO_WIN32_UTF8
时遇到的最大问题是我在::GetLastError()
收到错误,说找不到功能。
LoginUser用法:
if(password.length() == 0)
logonReturnVal = LogonUser(userName.c_str(), domain.c_str(), NULL, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &token);
else
logonReturnVal = LogonUser(userName.c_str(), domain.c_str(), password.c_str(), LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &token);
:: GetLastError()用法:
string Error::GetLastErrorAsString(void)
{
//Get the error message, if any.
DWORD errorMessageID = ::GetLastError();
if(errorMessageID == 0)
return string(); //No error message has been recorded
LPSTR messageBuffer = nullptr;
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);
string message(messageBuffer, size);
//Free the buffer.
LocalFree(messageBuffer);
return message;
}
答案 0 :(得分:0)
问题是我在Poco/Event.h
之前加入了windows.h
。在包含导致问题的标题之前,Poco/Event.h
需要定义#define POCO_WIN32_UTF8
。
通过在定义windows.h
之前加入#define POCO_WIN32_UTF8
来解决问题,而Poco/Event.h
又在包含tColor
之前定义了。{/ p>