继续深入C#调用win32 API的学习
2010-03-31 15:49
447 查看
找到几篇好文章
暴强贴:从.NET平台调用Win32 API 作者:刘铁猛
Calling Win32 DLLs in C# with P/Invoke
为什么是static extern 类型
上面这篇文章讲的不错
Now, notice that the MessageBeep method was declared as static. This is a requirement for P/Invoke methods because there is no consistent notion of an instance in the Windows API.
Next, notice that the method is marked as extern. This is your hint to the compiler that you mean for the method to be implemented by a function exported from a DLL, and therefore there is no need for you to supply a method body.
遇到里面的类型怎么解决呢?
1、非指针类型
Platform Invoke Tutorial
暴强贴:从.NET平台调用Win32 API 作者:刘铁猛
Calling Win32 DLLs in C# with P/Invoke
为什么是static extern 类型
上面这篇文章讲的不错
Now, notice that the MessageBeep method was declared as static. This is a requirement for P/Invoke methods because there is no consistent notion of an instance in the Windows API.
Next, notice that the method is marked as extern. This is your hint to the compiler that you mean for the method to be implemented by a function exported from a DLL, and therefore there is no need for you to supply a method body.
遇到里面的类型怎么解决呢?
1、非指针类型
Win32 Types | Specification | CLR Type |
---|---|---|
char, INT8, SBYTE, CHAR†| 8-bit signed integer | System.SByte |
short, short int, INT16, SHORT | 16-bit signed integer | System.Int16 |
int, long, long int, INT32, LONG32, BOOL†, INT | 32-bit signed integer | System.Int32 |
__int64, INT64, LONGLONG | 64-bit signed integer | System.Int64 |
unsigned char, UINT8, UCHAR†, BYTE | 8-bit unsigned integer | System.Byte |
unsigned short, UINT16, USHORT, WORD, ATOM, WCHAR†, __wchar_t | 16-bit unsigned integer | System.UInt16 |
unsigned, unsigned int, UINT32, ULONG32, DWORD32, ULONG, DWORD, UINT | 32-bit unsigned integer | System.UInt32 |
unsigned __int64, UINT64, DWORDLONG, ULONGLONG | 64-bit unsigned integer | System.UInt64 |
float, FLOAT | Single-precision floating point | System.Single |
double, long double, DOUBLE | Double-precision floating point | System.Double |
†In Win32 this type is an integer with a specially assigned meaning; in contrast, the CLR provides a specific type devoted to this meaning. 2,指针类型 这就涉及到其实在C#中,String类型是传引用的,见此博客解释/article/4848274.html 还有专业解释http://msdn.microsoft.com/en-us/library/0f66670z(VS.71).aspx 故有 // ** Documentation for Win32 GetShortPathName() API Function // DWORD GetShortPathName( // LPCTSTR lpszLongPath, // file for which to get short path // LPTSTR lpszShortPath, // short path name (output) // DWORD cchBuffer // size of output buffer // ); [DllImport("Kernel32", CharSet = CharSet.Auto)] static extern Int32 GetShortPathName( String path, // input string StringBuilder shortPath, // output string Int32 shortPathLength); // StringBuilder.Capacity |
相关文章推荐
- C#调用Win32 api学习总结
- C#调用Win32 api学习总结
- C#中调用WIN32的API
- C#调用win32 API读写INI文件
- Struts2.0深入学习 Strust2与Servlet API,Action多方法调用,result标签的type的类型
- java 调用win32 api 学习总结
- C#调用win32 api程序实例
- Java学习笔记 Java调用Win32 API控制鼠标活动范围
- c# 调用win32 api
- c#调用Win32 API如何处理指针类型的参数
- C#调用win32 API或称非托管代码
- 图解C# 调用Win32 API 示例程序
- C#中调用WIN32 API实现对光驱的操作
- c#调用Win32 API(C# DllImport用法)
- 常用C#调用 Win32 API 收录
- C#调用非托管的 win32 api
- C#中调用WIN32的API
- C#中调用WIN32的API
- 从.NET平台调用Win32 API(C#调用的dll动态链接库)
- c#调用Win32 API(C# DllImport用法)