Results 1 to 4 of 4

Thread: Does anyone know of any books that show how to use Windows API in Visual Basic .NET

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2002
    Posts
    121

    Does anyone know of any books that show how to use Windows API in Visual Basic .NET

    I need to work with the Windows API. I've read the help file in VB, MSDN, and other websites, and I can't seem to find any information for things like how to get started writing the code from scratch. There is a walkthrough on MSDN for an example, but it seems that it assumes you know a lot already. It doesn't say how it got some of the information that it tells me to put into my example program, for example the parameters, etc.

    This is one example:

    VB Code:
    1. DllImport(CharSet:=CharSet.Unicode, ExactSpelling:=True)

    It displays this as something I need to put this in my code, but it doesn't say why to use CharSet and any of those values, and it doesn't say how I'm supposed tell when I need to use values like this.

    Also, it doesn't say why to use ByVal, etc.

    Obviously, I have a lot to learn. Does anyone know of any books for beginners for Windows API .NET, or any way that I can learn this by myself?

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Does anyone know of any books that show how to use Windows API in Visual Basic .NET

    Depending on your needs, the basics would be to pass the dll library name and entry point.

    VB Code:
    1. Option Explicit On
    2.  
    3. Imports System.Runtime.InteropServices
    4.  
    5. Public Class Class1
    6.  
    7.     Inherits System.Windows.Forms.Form
    8.  
    9.     <StructLayout(LayoutKind.Sequential)> _
    10.     Public Structure SYSTEM_INFO
    11.         Public dwOemID As Int32
    12.         Public dwPageSize As Int32
    13.         Public wProcessorArchitecture As Int32
    14.         Public lpMinimumApplicationAddress As Int32
    15.         Public lpMaximumApplicationAddress As Int32
    16.         Public dwActiveProcessorMask As Int32
    17.         Public dwNumberOrfProcessors As Int32
    18.         Public dwProcessorType As Int32
    19.         Public dwAllocationGranularity As Int32
    20.         Public dwReserved As Int32
    21.     End Structure
    22.  
    23.     <DllImport("kernel32", EntryPoint:="GetSystemInfo")> _
    24.     Private Shared Function GetSystemInfo(ByRef lpSystemInfo As SYSTEM_INFO) As Int32
    25.     End Function
    26.  
    27.     Public Blah, blah, blah.....
    28.  
    29.     End Sub
    30.  
    31. End Class
    You should download the API Viewer utility from allapi.net and set the format to VB.NET. Makes life a little easier.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2002
    Posts
    121

    Re: Does anyone know of any books that show how to use Windows API in Visual Basic .NET

    Thanks. .NET and Visual Basic 6 use different coding for Windows API, right? So I've been assuming that researching Windows API in VB6 would be useless. Is that true?

  4. #4
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Does anyone know of any books that show how to use Windows API in Visual Basic .NET

    No, not useless. You can still see how the api functions are called and used. The data types are a little different, like Long in VB6 is Integer in VB.NET and things like that. The APIViewer 2004 prog in my link has a .NET mode (change in options, as it starts in VB6 mode) where you can lookup the function declarations, constants, structures, etc that are needed. Then its just a matter of copying and pasting...

    For examples on functions you are trying to use, usually sticking "VB.NET" into Google along with the function name will pull .NET examples of the API functions you are trying to use.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width