c++ - 不兼容的 var 类型

标签 c++ winapi

以下错误是@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?

不,他们不是。 LPCWSTRLPWSTR 分别是const wchar_t*wchar_t* 的别名。为此,您必须使用 std::wstring 而不是 std::string

分解它们的含义:

  • LPCWSTR:指向常量宽字符串的长指针
  • LPWSTR:指向宽字符串的长指针

或者,您可以将您的项目编译为 unicode(通过将字符集更改为多字节 IIRC),这样 Windows API 将需要“常规”字符串。

编辑:我应该注意到,就像字符串有一个广泛的模拟一样,std::coutstd::cin 也以 std 的形式存在: :wcoutstd::wcin

关于c++ - 不兼容的 var 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18039436/

相关文章:

c - 哪个 .lib 具有 IID___x_ABI_CWindows_CSystem_CProfile_CSystemManufacturers_CISmbiosInformationStatics?

c++ - VS 2008 生成的奇怪汇编器

c++列出(LINUX)中的所有目录和子目录

c++ - 是否所有 using 指令都被视为与 using namespace std 相同的方式?

c - fseek 和 Microsoft 的 CRT UNICODE 支持存在问题

windows - 创建虚拟文件夹并将它们挂接到文件系统

c++ - 运行时进程名称更改 (C++)

java - JNA映射以将输入/输出缓冲区传递给winapi函数

c++ - Game Of Life 程序中的混淆错误

C++ 从字符串中删除字符