---
title: "C#调用C++的库 P/Invoke工具集 "
author: "yzyzero"
date: "2015-04-28T15:06:13Z"
tags: []
categories: ["编程语言"]
slug: "c-c-p-invoke"
draft: false
lastmod: "2015-04-28T15:06:13Z"
id: 2206791
url: "https://yzyzero.iteye.com/blog/2206791"
---

p/Invoke可以使用工具辅助自动生成，以减少混淆

**1、官方的支持**

http://visualstudiogallery.msdn.microsoft.com/site/search?query=p%2Finvoke&f%5B0%5D.Value=p%2Finvoke&f%5B0%5D.Type=SearchText&ac=4

微软的官方扩展上也有很多

**开源的工具**

http://www.pin5i.com/showtopic-22763.html

看起来微软自己也是深受.NET蹩脚的P/Invoke支持的毒害，因此无奈之余发布了P/Invoke Interop Assistant工具，你可以去下面这个链接来下载这个工具：  
[http://download.microsoft.com/download/f/2/7/f279e71e-efb0-4155-873d-5554a0608523/CLRInsideOut2008\_01.exe](http://download.microsoft.com/download/f/2/7/f279e71e-efb0-4155-873d-5554a0608523/CLRInsideOut2008_01.exe)

实际上这个工具已经开源了，你可以从这里[http://www.codeplex.com/clrinterop/](http://www.codeplex.com/clrinterop/)下载到它的源代码

**2、经典的讨论区** 

http://stackoverflow.com/questions/2495632/easiest-way-to-generate-p-invoke-code

- PInvoker: [http://www.pinvoker.com](http://www.pinvoker.com/)
- P/Invoke Interop Assistant: [http://www.codeplex.com/clrinterop](http://www.codeplex.com/clrinterop)
- P/Invoke Wizard: [http://www.paulyao.com/res/pinvoke/pinvoke.aspx](http://www.paulyao.com/res/pinvoke/pinvoke.aspx)

http://www.paulyao.com/res/pinvoke/pinvoke.aspx

**3、社区评论**

http://through-the-interface.typepad.com/through\_the\_interface/2011/04/pinvoke-tools.html

 

The first tool is [the PInvoke Visual Studio Add-in](http://www.red-gate.com/products/dotnet-development/pinvoke) from [Red Gate Software](http://www.red-gate.com/) (the UK-based provider of various development tools, including Reflector Pro). It appears to be a Visual Studio Add-in for VS2003 and 2005 (I can’t see an update for VS2008 or 2010, which also means I can’t try it). The tool provides simplified access to the excellent [PInvoke.net](http://pinvoke.net/) website, to which I often refer when developing .NET apps. I don’t actually use *that* many P/Invoke statements that I feel I need an Add-In, though – which is perhaps why the add-in doesn’t appear to have been updated for more recent Visual Studio versions – but it seemed worth mentioning.

 

[![PInvoke Visual Studio Add-in menu item](http://through-the-interface.typepad.com/.a/6a00d83452464869e2014e881a2c6f970d-pi "PInvoke Visual Studio Add-in menu item")](http://through-the-interface.typepad.com/.a/6a00d83452464869e2015431f994fc970c-pi)[![PInvoke Visual Studio Add-in dialog](http://through-the-interface.typepad.com/.a/6a00d83452464869e201538e268bf1970b-pi "PInvoke Visual Studio Add-in dialog")](http://through-the-interface.typepad.com/.a/6a00d83452464869e2015431f99510970c-pi)

 

The second – in my opinion more interesting – tool is [the P/Invoke Interop Assistant](http://blogs.msdn.com/b/vbteam/archive/2008/03/14/making-pinvoke-easy.aspx)(here’s [a more in-depth article](http://msdn.microsoft.com/en-us/magazine/cc164193.aspx), [the CodePlex hosting site](http://clrinterop.codeplex.com/) and [a Channel 9 interview with one of the authors](http://channel9.msdn.com/posts/funkyonex/The-P-Invoke-Interop-Assistant/)). This tool generates P/Invoke signatures for use from C# and VB.NET, as well as the ability to determine the P/Invoke signatures used in compiled binaries:

 

- Generating P/Invoke declarations while searching for commonly-used (presumably Win32) functions, structures, messages, etc.

 

 

 

分类: [.net foundation](http://www.cnblogs.com/2018/category/297520.html), [C++ / COM](http://www.cnblogs.com/2018/category/257478.html)