在VS2008以及VS2010里,加载PInvoke

對於時不時需要在 VB/C# 裡面塞入一些 Win32 API 功能的程式設計師而言, PInvoke.Net 是一個非常好用的工具 (它甚至被 MSDN 雜誌評選為最需要被安裝的十個 VS Addin 之一)。可惜的是, 雖然這個工具完全支援 VS2003/2005, 它似乎並不認識 VS2008 及 VS2010 (即使 VS2008/2010 都已經上市那麼久了)。

如果要讓它在 VS2008 上能夠使用, 你可以按照以下的步驟來做:

1. 首先, 在 %programfiles%\red gate\PInvoke.NET 子目錄下面找到 PInvokeDotNetAddIn.Addin 這個檔案, 以 NotePad 開啟它。

2. 在這個檔案中找到最後一個 </HostApplication> 標記, 然後把以下這一段插入其下方 (記得存檔):

<HostApplication>
     <Name>Microsoft Visual Studio Macros</Name>
     <Version>9.0</Version>
</HostApplication>
<HostApplication>
     <Name>Microsoft Visual Studio</Name>
     <Version>9.0</Version>
</HostApplication>

3. 打開 VS2008, 開啟 【工具】 選單, 再選擇 【选项】,找到 【环境】中的【Add-in/Macro Security】 項目, 把 PInvoke.Net Addin 的安裝子目錄路徑 (C:\Program Files\Red Gate\PInvoke.NET) 加進列表裡面。

4. 重新開啟 VS2008, 你就可以在選單上找到 PInvoke.Net 項目了。在程式碼畫面中, 從該選單中選擇 Insert PInvoke Signatures 就行了。

對於 VS2010, 方法一樣, 但是要把上面 <Version>9.0</Version> 字樣改為 <Version>10.0</Version> 即可。

要使用 PInvoke.Net, 你可以在視窗上方輸入你想要查詢的 Win32 函式, 例如 "InternetOpen", 然後按下 Search 按鈕。如果找到的話, 你就可以在右邊視窗中看到對應的程式碼。不過, 並不是每個 Win32 API 都能找到對應的 C#/VB 碼; 有很多時候, 如果找不到可用的程式碼, 那麼可以按右下角視窗裡面的 Go To Function on PInvoke.Net 連結, 連到官方網站中繼續查詢。它的官網製作得如同 Wiki 一般, 你無需註冊就可以提供建議

 

PInvoke插件 RedGate.PInvokeExtension VS平台调用插件 PInvoke 平台调用 调用C++ 调用系统 C#调C++, Search Module: Directory Constants Delegates Enums Interfaces Structures Desktop Functions: advapi32 avifil32 cards cfgmgr32 comctl32 comdlg32 credui crypt32 dbghelp dbghlp dbghlp32 dhcpsapi difxapi dmcl40 dnsapi dtl dwmapi faultrep fbwflib fltlib fwpuclnt gdi32 gdiplus getuname glu32 glut32 gsapi hhctrl hid hlink httpapi icmp imm32 iphlpapi iprop irprops kernel32 mapi32 MinCore mpr mqrt mscorsn msdelta msdrm msi msports msvcrt ncrypt netapi32 ntdll ntdsapi odbc32 odbccp32 ole32 oleacc oleaut32 opengl32 pdh powrprof printui propsys psapi pstorec query quickusb rasapi32 rpcrt4 scarddlg secur32 setupapi shell32 shlwapi twain_32 unicows urlmon user32 userenv uxtheme version wer wevtapi winfax winhttp wininet winmm winscard winspool wintrust winusb wlanapi ws2_32 wtsapi32 xolehlp xpsprint Smart Device Functions: aygshell coredll ipaqutil rapi Glossary distributed computing LibHolocaust Marshaling Marshalling Marshalling PInvoke test pinvoke Show Recent Changes Subscribe (RSS) Misc. Pages Comments FAQ Helpful Tools Playground Suggested Reading Website TODO List Support Forum Download Visual Studio Add-In Terms of Use Privacy Policy Create page PInvoke (glossary) Summary The mechanism provided by the CLR that enables managed code to call static DLL exports. Access PInvoke.net directly from VS: Terms of Use Edit This Page Find References Show Printable Version Revisions Show changes
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值