Use the hosted C ++ to call the C # exe program.
(It turns out that reflector is invalid .) Ah.
Add a CLR console application. Place the C # exe program in the "resource file" folder, and set the item type of the right-click attribute to the compiled managed resource.
The main function of the main program code is rewritten as follows:
1 // X. cpp: Main project file. 2 3 # include "stdafx. H "4 5 using namespace system; 6 7 [stathreadattriction] 8 int main (array <system: String ^> ^ ARGs) 9 {10 system: Reflection :: assembly ^ A; 11 A = system: Reflection: Assembly: getexecutingassembly (); 12 system: IO: stream ^ stream; 13 stream = A-> getmanifestresourcestream ("csharp.exe"); 14 array <system: byte> ^ BS = gcnew array <system: byte> (Stream-> length ); 15 stream-> Read (BS, 0, (I NT) (Stream-> length); 16 system: Reflection: Assembly ^ EXE; 17 EXE = system: Reflection: Assembly: load (BS ); 18 system: Reflection: methodinfo ^ Info; 19 info = Exe-> entrypoint; 20 array <system: Reflection :: parameterinfo ^> ^ parameters = Info-> getparameters (); 21 if (parameters! = Nullptr) & (parameters-> length> 0) 22 {23 Info-> invoke (nullptr, (array <system: Object ^> ^) ARGs ); 24} 25 else26 {27 Info-> invoke (nullptr, nullptr); 28} 29 return 0; 30}
The corresponding C # code is as follows:
1 static class Program 2 {3 /// <summary> 4 // main entry point of the application. 5 /// </Summary> 6 [stathread] 7 static void main (string [] ARGs) 8 {9 var ASM = assembly. getexecutingassembly (); 10 stream = ASM. getmanifestresourcestream ("csharp.exe"); 11 byte [] BS = new byte [stream. length]; 12 stream. read (BS, 0, (INT) stream. length); 13 var EXE = assembly. load (BS); 14 methodinfo info = exe. entrypoint; 15 parameterinfo [] parameters = info. getparameters (); 16 if (parameters! = NULL) & (parameters. length> 0) 17 info. invoke (null, (object []) ARGs); 18 else19 info. invoke (null, null); 20 // application. enablevisualstyles (); 21 // application. setcompatibletextrenderingdefault (false); 22 // application. run (New form1 (); 23} 24}