|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThis article describes the PInvokeLib Visual Studio Add-in. This tool will help you organize P/Invoke signatures that you use regularly in your application. Hopefully, you will not find this tool outdated since it provides several features not found in other tools. BackgroundOne website that I visit regularly is pInvoke.net. This is a pretty cool website with a web service back-end. Similarly, it provides a Visual Studio add-in to communicate with their service and let you insert P/Invoke signatures in your program. I'm sure this website will continue to serve the .NET community for years to come. PInvokeLib is intended to complement such a tool by letting you organize your own library as well. In fact, you can almost cut and paste functions from the MSDN or your own header files. Only minor modifications may be required. PInvokeLib supports the following programming languages: C#, VB .NET, and MC++. Getting StartedThe PInvokeLib Manager has two tabs. The Module tab is where you can insert P/Invoke signatures. Currently, only functions and structures can be added. Use the Define tab to define your functions and structures. You can Add, Update, Delete, and Search a definition. Search is limited to selected modules only. Search can also use the wildcard character (*). Inserting an API Function
Note: Most C types are already defined, and can be reused as is. C pointers other than character strings are not supported. PInvokeLib will convert any unknown types to uppercase, and make them easier to find. I believe this will make life easier for you, in case you need to define your own struct later. Inserting a Structure
Advanced FeaturesFunction argument direction support P/Invoke signatures can be specified to have function arguments passed by value (default), by reference, or output only. This is supported only for function prototypes. PInvokeLib supports the following extensions for parameters:
For example, let's import [DllImport("ShlwAPI.dll")]
public static extern String PathAddBackslashW([In,Out]String lpszPath)
But, for you to get correct results, the input parameter should be a using System;
using System.IO;
using System.Text;
using System.Runtime.InteropServices;
namespace PInvokeLib
{
class PInvoke
{
[DllImport("ShlwAPI.dll")]
public static extern String PathAddBackslashW([In,Out]StringBuilder lpszPath);
public static void Main(string[] args)
{
StringBuilder sb = new StringBuilder(@"c:\temp\temp", 200);
PathAddBackslashW(sb);
Console.WriteLine("Path with extra slash:"+ sb);
}
}
}
InstallationThe PInvokeLib add-in is fully supported by Visual Studio 2005 and 2008. Extract all the files in PInvokeAddin_Bin.zip to:
Then, make sure you enable the add-in from the Add-in Manager (Tools->Add-in Manager...). Start the add-in from the context menu (right click in the text editor).
HistoryLast Updated [02/26/08]This update will accept The SpecImporter class library is available - a parser class based on CocoR. Feel free to reuse this library in your own program. As always, enjoy!
|
||||||||||||||||||||||