作者pico2k (风月)
站内C_Sharp
标题Re: [问题] C# call win32 API
时间Sun Feb 20 22:07:50 2011
sample code (using managed code)
===========================================
import System.Runtime.InteropServices;
...
public static extern ulong abc
(string Disk, ulong Session, IntPtr List,out ulong size);
...
//Call abc
ulong s = 32;
String disk = "A";
ulong r = 0;
ulong Session = 1;
try{
IntPtr ptr = Marshal.AllocHGlobal(s);
r = abc(disk,Session,ptr,s);
}
catch(Exception ex){
...
}
finally{
if (ptr !=IntPtr.Zero){
Marshal.FreeHGlobal(ptr);
}
}
ps.在C#里面,最好少用unmanaged code...
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.62.64.95
1F:推 horngsh:我在C#里用win32 api用得很顺, 端看用者对P/Invoke熟不熟 02/24 15:28