Hello
How Do I return a wchar_t from function and How Does string return from wchar_t function ?
See below the errors pls
Code:
#include <windows.h>
#include <wchar.h>
#pragma comment(lib, "user32.lib")
wchar_t cname(void);
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PWSTR szCmdLine, int CmdShow) {
MessageBoxW(NULL, szCmdLine, L"Title", MB_OK);
int r = LockWorkStation();
if( r == 0 ) {
wprintf(L"LockWorkStation() failed %d\n", GetLastError());
return 1;
}
return 0;
}
wchar_t cname(void){
wchar_t computerName[MAX_COMPUTERNAME_LENGTH + 1];
DWORD size = sizeof(computerName) / sizeof(computerName[0]);
int r = GetComputerNameW(computerName, &size);
if (r == 0) {
wprintf(L"Failed to get computer name %ld", GetLastError());
return "Failed."; <------------------------------------// Invalid return type; expected 'wchar_t' but found 'char *'.
}
wprintf(L"Computer name: %ls\n", computerName);
return computerName; <------------- Invalid return type; expected 'wchar_t' but found 'wchar_t *'
}