Results 1 to 6 of 6

Thread: Howto use API functions without declaring it?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2001
    Location
    San Jose
    Posts
    26

    Unhappy Howto use API functions without declaring it?

    Hi,
    How to use WIN32 API functions without declaring it? Is it possible by useing LoadLibrary()/GetProcAddress() API function or by CreateObject() function? if not then what shall i use for it?

  2. #2
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    not possible, if you want to make an API call to a function / void inside a DLL you must declare it...
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  3. #3
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    What is worng with declaring apis (except that it is very borring and annoying ). The loadlibrary api isn't exactly meant for usage in VB.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  4. #4
    jim mcnamara
    Guest
    You can do this in a limited way. This is from allapi.net -

    Code:
    Create a new project and add this code to Form1
    Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
    Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
    Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
    Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Any, ByVal wParam As Any, ByVal lParam As Any) As Long
    Private Sub Form_Load()
        On Error Resume Next
        'KPD-Team 1999
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        'We're going to call an API-function, without declaring it!
        Dim lb As Long, pa As Long
        'map 'user32' into the address space of the calling process.
        lb = LoadLibrary("user32")
        'retrieve the address of 'SetWindowTextA'
        pa = GetProcAddress(lb, "SetWindowTextA")
        'Call the SetWindowTextA-function
        CallWindowProc pa, Me.hWnd, "Hello !", ByVal 0&, ByVal 0&
        'unmap the library's address
        FreeLibrary lb
    End Sub
    But - Cripsin & Vlatko are right - why go to all this bother?

  5. #5
    Megatron
    Guest
    As a work around, you could declare your most commonly used API's in a module, and whenever you want to use them, just include the module.

  6. #6
    New Member
    Join Date
    Jun 2002
    Posts
    1

    Code Example??

    I am trying to the same thing and have tried that code example from allapi.net
    Once it gets to the callwindowproc the program shuts down. Anyone know why or having the same problem?
    Thanks
    Craig

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