求教 无法从“const char [14]”转换为“wchar_t”
我写了一段代码 主要就是想用NetUserGetInfo函数,从返回的参数里判断账号密码是否永不过期,但是在
wchar_t user = "administrator"; LPCWSTR username = &user;的地方遇到编译错误 错误 1 error C2440: “初始化”: 无法从“const char [14]”转换为“wchar_t” 应该如何修改?另外我这段代码是否能判断administrator账号密码永不过期?
#ifndef UNICODE
#define UNICODE
#endif
#include <stdio.h>
#include <windows.h>
#include <lm.h>
#pragma comment(lib , "Netapi32.lib")
int main(int argc, wchar_t *argv[])
{
DWORD dwLevel = 2;
LPUSER_INFO_2 pBuf = NULL;
LPCWSTR servername = NULL;
wchar_t user = "administrator";
LPCWSTR username = &user;
NET_API_STATUS nStatus;
// Call the NetUserGetInfo function; specify level 2.
//
nStatus = NetUserGetInfo(servername,
username,
dwLevel,
(LPBYTE *)&pBuf);
//
// If the call succeeds, print the user information.
//
if (nStatus == NERR_Success)
{
if (pBuf != NULL)
if(pBuf->usri2_flags==UF_DONT_EXPIRE_PASSWD)
printf("The password should never expire on the account\n");
else
printf("The password will expire on the account\n");
}
// Otherwise, print the system error.
//
else
fprintf(stderr, "A system error has occurred: %d\n", nStatus);
//
// Free the allocated memory.
//
if (pBuf != NULL)
NetApiBufferFree(pBuf);
getchar();//使ms-dos窗口停留,以查看程序显示的信息
return 0;
}