以下错误是@GetFullPathName() 函数
1 IntelliSense: argument of type "const char *" is incompatible with parameter of type "LPCWSTR"
2 IntelliSense: argument of type "char *" is incompatible with parameter of type "LPWSTR"
当我尝试运行我的程序时,我不断收到上述错误。变量是适当的类型,但它一直说不是这样?关于这是为什么的任何想法?我认为没有必要对它们进行类型转换。
#include "stdafx.h"
using namespace std;
int main(int argc, _TCHAR* argv[])
{
/* Get path of DLL we're loading */
string name;
cin >> name;
const char* DLL_NAME = name.c_str();
HWND handle = FindWindow(0, L"Calculator");
if(handle == NULL){
cout << "Couldn't find process window!" << endl;
}else{
cout << "Process window found, continuing..." << endl;
DWORD id;
GetWindowThreadProcessId(handle, &id);
char DLL_LOCATION[MAX_PATH] = {0};
GetFullPathName(DLL_NAME, MAX_PATH, DLL_LOCATION, NULL);
}
return 0;
}
最佳答案
The variables are of the appropriate type, yet it keeps saying otherwise?
不,他们不是。 LPCWSTR
和LPWSTR
分别是const wchar_t*
和wchar_t*
的别名。为此,您必须使用 std::wstring
而不是 std::string
。
分解它们的含义:
LPCWSTR
:指向常量宽字符串的长指针LPWSTR
:指向宽字符串的长指针
或者,您可以不将您的项目编译为 unicode(通过将字符集更改为多字节 IIRC),这样 Windows API 将需要“常规”字符串。
编辑:我应该注意到,就像字符串有一个广泛的模拟一样,std::cout
和 std::cin
也以 std 的形式存在: :wcout
和 std::wcin
。
关于c++ - 不兼容的 var 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18039436/