作者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