在C#里如何调用标准DLL函数

时间:2007-10-02 10:16:47   来源:chinaitzhe.com  作者:ChinaITzhe  编辑:gaopoadmin

在C#里只需要调用PInvoke (Platform Invocation) 服务。C# 支持一种sysimport属性
支持这种调用。
下面是完整的语法形式(在例子里没有用到所有的参数):

[sysimport(
dll=dllName,
name=functionName,
charset=characterSetToBeUsed)
]

给出一个调用Win32 MessageBox函数的例子:

using System;

class pinvokeClient
{
[sysimport(dll="user32.dll")]

public static extern int MessageBoxA(int hwnd, string message,
string caption, int type);

public static void Main()
{
int result = MessageBoxA(0, "Hello World", "PInvoke Test", 0);
}
}

 

关键字:在C#里如何调用标准DLL函数

相关文章

    无相关信息

文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面