« Guide du C++ pour .NET Programmation » : différence entre les versions

Contenu supprimé Contenu ajouté
francisation
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;
<pre>
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);
</pre>
 
Il est fortement conseillé de créer une Macro dans un fichier ''header'' :
 
#define CONVERT2STRING(x) Marshal::PtrToStringAnsi(IntPtr((void*) x ),256)
<pre>
#define CONVERT2STRING(x) Marshal::PtrToStringAnsi(IntPtr((void*) x ),256)
</pre>
 
Ainsi l'utilisation de la classe '''Marshal''' est simplifiée
 
using namespace System::Runtime::InteropServices;
<pre>
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);
</pre>
 
 
== Conversion des String* en char* ==