Announcement

Collapse
No announcement yet.

Has anyone gotten a compiled Dll to work with VB, VBA or VBSCRIPT?

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

  • Has anyone gotten a compiled Dll to work with VB, VBA or VBSCRIPT?

    I can not seem to create an object created in powerbasic in any of the above languages.

    I am using this
    Code:
    #COMPILE DLL "TESTITEM.DLL
    #DIM ALL
    #COM NAME "IITEM"
    #COM GUID GUID$("{1594918F-1131-488C-A11E-CFAFB4A17D31}")
    #COM TLIB ON
    
    $MyClassGuid = GUID$("{00000099-0000-0000-0000-000000000008}")
    $MyIfaceGuid = GUID$("{00000099-0000-0000-0000-000000000009}")
    
    CLASS MyClass $MyClassGuid AS COM
      INTERFACE MyInterface $MyIfaceGuid
        INHERIT dual
        METHOD Method1(parm AS LONG)
          'CALL abc(parm)
        END METHOD
      END INTERFACE
    END CLASS
    I compile this, once compiled I use regsvr32.exe to import (I checked the registry and nothing is there) and then try to use in vb/vba using the tlb and I can not create the object. OLEVW lists this as not creatable.

    Any help would be appreciated.
    Sr. Software Development Engineer and Sr. Information Security Analyst,
    CEH, Digital Forensic Examiner

  • #2
    You need to embed the tlb in the dll using PBTYP.EXE
    Or use a resource script as in my example
    James

    Comment


    • #3
      Thanks JC,

      I used both of those methods and neither one worked.

      No matter what I do this object is listed as notcreatable in OLEVIEW
      Last edited by Thomas Tierney; 25 Aug 2008, 10:15 AM.
      Sr. Software Development Engineer and Sr. Information Security Analyst,
      CEH, Digital Forensic Examiner

      Comment


      • #4
        I am probably the worst OOP's or COM man on the board so please take this comment for what its worth. I understand PB only creates inprocess servers so are you placing PB server as you would a normal DLL preferably in the same folder as the program

        Comment


        • #5
          I don't want to put a innuendo of some kind but I believe there is a
          problem with the IDispatch.

          I have a problem where passing an IDispatch to an ActiveX causes
          a GPF. In VB this works perfectly

          I need to do more testing and hope to put together some package for the support dept. during the week

          Cheers

          Steven
          So here we are, this is the end.
          But all that dies, is born again.
          - From The Ashes (In This Moment)

          Comment


          • #6
            Steven,

            In general, have you gotten this to work in VB or VBScript? or was this vb.net?

            Thanks
            Sr. Software Development Engineer and Sr. Information Security Analyst,
            CEH, Digital Forensic Examiner

            Comment


            • #7
              Originally posted by John Petty View Post
              I am probably the worst OOP's or COM man on the board so please take this comment for what its worth. I understand PB only creates inprocess servers so are you placing PB server as you would a normal DLL preferably in the same folder as the program
              The location of the Dll should be irrelevent as the location, after calling dllregisterserver() via RegSvr32.exe, should be in the registry. Problem is that I dont even see it in the registry after importing the tlb and registering.
              Sr. Software Development Engineer and Sr. Information Security Analyst,
              CEH, Digital Forensic Examiner

              Comment


              • #8
                Thomas,

                In VB 6 the passing of an object is not an powerbasic object. It's an object
                that is created using the CreateObject statement in Visual Basic 6.

                However, the ActiveX requires for that certain method that I use an IDispatch
                now, the MFC equivalent speaks of a LPDISPATCH *lp which is a pointer to a dispatch. The COM browser specifies an IDispatch as a parameter for the method.

                Like I said, before I come to my conclusion I have to do some more testing. Hopefully it's me who doing something fuzzy.
                So here we are, this is the end.
                But all that dies, is born again.
                - From The Ashes (In This Moment)

                Comment


                • #9
                  Originally posted by Thomas Tierney View Post
                  The location of the Dll should be irrelevent as the location, after calling dllregisterserver() via RegSvr32.exe, should be in the registry. Problem is that I dont even see it in the registry after importing the tlb and registering.
                  Have you tried opening the dll with PBrow or TLB_400??

                  James

                  Comment


                  • #10
                    The easiest method of embedding a typlib in your dll is with a resource file.

                    Contents of YourDll.Rc
                    1 TYPELIB "YourDll.Tlb"

                    Load and compile the rc file to a pbr and use in your source.

                    #RESOURCE "YourDll.Pbr"


                    James

                    Comment


                    • #11
                      I don't see why a typelib is required for actual execution.
                      Afaik it's only useful for combrowsers to extract the interface's definitions.

                      So if you have a valid interface description in the language using this dll, you should be ok.
                      If you don't, using the late bound option can be useful.
                      no need to describe the functions with that one.

                      Note that i tried this under .NET and that one complaints not having a constructor.
                      Even while the Create method was available.
                      Maybe some return value in the addref part is not ok, but what do i know..?
                      ??
                      hellobasic

                      Comment


                      • #12
                        Edwin,

                        Everything I see tells me that these objects are not creatable using CreateObject() from vbscript. If anyone has gotten this to work could you post the steps and a sample? I am not trying to do anything incredible.. just trying to call a method that pops up a message box.

                        Thanks
                        Sr. Software Development Engineer and Sr. Information Security Analyst,
                        CEH, Digital Forensic Examiner

                        Comment


                        • #13
                          Got it using VB6:
                          James

                          sever code:
                          Code:
                          '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
                          'SED_PBWIN
                          '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
                          '
                          'Compile this first.
                          '******************************************************************************
                          '                            James C. Fuller
                          '                            August 8, 2008
                          '                         [email protected]
                          '******************************************************************************
                          #COMPILE DLL "JCFSERV.DLL
                          #DIM ALL
                          #COM NAME "JCFServer",1.0
                          #COM GUID GUID$("{C7214A4E-D4F7-456C-9F4A-994B56091E95}")
                          #COM TLIB ON
                          'This embeds the Typelib in the dll using José's SED
                          ''''''''%   RC TEXT 1 TYPELIB "JCFSERV.tlb"
                          #RESOURCE "JCFSERV.PBR"
                          
                          $cJcfServGuid = GUID$("{34D68488-BD5E-4F80-B060-84E373F4D112}")
                          $iJcfServGuid = GUID$("{E211F708-8350-4CBE-B3B3-C6BD70E25108}")
                          
                          
                          CLASS cJcfServ $cJcfServGuid AS COM
                          	INSTANCE L1 AS LONG
                              INTERFACE iJcfServ $iJcfServGuid : INHERIT DUAL
                          
                                  METHOD DoIt<101>() AS LONG
                          			?"I Am Here"+$CR + FORMAT$(L1)
                                  END METHOD
                          		METHOD GetString() AS STRING
                          			METHOD = UCODE$("James Fuller")
                          		END METHOD
                          		PROPERTY GET L1<102>() AS LONG
                          			PROPERTY = L1
                          		END PROPERTY
                          		PROPERTY SET L1<102>(BYVAL Param AS LONG)
                          			L1 = Param
                          		END PROPERTY
                              END INTERFACE
                          
                          END CLASS

                          '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*

                          VB6 Form with a button and edit.Make sure you reference the server


                          Code:
                          Public oJcf As JCFServer.IJCFSERV
                          Private Sub Command1_Click()
                          
                                  Dim L2 As Integer
                                  Dim S1 As String
                                  
                                  Set oJcf = CreateObject("CJCFSERV")
                                  oJcf.L1 = 7
                                  L2 = oJcf.DOIT()
                                  S1 = oJcf.GETSTRING
                                  Text1.Text = S1
                          End Sub
                          Last edited by jcfuller; 25 Aug 2008, 03:29 PM.

                          Comment


                          • #14
                            I did just install VB6.
                            The normal notation using New and such does not work:
                            I get a Run-time error '91'
                            Object not set.

                            Objectbrowser:
                            Class CLASS1
                            Member of PwrDev_COM_server

                            'New' is getting me:

                            ---------------------------
                            Microsoft Visual Basic
                            ---------------------------
                            Compile error:

                            Invalid use of New keyword
                            ---------------------------
                            OK Help
                            ---------------------------

                            Private Sub Command1_Click()
                            Dim c As CLASS1
                            Set c = New CLASS1
                            MsgBox c.MyClassMethod(11)
                            End Sub

                            My call in the objectbrowser:
                            Function MyClassMethod(PARAM As Long) As String
                            Member of PwrDev_COM_server.CLASS1
                            hellobasic

                            Comment


                            • #15
                              Thats where I am hung up too Edwin, the new keyword. I then fired up OLEVIEW and took a look at the object and that is where I found it to be "noncreatable". This is beginning to becom frustrating. Also, Edwin, can you verify whether or not the class information including GUIDS is located in the HKEY ROOT? On my machine, when registering, nothing shows up in the registry. I have searched all guids and class names and see nothing there.

                              Thanks
                              Sr. Software Development Engineer and Sr. Information Security Analyst,
                              CEH, Digital Forensic Examiner

                              Comment


                              • #16
                                Edwin, Thomas
                                My last example doesn't work for you???

                                James

                                Comment


                                • #17
                                  Odd is that i can't find 'Interface1' in VB6
                                  In .NET it showed afaik.
                                  (The .NET topic: http://www.powerbasic.com/support/pb...ad.php?t=38312 )

                                  my PwrDev_COM_server pops up at :
                                  HKEY_CLASSES_ROOT\CLASS1

                                  HKEY_CLASSES_ROOT\CLASS1\CLSID > {8F6D0C85-EE8E-4678-BA22-C3E904BA05F0}
                                  Which is the GUID of my class, not the dll.
                                  --
                                  HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLASS1
                                  and clsid.

                                  Boring stuff, but the typelib is registered with 1.0
                                  Maybe we mis a version?
                                  hellobasic

                                  Comment


                                  • #18
                                    Originally posted by jcfuller View Post
                                    Edwin, Thomas
                                    My last example doesn't work for you???

                                    James
                                    Maybe it does but it will be late bound.
                                    Just 'making it to work' is not always good.
                                    hellobasic

                                    Comment


                                    • #19
                                      I know nothing of vb but the last section of this page indicates that the code I posted is in fact early binding???

                                      http://kandkconsulting.tripod.com/VB...g_tutorial.htm

                                      James

                                      Comment


                                      • #20
                                        Hi James,

                                        is the resource file necessary in order to get your example to work?

                                        I tried compiling without the resource, and registered the dll successfully.

                                        When I attempted to reference the .tlb in the Access module I received the following error...

                                        Code:
                                        Microsoft Visual Basic
                                        Error in loading DLL
                                        [OK] [Help]
                                        On pressing help...

                                        Code:
                                        Error in loading DLL (Error 48)
                                           
                                        A dynamic link library (DLL) is a library specified in the Lib clause of a Declare statement. This error has the following causes and solutions: 
                                        
                                        The file isn't DLL-executable. 
                                        If the file is a source-text file, it must be compiled and linked to DLL executable form. 
                                        
                                        The file isn't a Microsoft Windows DLL. 
                                        Obtain the Microsoft Windows DLL equivalent of the file. 
                                        
                                        The file is an early Microsoft Windows DLL that is incompatible with Microsoft Windows protect mode. 
                                        Obtain an updated version of the DLL. 
                                        
                                        The DLL references another DLL that isn't present. 
                                        Obtain the referenced DLL and make it available to the other DLL. 
                                        
                                        The DLL or one of the referenced DLLs isn't in a directory specified by your path. 
                                        Move the DLL to a referenced directory or place its current directory on the path.
                                        David

                                        Comment

                                        Working...
                                        X