CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2007
    Posts
    3

    VB 6 API Programming

    I would like to design the program in VB 6.0 for the following activity:
    1) open the Excel file
    2) Read the API function name, required parameters value.
    3) Call the API
    4) Store the result in other excel file.

    Is it possible with VB 6.0?

    Please help.

  2. #2
    Join Date
    Oct 2006
    Posts
    327

    Re: VB 6 API Programming

    hello,
    1) open the Excel file
    2) Read the API function name, required parameters value.
    3) Call the API
    4) Store the result in other excel file.
    I hardly understand (just guess... without being quite sure)

    1) what does "open the Excel file" mean ? would it be "open an existing and known excel File ?

    2) When tou say " Read the API function name, required parameters value",; what do you exactly mean ? Read from where ?

  3. #3
    Join Date
    May 2002
    Posts
    10,943

    Re: VB 6 API Programming

    If you are talking about the API calls being held in an Excel file, then no, you cannot. You cannot add and subtract code from an EXE during runtime.

    If you desire to write a log file, that is very simply done, but why you would use Excel for that, I don't know. Do some searching in the forums. Plenty of code is provided to help you work with Excel.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  4. #4
    Join Date
    Aug 2006
    Posts
    145

    Re: VB 6 API Programming

    Quote Originally Posted by PeejAvery
    You cannot add and subtract code from an EXE during runtime.
    True, but you can dynamically load and call procedures within DLLs.

    Use LoadLibrary to load the dll, GetProcAddress to get the address of the function, and, at it's most simple use CallWindowProc to call the function: Example at AllAPI.net

    You're limited to 4 parameters using CallWindowProc and I'm not sure passing 0& to unused parameters is completely safe, but you can circumvent this by using SoftCircuits' CallPtr dll:
    Code:
    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 CallAPI Lib "CALLPTR.DLL" Alias "scCallPtr" ( _
        ByVal pProc As Long) As Long
        
    Private Declare Function CallAPIWithArgs2 Lib "CALLPTR.DLL" Alias "scCallPtr" ( _
        ByVal pProc As Long, ByVal arg1 As Any, ByVal arg2 As Any) As Long
    
    Private Sub Command1_Click()
        Dim hLib As Long, hProc As Long
        
        hLib = LoadLibrary("user32")
        
        hProc = GetProcAddress(hLib, "SetWindowTextA")
        Debug.Print CallAPIWithArgs2(hProc, Me.hWnd, "Test")
        
        hProc = GetProcAddress(hLib, "GetDesktopWindow")
        Debug.Print CallAPI(hProc)
        
        FreeLibrary hLib
    End Sub

  5. #5
    Join Date
    May 2002
    Posts
    10,943

    Re: VB 6 API Programming

    Quote Originally Posted by bushmobile
    True, but you can dynamically load and call procedures within DLLs.
    Ah yes. How could I forget that.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  6. #6
    Join Date
    Nov 2005
    Location
    Omaha, Nebraska, USA
    Posts
    696

    Re: VB 6 API Programming

    There is also a pure VB way of doing that:
    http://www.planet-source-code.com/vb...32873&lngWId=1

    Nifty piece of code lets you put DLLs wherever and call their functions, not just force them into the system32 directory or add to the PATH environment variable.

    I've only tested it with a DLL that takes two strings as it's parameters, but that works perfectly.

  7. #7
    Join Date
    Mar 2007
    Posts
    3

    Re: VB 6 API Programming

    Thanks Bushmobile.
    you got it right what I actually want to say.
    Still SoftCircuits' CallPtr.dll having limitation i.e. you cannot use a string
    argument here because Visual Basic converts strings to ANSI when calling DLL functions.
    Some functions which I need to call requires string parametr then how to tackle this problem.

    PeejAvery:
    "you can dynamically load and call procedures within DLLs."
    Plesae tell me how to do this. Code sample will be very helpful.

  8. #8
    Join Date
    Aug 2006
    Posts
    145

    Re: VB 6 API Programming

    Quote Originally Posted by g_bhujbal
    Thanks Bushmobile.
    you got it right what I actually want to say.
    Still SoftCircuits' CallPtr.dll having limitation i.e. you cannot use a string
    argument here because Visual Basic converts strings to ANSI when calling DLL functions.
    I used a string in my example.

    Quote Originally Posted by g_bhujbal
    PeejAvery:
    "you can dynamically load and call procedures within DLLs."
    Plesae tell me how to do this. Code sample will be very helpful.
    he was quoting me, and i demonstrated it in my post, also check out ChaosTheEternal's post


    @ChaosTheEternal: nice link!

  9. #9
    Join Date
    Mar 2007
    Posts
    3

    Re: VB 6 API Programming

    Thanks

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

Featured