SolvedReturn wchar_t

Posts 1–3 of 3 · Page 1 of 1
Return wchar_t
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 *'

}
change wchar_t cname(void){ to wchar_t* cname(void){
with other words, exactly what the compiler said
and return L"Failed."; for the first error
Quote Originally Posted by MikeRohsoft View Post
change wchar_t cname(void){ to wchar_t* cname(void){
with other words, exactly what the compiler said
and return L"Failed."; for the first error

Thank Mike
Posts 1–3 of 3 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us