Erzeugen von String Literale



  • Hi,

    ich habe eine Funktion von SQL vorgegeben die als Parameter nur ein:

    SQLWCHAR* <===(typedef wchar_t SQLWCHAR)

    akzeptiert.

    //ERROR (pstrCmd ist vom typ const char*)
    wchar_t* test = (wchar_t*)pstrCmd; // L"Use Sakila;"
    _retcode = SQLExecDirect(m_mapDestination[ucDestination], (SQLWCHAR*)test, SQL_NTS);
    
    //SUCCESS
    wchar_t* test = (wchar_t*)L"Use Sakila;";
    _retcode = SQLExecDirect(m_mapDestination[ucDestination], (SQLWCHAR*)test, SQL_NTS);
    
    //SUCCESS
    _retcode = SQLExecDirect(m_mapDestination[ucDestination], (SQLWCHAR*)L"Use Sakila;", SQL_NTS);
    

    Ich möchte aber gerne Variante 1 zum laufen kriegen damit man über die Konsole Sql-Statements ausführen kann.

    Es scheint ein Problem damit zu geben, dass das L beim casten nicht erzeugt wird.

    Hat jemand eine Idee?

    cuanu



  • Hallo.

    Wie wäre es mit einer Konvertierung von char* nach wchar_t* ?
    Es findet keine Konvertierung statt, in dem Du es hart auf den Typ wchar_t änderst!

    const wchar_t *GetWC(const char *c)
    {
        const size_t cSize = strlen(c)+1;
        wchar_t* wc = new wchar_t[cSize];
        mbstowcs (wc, c, cSize);
    
        return wc;
    }
    

    Quelle: http://stackoverflow.com/questions/8032080/how-to-convert-char-to-wchar-t

    Viele Grüße,



  • cuanuriaq schrieb:

    Ich möchte aber gerne Variante 1 zum laufen kriegen damit man über die Konsole Sql-Statements ausführen kann.

    Dann benutze wcin und wstring. Mit C-Style gecaste kommst du nicht weiter.


Anmelden zum Antworten