Announcement

Collapse
No announcement yet.

From VB to PB: Again...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • From VB to PB: Again...

    Hi all

    In PB, how do I make a reference to a DLL and use the objects in it?

    Thanks

  • #2
    Suggest that you take a look at the WINAPI subdirectory of your PBWin installation. The .INC files contain all that you need for most "popular" dlls, by #INCLUDing them in your program, you can just call the function by name. Also, look at the Samples folder and the compiler help.

    Comment


    • #3
      Originally posted by Virginio Reis View Post
      Hi all

      In PB, how do I make a reference to a DLL and use the objects in it?

      Thanks
      I suspect a VB DLL is used here..
      hellobasic

      Comment


      • #4
        yes Edwin, it is a vb DLL.

        And, Chris, what about if the DLL I want to use isn't there?

        Comment


        • #5
          For a COM (ActiveX) DLL, you need to create an .INC file using the PB COM Browser. You should probably read up oin how to deal with COM DLLs in the help file before doing so.

          Comment


          • #6
            Was just going to post what Knuth just wrote Virginio. What specific dll/functionality are you looking for? It makes a difference for anyone here to offer specific advice.
            Fred
            "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

            Comment


            • #7
              SQLDMO is the DLL I want to use

              Comment


              • #8
                just for info, here is the VB& code to enumerate the SQL servers in a network (SQLDMO was added as a reference):
                Code:
                Private Sub Form_Load()
                  On Error GoTo ErrorHandler
                  Dim oSQLServerDMOApp As SQLDMO.Application
                  Dim i As Integer
                  
                  'Use the SQL DMO Application Object to find the available SQL Servers
                  Set oSQLServerDMOApp = New SQLDMO.Application
                  
                  Dim namX As NameList
                  Set namX = oSQLServerDMOApp.ListAvailableSQLServers
                  For i = 1 To namX.Count
                    txtServer.AddItem namX.Item(i)
                  Next
                  'Show top server
                  txtServer.ListIndex = 0
                  
                  Set oSQLServerDMOApp = Nothing
                  Exit Sub
                  
                ErrorHandler:
                  Set oSQLServerDMOApp = Nothing
                  MsgBox Err.Description
                End Sub
                It is very simple. that is why I would like to be able to use the SQLDMO DLL

                Comment


                • #9
                  This is an example using late binding (untested, because I don't have SQLServer installed in my computer). See the help file to learn how to use early binding.

                  Code:
                  #COMPILE EXE
                  #DIM ALL
                  #INCLUDE "WIN32API.INC"
                  
                  FUNCTION PBMAIN () AS LONG
                  
                    Dim oSQLServerDMOApp As Dispatch
                    Dim i As Integer
                    Dim vRes AS Variant
                    Dim nCount AS Long
                    Dim vIdx AS Variant
                    Dim vItem AS Variant
                    Dim strItem AS String
                    Dim namX As Dispatch
                    
                    'Use the SQL DMO Application Object to find the available SQL Servers
                    oSQLServerDMOApp = New Dispatch In "SQLDMO.Application"
                    If IsNothing(oSQLServerDMOApp) Then Exit Function
                    
                    Try
                       Object Call oSQLServerDMOApp.ListAvailableSQLServers TO vRes
                       namX = vRes
                       Object Get namX.Count To vRes
                       nCount = Variant#(vRes)
                       For i = 1 To nCount
                          vIdx = i
                          Object Call namX.Item(vIdx) To vItem
                          strItem = Variant$(vItem)
                          MSGBOX strItem
                       Next
                    Catch
                       MSGBOX "Error &H" & Hex$(Objresult)
                    Finally
                       oSQLServerDMOApp = Nothing
                    End Try
                  
                  END FUNCTION
                  Last edited by José Roca; 15 Mar 2008, 09:56 PM.
                  Forum: http://www.jose.it-berater.org/smfforum/index.php

                  Comment


                  • #10
                    Small correction to Jose's code. The line:
                    Code:
                    Object Call namX.Item To vItem
                    Should be:
                    Code:
                    Object Call namX.Item(vIdx) To vItem
                    Other than that, it works fine here!

                    Regards,

                    Pete.

                    Comment


                    • #11
                      Thanks for spotting it. I have modified the code.
                      Forum: http://www.jose.it-berater.org/smfforum/index.php

                      Comment


                      • #12
                        It works great. One thing I didn't get: Where are you including the SQLDMO Dll? in the win32api.inc?

                        Thank You guys

                        Comment


                        • #13
                          Nowhere. The instruction New Dispatch In "SQLDMO.Application" retrieves the ClsID from the registry and calls CoCreateInstance, that loads the DLL and creates and instance of the Application class.
                          Forum: http://www.jose.it-berater.org/smfforum/index.php

                          Comment


                          • #14
                            In Visual Basic, your code there was using early binding; you referenced the DLL and then created an instance of the object. The code that José posted uses late binding; it would be the same as if you had used CreateObject to create an instance of the object.
                            Mike Stefanik
                            sockettools.com

                            Comment

                            Working...
                            X