1313
1414在C#中执行一个` .exe ` 文件可以使用` Process ` 类,
1515
16- ``` Csharp
16+ ``` C#
1717using System ;
1818using System .Diagnostics ;
1919
@@ -28,7 +28,7 @@ class Program
2828
2929而在C++中可以使用` CreateProcess ` 函数。
3030
31- ``` Cpp
31+ ``` C++
3232#include < windows.h>
3333
3434int main ()
@@ -64,7 +64,7 @@ int main()
6464
6565在C#中执行一个` .dll ` 文件通常涉及在应用程序中加载并调用该` .dll ` 中的函数。
6666
67- ``` Csharp
67+ ``` C#
6868using System ;
6969using System .Runtime .InteropServices ;
7070
@@ -82,7 +82,7 @@ class Program
8282
8383在C++中执行一个` .dll ` 文件通常是通过加载动态链接库并调用其中的函数。
8484
85- ``` Cpp
85+ ``` C++
8686#include < windows.h>
8787
8888typedef void (* YourFunction)(); // 假设要调用的函数没有返回值
@@ -138,7 +138,7 @@ int main()
138138
139139测试程序的代码如下:
140140
141- ```
141+ ```c#
142142using System;
143143namespace TestApplication
144144{
@@ -173,7 +173,7 @@ C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /out:testcalc.exe test.c
173173
174174代码如下:
175175
176- ```
176+ ``` C#
177177using System ;
178178using System .Reflection ;
179179namespace TestApplication
@@ -193,7 +193,7 @@ namespace TestApplication
193193
194194** (3) 还原.exe的内容**
195195
196- ```Csharp
196+ ``` C#
197197using System ;
198198using System .Reflection ;
199199namespace TestApplication
@@ -214,7 +214,7 @@ namespace TestApplication
214214
215215代码如下:
216216
217- ``` Csharp
217+ ```C #
218218using System;
219219using System.Reflection;
220220namespace TestApplication
@@ -239,7 +239,7 @@ namespace TestApplication
239239
240240如果不需要指定需要调用的方法,调用main 函数即可:
241241
242- ``` Csharp
242+ ```C #
243243using System;
244244using System.Reflection;
245245namespace TestApplication
@@ -266,7 +266,7 @@ namespace TestApplication
266266
267267#### c#
268268
269- ``` Csharp
269+ ```C #
270270using System;
271271using System.IO;
272272using System.Reflection;
@@ -426,7 +426,7 @@ public void spawn(String var1) {
426426
427427** unmanaged .cpp **
428428
429- ``` Cpp
429+ ```C ++
430430#include <metahost.h>
431431#pragma comment(lib, "mscoree.lib")
432432
@@ -456,7 +456,7 @@ int main()
456456
457457执行的C #源码
458458
459- ``` Csharp
459+ ```C #
460460using System ;
461461
462462namespace TEST
@@ -481,7 +481,7 @@ namespace TEST
481481
4824821 .初始化CLR 环境(同上)
483483
484- ``` Cpp
484+ ```C ++
485485 CLRCreateInstance (CLSID_CLRMetaHost , IID_ICLRMetaHost , (VOID ** )& iMetaHost );
486486 iMetaHost ->GetRuntime (L " v4.0.30319" , IID_ICLRRuntimeInfo , (VOID ** )& iRuntimeInfo );
487487 iRuntimeInfo ->GetInterface (CLSID_CorRuntimeHost , IID_ICorRuntimeHost , (VOID ** )& iRuntimeHost );
@@ -490,14 +490,14 @@ namespace TEST
490490
4914912 .通过ICLRRuntimeHost 获取AppDomain 接口指针,然后通过AppDomain 接口的QueryInterface 方法来查询默认应用程序域的实例指针。
492492
493- ```Cpp
493+ ```C ++
494494 iRuntimeHost ->GetDefaultDomain (& pAppDomain );
495495 pAppDomain ->QueryInterface (__uuidof (_AppDomain ), (VOID ** )& pDefaultAppDomain );
496496```
497497
4984983 .通过默认应用程序域实例的Load_3 方法加载安全.net 程序集数组,并返回Assembly 的实例对象指针,通过Assembly 实例对象的get_EntryPoint 方法获取描述入口点的MethodInfo 实例对象。
499499
500- ``` Cpp
500+ ```C ++
501501 saBound [0 ].cElements = ASSEMBLY_LENGTH ;
502502 saBound [0 ].lLbound = 0 ;
503503 SAFEARRAY * pSafeArray = SafeArrayCreate (VT_UI1 , 1 , saBound );
@@ -512,7 +512,7 @@ namespace TEST
512512
5135134 .创建参数安全数组
514514
515- ```Cpp
515+ ```C ++
516516ZeroMemory (& vRet , sizeof (VARIANT ));
517517 ZeroMemory (& vObj , sizeof (VARIANT ));
518518 vObj .vt = VT_NULL ;
@@ -535,13 +535,13 @@ ZeroMemory(&vRet, sizeof(VARIANT));
535535
5365365 .通过描述入口点的MethodInfo 实例对象的Invoke 方法执行入口点。
537537
538- ``` Cpp
538+ ```C ++
539539HRESULT hr = pMethodInfo ->Invoke_3 (vObj , args , & vRet );
540540```
541541
542542#### 示例代码
543543
544- ```Cpp
544+ ```C ++
545545#include <stdio.h>
546546#include <tchar.h>
547547#include <metahost.h>
@@ -634,7 +634,7 @@ int _tmain(int argc, _TCHAR* argv[])
634634
635635执行的C #源码
636636
637- ``` Csharp
637+ ```C #
638638using System ;
639639
640640namespace TEST
0 commit comments