Re: [問題] C# call win32 API

看板C_Sharp作者 (風月)時間15年前 (2011/02/20 22:07), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
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

02/24 15:28, , 1F
我在C#裡用win32 api用得很順, 端看用者對P/Invoke熟不熟
02/24 15:28, 1F
文章代碼(AID): #1DOI0uXy (C_Sharp)
文章代碼(AID): #1DOI0uXy (C_Sharp)