LPSTR -> LPWSTR



  • Hello People,

    wie kann ich die lpCmdLine in ein LPWSTR konvertieren, um damit weiterzuarbeiten?

    int WINAPI WinMain(HINSTANCE hInstance,
    				   HINSTANCE hPrevInstance,
    				   LPSTR     lpCmdLine,
    				   int       nShowCmd)
    {
    	WCHAR path[MAX_PATH + 1];
    
    	// cannot convert 'LPSTR' to 'LPCWSTR*
    	lstrcpy(path, lpCmdLine);
    
    	if (PathFileExists(path))
    	{
    
    	}
    	return 0;
    }
    

    Danke.



  • Was willst Du denn da konvertieren? Mach es einfach so:

    #include <tchar.h>
    
    int WINAPI _tWinMain(HINSTANCE hInstance, 
                         HINSTANCE hPrevInstance, 
                         LPTSTR    lpCmdLine, 
                         int       nShowCmd) 
    { 
        TCHAR path[MAX_PATH + 1]; 
    
        // cannot convert 'LPSTR' to 'LPCWSTR* 
        lstrcpy(path, lpCmdLine); 
    
        if (PathFileExists(path)) 
        { 
    
        } 
        return 0; 
    }
    


  • Ich habe aber ein WCHAR , denn ich habe auf unicode umgestellt.



  • LPWSTR CTabSetups::ConvertToUnicode(CString cString)
    {
    	int nBufSize = cString.GetLength() + 1;
    	LPWSTR lpws = new wchar_t[nBufSize];
    
    	if (lpws != NULL)
    	{
    		#if defined(_UNICODE)
    		lstrcpy(lpws, cString); // If Unicode is defined, just copy the string.
    		#else
    		// mbstowcs() would work here as well...
    		MultiByteToWideChar(CP_ACP, 0, cString, nBufSize, lpws, nBufSize * 2);
    		#endif // _UNICODE
    	}
    
    	return lpws;
    }
    

    aus deinem LPTSTR nen CString zu bekommen wirste ja wohl hinbekommen 😉



  • Code:) schrieb:

    Ich habe aber ein WCHAR , denn ich habe auf unicode umgestellt.

    Aber nur halb, oder was ist das mit lstrcpy und PathFileExists? Aber gut, dann eben so:

    int WINAPI wWinMain(HINSTANCE hInstance, 
                        HINSTANCE hPrevInstance, 
                        LPWSTR    lpCmdLine, 
                        int       nShowCmd) 
    { 
        WCHAR path[MAX_PATH + 1]; 
    
        // cannot convert 'LPSTR' to 'LPCWSTR* 
        lstrcpyW(path, lpCmdLine); 
    
        if (PathFileExistsW(path)) 
        { 
    
        } 
        return 0; 
    }
    



Anmelden zum Antworten