Outils pour utilisateurs

Outils du site


lang:csharp:clr

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
lang:csharp:clr [2019/02/20 23:21] – Ajout de "Marshaling" rootlang:csharp:clr [2019/12/13 15:17] (Version actuelle) – mhtml -> html root
Ligne 1: Ligne 1:
-=====Syntaxe de C++/CLI====+====Syntaxe de C++/CLI====
 Les types ''C#'' se postfixe avec un ''^'' et on utilise ''using namespace'' à la place de ''using'' pour faire la différence avec le ''C++''. Les types ''C#'' se postfixe avec un ''^'' et on utilise ''using namespace'' à la place de ''using'' pour faire la différence avec le ''C++''.
 <code csharp> <code csharp>
Ligne 20: Ligne 20:
 La notion de référence ''&'' n'existe pas pour les objets managés. La notion de référence ''&'' n'existe pas pour les objets managés.
  
-=====C# => C++=====+====C# => C++====
 ===Pointeurs=== ===Pointeurs===
-[[https://stackoverflow.com/questions/25600940/managed-c-cli-array-conversion-error|Managed C++/CLI Array Conversion Error]] {{ :lang:csharp:clr:c_cli_-_managed_c_cli_array_conversion_error_-_stack_overflow.mhtml |Archive du 22/11/2018}}+[[https://stackoverflow.com/questions/25600940/managed-c-cli-array-conversion-error|Managed C++/CLI Array Conversion Error]] {{ :lang:csharp:clr:c_cli_-_managed_c_cli_array_conversion_error_-_stack_overflow_2019-12-13_3_13_20_pm_.html |Archive du 01/09/2014 le 13/12/2019}}
   * C#   * C#
 <code csharp> <code csharp>
Ligne 29: Ligne 29:
  
   * CLR   * CLR
 +C'est ''cli::pin_ptr'' qui fait office de ''GC::StillAlive()'' et donc ''val'' ne sera pas purgé tant que ''pin_ptr'' est en vie.
 +
 +<blockquote>An object is pinned only while a pin_ptr points to it. The object is no longer pinned when its pinning pointer goes out of scope, or is set to nullptr. After the pin_ptr goes out of scope, the object that was pinned can be moved in the heap by the garbage collector.
 +
 +[[https://docs.microsoft.com/en-us/cpp/windows/pin-ptr-cpp-cli?view=vs-2017|pin_ptr (C++/CLI)]] {{ :lang:csharp:clr:pin_ptr_c_cli_microsoft_docs_2019-12-13_3_13_28_pm_.html |Archive du 12/10/2018 le 13/12/2019}}
 +</blockquote>
 +
 <code cpp> <code cpp>
 static float CalcSumArray(array<float>^ val, int length) static float CalcSumArray(array<float>^ val, int length)
Ligne 63: Ligne 70:
 </code> </code>
  
-[[https://docs.microsoft.com/en-us/cpp/dotnet/overview-of-marshaling-in-cpp?view=vs-2017|Overview of Marshaling in C++]] {{ :lang:csharp:clr:overview_of_marshaling_in_c_microsoft_docs.mhtml |Archive du 20/02/2019}}+[[https://docs.microsoft.com/en-us/cpp/dotnet/overview-of-marshaling-in-cpp?view=vs-2017|Overview of Marshaling in C++]] {{ :lang:csharp:clr:overview_of_marshaling_in_c_microsoft_docs_2019-12-13_3_13_36_pm_.html |Archive du 12/07/2019 le 13/12/2019}}
  
-=====C++ => C#=====+====C++ => C#====
 ===Marshaling=== ===Marshaling===
 ^From type         ^To type             ^Marshal method ^Include file^ ^From type         ^To type             ^Marshal method ^Include file^
Ligne 103: Ligne 110:
  
 ===Prototype=== ===Prototype===
-<code cpp> +^C++/CLI                                                        ^C# généré     ^ 
-int32_t ReadBytes(uint8_t bank, uint8_t index, uint8_t length, [System::Runtime::InteropServices::Out] array<uint8_t>^% value); +|''uint8_t''                                                    |''byte''      | 
-</code>+|''array<uint8_t>%%^%%''                                        |''byte[]''    | 
 +|''System::String%%^%%''                                        |''string''    | 
 +|''System::String%%^%%%''                                       |''ref string''
 +|''[System::Runtime::InteropServices::Out]System::String%%^%%%''|''out string''| 
 +|''[System::Runtime::InteropServices::In]System::String%%^%%%'' |''ref string''
 +|''float''                                                      |''float''     | 
 +|''float&''                                                     |''float*''    | 
 +|''float%''                                                     |''ref float'' |
  
-va générer+====Erreurs==== 
 +  * '''IServiceProvider': ambiguous symbol'' 
 +Il ne faut pas mettre ''using namespace System;'' avant la déclaration de ''#include <msclr/marshal_cppstd.h>''.
  
-<code csharp+  * '''msclr::interop::marshal_as': none of the 3 overloads could convert all the argument types'' 
-public int ReadBytes(byte bank, byte index, byte length, out byte[] value);+Il ne faut pas tenter d'utiliser directement un attribut d'une classe. Il faut passer par une variable locale : 
 +<code> 
 +System::String^ fic = fichier_; 
 +std::string tt = msclr::interop::marshal_as<std::string>(fic);
 </code> </code>
  
-Sans ''[Out]'', l'argument est considéré comme un ''ref'' en C#.+  * '''XXX.YYY(?)' is not supported by the language'' 
 +Apparaît dans le projet C# en essayant d'appeler une fonction du projet ''C++/CLI''. Dans le projet ''C++/CLI'', il manque le ''^'' après le type à la place du ''?''
 + 
 +[[https://qualapps.blogspot.com/2008/07/using-atlstrh-in-managed-project.html|Fixing "ambiguous symbol" in a C++/CLR project]] {{ :lang:csharp:clr:technical_blog_for_jim_beveridge_fixing_ambiguous_symbol_in_a_c_clr_project_2019-12-13_3_13_44_pm_.html |Archive du 11/07/2008 le 13/12/2019}}
lang/csharp/clr.1550701292.txt.gz · Dernière modification : 2019/02/20 23:21 de root