“平台调用”示例

本示例演示了如何从 C# 中调用平台调用(导出的 DLL 函数)。有关更多信息,请参见互操作性(C# 编程指南)

安全说明

提供此代码示例是为了阐释一个概念,它并不代表最安全的编码实践,因此不应在应用程序或网站中使用此代码示例。对于因将此代码示例用于其他用途而出现的偶然或必然的损害,Microsoft 不承担任何责任。

在 Visual Studio 中生成并运行“平台调用”示例

  1. (-:In Solution Explorer, right-click the PinvokeTest project and click Set as StartUp Project.)=100%(在解决方案资源管理器中,右击“PinvokeTest”项目并单击“设为启动项目”。:-)

  2. (-:On the Debug menu, click Start Without Debugging.)=100%(在“调试”菜单上单击“开始执行(不调试)”。:-)

  3. (-:Repeat the preceding steps for Marshal and Pinvoke.)=100%(对于 Marshal 和 Pinvoke,请重复前面的步骤。:-)

(-:To build and run the Platform Invoke samples from the Command Line)=100%(从命令行生成并运行“平台调用”示例:-)

  1. 使用“更改目录”命令转到“PinvokeTest”目录。

  2. 键入以下命令:

    csc PinvokeTest.cs
    PinvokeTest
  3. 使用“更改目录”命令转到“Marshal”目录。

  4. 键入以下命令:

    csc Marshal.cs
    Marshal
  5. 使用“更改目录”命令转到“Pinvoke”目录。

  6. 键入以下命令:

    csc logfont.cs pinvoke.cs
    pinvoke