Udostępnij za pośrednictwem


In VB6 we had the API Viewer, In VB .NET you get the P/Invoke Interop Assistant

VB6 programmers will remember a useful little utility called the API Viewer, the helped out when you needed to make a Windows API call.

clip_image002

There is now an equivalent tool for .NET, the P/Invoke Interop Assistant (https://www.codeplex.com/clrinterop ). Not surprisingly it does a little bit more, so as well as enabling you to look up the signature for a particular call, it will also translate snippets of C code.

clip_image004

Notice that it generates required structure definitions to go with your function call!

I also noticed that the P/Invoke Interop Assistant generated code that used the DllImport approach to setting up the API call. I expect this question has been answered loads of times before, but what are the advantages of using DllImport rather than Declare in your VB code? The obvious answer is that DllImport is a .NET way of doing things, but for VB6 programmers of the Declare statement looks much more natural. DllImport does offer much finer control over the way the call is made, but unless you need this fine control you can stick with Declare.

Comments

  • Anonymous
    June 08, 2009
    I have been sitting on a long list of part finished posts on Visual Basic “stuff” intended for my other