"GetUserNameA":无法将参数 2 从"int"转换为"LPDWORD"
'GetUserNameA' : cannot convert parameter 2 from 'int' to 'LPDWORD'
我试过 https://stackoverflow.com/a/11587467/2738536
#include <windows.h>
#include <Lmcons.h>
char username[UNLEN+1];
GetUserName(username, UNLEN+1);
但是我收到此错误:"获取用户名A":无法将参数2从"int"转换为"LPDWORD"
根据文档,您传入的长度必须是指向双字的指针,因为该函数会根据返回的内容对其进行更改。
因此,您应该拥有以下内容:
TCHAR username[UNLEN+1]; // TCHAR to allow for MBCS and Unicode
DWORD len = UNLEN + 1; // if you're in to that sort of thing :-)
GetUserName(username, &len);
类型LPDWORD
实际上是一个指针。
您需要执行以下操作:
char username[UNLEN + 1];
DWORD name_length = ULEN + 1;
GetUserName(username, &name_length);
双字节参考
相关文章:
- 是否可以从int转换为enum类类型
- 如何在C++中将一个无符号的 int 转换为两个无符号的短裤?
- 是什么导致了这种使用三进制而不是短整型的有符号int到无符号int转换
- 将字符串中的 int 转换为字母;
- 主.cpp:18:20:错误:从"int*"转换为"int"会失去精度 [-fa
- 将非常大的 int 转换为双倍,在某些计算机上会损失精度
- 如何将矢量<int>转换为字符数组?
- C++ 无法从 const int* 转换为 const_iterator
- 我不断收到错误 C2440'=':无法从"int *(__cdecl *)(int *,int *,int,int)"转换为"int *
- 如何将 int[4] 转换为 std::array<int,4>?
- 如何将data[i].int转换为vaible
- 将 int 转换为字符串,然后连接另一个变量以创建完整扩展名,然后将其转换为 const_char*
- 将私有矩阵形式 int 转换为双 C++
- 无法将参数 1 从 'int' 转换为 'int &'
- 将 int 转换为字符串后始终得到 0
- isspace 函数的性能警告,从 int 转换为布尔值
- 将大 int 转换为浮点数,而不舍入 c++
- 错误:无法将'uint8* {aka unsigned int*}'转换为"常量emxArray_uint8_T*"?
- 将未签名的INT转换为BCD
- 在 C++ 中将 int 转换为双精度