Thread: Return wchar_t

Results 1 to 3 of 3
  1. #1
    LagsBunny's Avatar
    Join Date
    Nov 2018
    Gender
    male
    Posts
    3
    Reputation
    10
    Thanks
    0

    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 *'
    
    }

  2. #2
    MikeRohsoft's Avatar
    Join Date
    May 2013
    Gender
    male
    Location
    Los Santos
    Posts
    797
    Reputation
    593
    Thanks
    26,318
    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

  3. #3
    LagsBunny's Avatar
    Join Date
    Nov 2018
    Gender
    male
    Posts
    3
    Reputation
    10
    Thanks
    0
    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

Similar Threads

  1. my slow triumphant return
    By -[standoff]- in forum Art & Graphic Design
    Replies: 13
    Last Post: 02-06-2007, 04:57 PM
  2. 79 Has returned from the death.
    By TechNixz in forum General
    Replies: 30
    Last Post: 12-30-2006, 11:46 AM
  3. Superman Returns
    By barney in forum SCI-FI
    Replies: 2
    Last Post: 11-12-2006, 10:49 PM
  4. Naruto Returns
    By arunforce in forum Anime
    Replies: 8
    Last Post: 10-16-2006, 06:25 AM
  5. Return of MPGH WoW
    By RebornAce in forum General
    Replies: 10
    Last Post: 08-14-2006, 06:05 PM