char lpszUsername[255];
DWORD dUsername = sizeof(lpszUsername);
GetUserNameA(lpszUsername, &dUsername);
ret_status = NetUserGetInfo(pc_name, lpszUsername, 1, (LPBYTE*)&ui);因此,对于GetUserNameA,我需要char,但对于NetUserGetInfo - LPCWSTR,我需要char。见鬼?如何将char转换为this?
error C2664: 'NetUserGetInfo' : cannot convert parameter 2 from 'char [255]' to 'LPCWSTR'发布于 2010-10-04 10:20:12
LPCWSTR的英文翻译为:"Wide-character string",或C中的wchar_t*。
要将ascii字符串转换为宽字符字符串,可能需要特殊的转换函数。
mbstowcs()可能就是您需要的。
发布于 2010-10-04 10:25:44
考虑使用GetUserNameW而不是GetUserNameA。这将为您提供宽字符字符串形式的当前用户名,从而消除将ANSI转换为Unicode的需要。
WCHAR lpwszUsername[255];
DWORD dUsername = sizeof(lpwszUsername) / sizeof(WCHAR);
GetUserNameW(lpwszUsername, &dUsername);
ret_status = NetUserGetInfo(pc_name, lpwszUsername, 1, (LPBYTE*)&ui);发布于 2010-10-04 10:17:12
有关转换宏的信息,请参阅MSDN:
#include <AtlBase.h>
USES_CONVERSION;
char lpszUsername[255];
DWORD dUsername = sizeof(lpszUsername);
GetUserNameA(lpszUsername, &dUsername);
// A2W() should do it
ret_status = NetUserGetInfo(pc_name, A2W(lpszUsername), 1, (LPBYTE*)&ui);https://stackoverflow.com/questions/3852435
复制相似问题