tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
6
ZUGRIFFE
1497
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    zu1u zu1u ist offline Mitglied Bronze
    Registriert seit
    Feb 2005
    Beiträge
    26
    hallo zusammen,
    zunächst mal bin ich nicht sicher ob das thema nicht irgendwo in den .NET Bereich gehört.
    Jedenfalls würde ich gerne im Rahmen von JNI einen System::String in einen jstring konvertieren.. wie der Titel bereits sagt.

    Mit der mir bekannten
    jstring js= globalEnv->NewStringUTF(string);
    komme ich leider nicht weit.

    kann mir jemand helfen?
     

  2. #2
    deepthroat deepthroat ist offline Mitglied Diamant
    tutorials.de Premium-User
    Registriert seit
    Jun 2005
    Beiträge
    8.168
    Hi.

    Probier's mal so:
    Code cpp:
    1
    
    globalEnv->NewStringUTF(string->ToCharArray());
    Gruß
     
    If at first you don't succeed, try again. Then quit. No use being a damn fool about it.

  3. #3
    zu1u zu1u ist offline Mitglied Bronze
    Registriert seit
    Feb 2005
    Beiträge
    26
    danke, funktioniert aber leider nicht

    Code :
    1
    2
    3
    4
    5
    6
    
    1>.\jni.cpp(71) : error C2664: 'JNIEnv_::NewStringUTF' : cannot convert parameter 1 from 'cli::array<Type,dimension> ^' to 'const char *'
    1>        with
    1>        [
    1>            Type=wchar_t,
    1>            dimension=1
    1>        ]
     

  4. #4
    deepthroat deepthroat ist offline Mitglied Diamant
    tutorials.de Premium-User
    Registriert seit
    Jun 2005
    Beiträge
    8.168
    Ok.

    Code cpp:
    1
    2
    3
    4
    5
    6
    
    #include <msclr\marshal.h>
     
    using namespace msclr::interop;
    ...
     
    globalEnv->NewStringUTF(marshal_as<const char*>(string));
    Gruß
     
    If at first you don't succeed, try again. Then quit. No use being a damn fool about it.

  5. #5
    zu1u zu1u ist offline Mitglied Bronze
    Registriert seit
    Feb 2005
    Beiträge
    26
    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    
    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\msclr\marshal.h(203) : error C4996: 'msclr::interop::error_reporting_helper<_To_Type,_From_Type>::marshal_as': This conversion requires a marshal_context.  Please use a marshal_context for this conversion.
    1>        with
    1>        [
    1>            _To_Type=const char *,
    1>            _From_Type=System::String ^
    1>        ]
    1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\msclr\marshal.h(194) : see declaration of 'msclr::interop::error_reporting_helper<_To_Type,_From_Type>::marshal_as'
    1>        with
    1>        [
    1>            _To_Type=const char *,
    1>            _From_Type=System::String ^
    1>        ]
    1>        .\fsw.cpp(75) : see reference to function template instantiation '_To_Type msclr::interop::marshal_as<const char*,System::String^>(const _From_Type &)' being compiled
    1>        with
    1>        [
    1>            _To_Type=const char *,
    1>            _From_Type=System::String ^
    1>        ]

    ging das bei dir denn?
    und woher nimmst du die Infos? ich müsste nämlich auch die andere Richtung konvertieren :S
    Geändert von zu1u (10.07.09 um 13:20 Uhr)
     

  6. #6
    zu1u zu1u ist offline Mitglied Bronze
    Registriert seit
    Feb 2005
    Beiträge
    26
    habs jetzt so gemacht.
    Code :
    1
    2
    3
    4
    5
    6
    7
    
    char string[100] = "";
    msclr::interop::marshal_context ctx;
    const char* deststring1 = ctx.marshal_as<const char*>(str);
    strcpy_s(string, deststring1);
     
    jstring jstring_var = globalEnv->NewStringUTF(string);
    return jstring_var;
    jetzt muss ich nur noch einen Rückweg finden

    Edit:
    hab ich jetzt auch:
    Code :
    1
    2
    3
    
        const char* charStr = globalEnv->GetStringUTFChars(jstr, NULL);
        String ^text= gcnew String(charStr);
        return text;

    ..danke
    Geändert von zu1u (10.07.09 um 14:07 Uhr)
     

  7. #7
    deepthroat deepthroat ist offline Mitglied Diamant
    tutorials.de Premium-User
    Registriert seit
    Jun 2005
    Beiträge
    8.168
    Zitat Zitat von zu1u Beitrag anzeigen
    ging das bei dir denn?
    Ich hab's nicht ausprobiert, hatte nur schnell geschaut.
    Zitat Zitat von zu1u Beitrag anzeigen
    und woher nimmst du die Infos?
    http://msdn.microsoft.com/en-us/library/bb384865.aspx

    In die andere Richtung geht einfach mit marshal_as.

    Gruß
     
    If at first you don't succeed, try again. Then quit. No use being a damn fool about it.

Ähnliche Themen

  1. Convert String to Date
    Von myD00M im Forum Java
    Antworten: 3
    Letzter Beitrag: 25.05.10, 10:43
  2. Convert String to XMLString
    Von nopePlan im Forum Java
    Antworten: 1
    Letzter Beitrag: 23.02.10, 09:19
  3. convert string to bool
    Von Thomasio im Forum C/C++
    Antworten: 5
    Letzter Beitrag: 30.08.08, 02:52
  4. [C#] Error 4 Cannot implicitly convert type 'object' to 'string'. ...
    Von yellowspam im Forum .NET Datenverwaltung
    Antworten: 1
    Letzter Beitrag: 02.11.07, 13:10
  5. System::Byte => System::String
    Von dertobian im Forum C/C++
    Antworten: 6
    Letzter Beitrag: 25.08.07, 18:57

Stichworte