不兼容的 var 类型 [英] Incompatible var types

查看:26
本文介绍了不兼容的 var 类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下错误是@GetFullPathName() 函数

The below errors are @ the GetFullPathName() function

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"

当我尝试运行我的程序时,我不断收到上述错误.变量是适当的类型,但它一直在说别的?关于为什么会这样的任何想法?我认为没有必要对它们进行类型转换.

I keep getting the above errors when I try to run my program. The variables are of the appropriate type, yet it keeps saying otherwise? Any ideas as to why this is? I don't think it's necessary to type cast them.

#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.

No they aren't. LPCWSTR and LPWSTR are aliases for const wchar_t* and wchar_t*respectively. You'll have to use std::wstring instead of std::string for this.

其含义的细分:

  • LPCWSTR:指向常量宽字符串的长指针
  • LPWSTR:指向宽字符串的长指针
  • LPCWSTR: Long Pointer to Const Wide String
  • LPWSTR: Long Pointer to Wide String

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

Alternatively you could not compile your project as unicode (by changing the character set to Multi-Byte IIRC), that way the Windows API will expect "regular" strings.

我应该注意到,就像字符串有一个广泛的类似物一样,std::coutstd::cin 也有 std 的形式::wcoutstd::wcin.

I should note that just like strings have a wide analogue so do std::cout and std::cin in the form of std::wcout and std::wcin.

这篇关于不兼容的 var 类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆