.NET开发

本类阅读TOP10

·NHibernate快速指南(翻译)
·vs.net 2005中文版下载地址收藏
·【小技巧】一个判断session是否过期的小技巧
·VB/ASP 调用 SQL Server 的存储过程
·?dos下编译.net程序找不到csc.exe文件
·通过Web Services上传和下载文件
·学习笔记(补)《.NET框架程序设计(修订版)》--目录
·VB.NET实现DirectDraw9 (2) 动画
·VB.NET实现DirectDraw9 (1) 托管的DDraw
·建站框架规范书之——文件命名

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
Some Comments about Calling Win32 APIs in C# Managed Code

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

When we need to invoke a Win32 API in a certain .DLL file of the Win32 system:
1. Search the API in MSDN or Platform SDK for its accurate prototype, as well as informations of its  parameters' types.

2. In the C# source file, declare that function prototype using DllImportAttribute, e.g.:

[DllImport(“User32.dll“), CharSet=CharSet.Unicode, EntryPoint="MessageBoxW"), ......]

According to the API we want to use, we must specify appropriate properties to the DllImportAttribute object. For example, if we need to call a API which uses a Unicode string as its parameter, we must set the CharSet property to CharSet.Unicode, etc.

3. If the API need pointers or handles as its parameters, in the C# file, we should use System.UIntPtr or System.IntPtr instead.

4. If the API need a pointer to a certain variable as its parameter, in the C# file, we should use ref or out keywords.

5. If the API need a parameter reletive to a structure, we should define the structure in our own C# file.

6. If the API need function pointer as its parameter, we should define a corresponding delegate object.




相关文章

相关软件