ERLEDIGT
NEIN
NEIN
ANTWORTEN
6
6
ZUGRIFFE
1497
1497
EMPFEHLEN
-
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?
-
10.07.09 12:02 #2
- Registriert seit
- Jun 2005
- Beiträge
- 8.168
Hi.
Probier's mal so:
GrußCode cpp:1
globalEnv->NewStringUTF(string->ToCharArray());
If at first you don't succeed, try again. Then quit. No use being a damn fool about it.
-
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> ]
-
10.07.09 13:01 #4
- Registriert seit
- Jun 2005
- Beiträge
- 8.168
Ok.
GrußCode cpp:1 2 3 4 5 6
#include <msclr\marshal.h> using namespace msclr::interop; ... globalEnv->NewStringUTF(marshal_as<const char*>(string));
If at first you don't succeed, try again. Then quit. No use being a damn fool about it.
-
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 :SGeändert von zu1u (10.07.09 um 13:20 Uhr)
-
habs jetzt so gemacht.
jetzt muss ich nur noch einen Rückweg findenCode :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;
Edit:
hab ich jetzt auch:
Code :1 2 3
const char* charStr = globalEnv->GetStringUTFChars(jstr, NULL); String ^text= gcnew String(charStr); return text;
..dankeGeändert von zu1u (10.07.09 um 14:07 Uhr)
-
10.07.09 14:08 #7
- Registriert seit
- Jun 2005
- Beiträge
- 8.168
Ich hab's nicht ausprobiert, hatte nur schnell geschaut.
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
-
Convert String to Date
Von myD00M im Forum JavaAntworten: 3Letzter Beitrag: 25.05.10, 10:43 -
Convert String to XMLString
Von nopePlan im Forum JavaAntworten: 1Letzter Beitrag: 23.02.10, 09:19 -
convert string to bool
Von Thomasio im Forum C/C++Antworten: 5Letzter Beitrag: 30.08.08, 02:52 -
[C#] Error 4 Cannot implicitly convert type 'object' to 'string'. ...
Von yellowspam im Forum .NET DatenverwaltungAntworten: 1Letzter Beitrag: 02.11.07, 13:10 -
System::Byte => System::String
Von dertobian im Forum C/C++Antworten: 6Letzter Beitrag: 25.08.07, 18:57





Zitieren

Login






