« Guide du C++ pour .NET Programmation » : différence entre les versions
Contenu supprimé Contenu ajouté
francisation |
m →Conversion des char* en String* : syntaxe wiki |
||
Ligne 29 :
Le code suivant en est un exemple, (la valeur 256 correspond à la taille maximale de votre chaîne initiale, vous pouvez modifier ce paramètre):
using namespace System::Runtime::InteropServices;▼
▲using namespace System::Runtime::InteropServices;
char* ch_1 = "Hello World !";▼
▲char* ch_1 = "Hello World !";
String* ch_2 = Marshal::PtrToStringAnsi(IntPtr((void*) ch_1 ) , 256);▼
▲String* ch_2 = Marshal::PtrToStringAnsi(IntPtr((void*) ch_1 ) , 256);
Il est fortement conseillé de créer une Macro dans un fichier ''header'' :
#define CONVERT2STRING(x) Marshal::PtrToStringAnsi(IntPtr((void*) x ),256)▼
▲#define CONVERT2STRING(x) Marshal::PtrToStringAnsi(IntPtr((void*) x ),256)
Ainsi l'utilisation de la classe '''Marshal''' est simplifiée
using namespace System::Runtime::InteropServices;▼
▲using namespace System::Runtime::InteropServices;
char* ch_1 = "Hello World !";▼
▲char* ch_1 = "Hello World !";
String* ch_2 = CONVERT2STRING(ch_1);▼
▲String* ch_2 = CONVERT2STRING(ch_1);
== Conversion des String* en char* ==
|