Announcement

Collapse
No announcement yet.

PB code to replace Regsvr32?

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

  • PB code to replace Regsvr32?

    I was wondering if anyone has code to replace the "standard" Windows Regsvr32. I would hate to spoil my tiny PB exe by shelling out to Regsvr32.

    Thanks In Advance,

    Rich
    _____________________________________________________________________________________
    It's hard when you're up to your armpits in alligators to remember you came here to drain the swamp.
    President Reagan
    February 10, 1982

  • #2
    Can I ask what you are trying to achieve? DLL's created with PB/DLL are 'standard' DLL's and do not need to be registered like OCX's.

    Philippe Monteil (sorry If I spelt you name wrong Philippe!) who created JA/COMPB may be able to help you with this as he has vast experience with COM libraries. Philippe? Are you listening?


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Lance,

      Essentially, it is going to be a "home grown" installer. One required feature is the ability to register and unregister ActiveX components.

      Thanks,

      Rich

      ------------------
      _____________________________________________________________________________________
      It's hard when you're up to your armpits in alligators to remember you came here to drain the swamp.
      President Reagan
      February 10, 1982

      Comment


      • #4
        Rich,

        I'm on seriously thin ice here, but to the best of my knowledge all Regsvr32 does is call the DLL's DLLRegisterServer and DLLUnregisterServer procs. I've even read somewhere that that's how you determine if a DLL should be registered: Look at the export table with QuickView, and see if those two procs are present.

        I searhced MSDN for info on DllRegisterServer, and it looks like it's easy (with Microsoft's kind permission, I hope):

        DllRegisterServer
        Instructs an in-process server to create its registry entries for all classes supported in this server module. If this function fails, the state of the registry for all its classes is indeterminate.

        Code:
        STDAPI DllRegisterServer(void);
        Return Values
        This function supports the standard return values E_OUTOFMEMORY and E_UNEXPECTED, as well as the following:

        S_OK
        The registry entries were created successfully.
        SELFREG_E_TYPELIB
        The server was unable to complete the registration of all the type libraries used by its classes.
        SELFREG_E_CLASS
        The server was unable to complete the registration of all the object classes.
        DLLUnregisterServer is pretty much the same:

        DllUnregisterServer
        Instructs an in-process server to remove only those entries created through DllRegisterServer.

        Code:
        STDAPI DllUnregisterServer(void);
        Return Values
        This function supports the standard return values E_OUTOFMEMORY and E_UNEXPECTED, as well as the following:

        S_OK
        The registry entries were created successfully.
        S_FALSE
        Unregistration of this server's known entries was successful, but other entries still exist for this server's classes.
        SELFREG_E_TYPELIB
        The server was unable to remove the entries of all the type libraries used by its classes.
        SELFREG_E_CLASS
        The server was unable to remove the entries of all the object classes.
        Hope this helps!

        Ketil


        ------------------

        Comment


        • #5
          This is how I do it in VB. I am new to PB so I can't port. Give me a couple hours.

          Code:
          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 CreateThread Lib "kernel32" (lpThreadAttributes As Any, _
             ByVal dwStackSize As Long, ByVal lpStartAddress As Long, ByVal lParameter As Long, _
             ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
             
          Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, _
              ByVal dwMilliseconds As Long) As Long
             
          Private Declare Function GetExitCodeThread Lib "kernel32" (ByVal hThread As Long, _
              lpExitCode As Long) As Long
          
          Private Declare Sub ExitThread Lib "kernel32" (ByVal dwExitCode As Long)
          
          Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
          
          Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
          
          Private Function RegUnReg(ByVal inFileSpec As String, Optional Register As Boolean = True) As String
              On Error Resume Next
              
              Dim lLib As Long                 ' Store handle of the control library
              Dim lpDLLEntryPoint As Long      ' Store the address of function called
              Dim lpThreadID As Long           ' Pointer that receives the thread identifier
              Dim lpExitCode As Long           ' Exit code of GetExitCodeThread
              Dim mThread As Long
              Dim mResult As Long
              
              ' Load the control DLL
              lLib = LoadLibrary(inFileSpec)
              If lLib = 0 Then
                   ' e.g. file not exists or not a valid DLL file
                  RegUnReg = "ERROR: Failure loading control DLL"
                  Exit Function
              End If
              
              ' Find and store the DLL entry point
              If Register Then
                  lpDLLEntryPoint = GetProcAddress(lLib, "DllRegisterServer")
              Else
                  lpDLLEntryPoint = GetProcAddress(lLib, "DllUnregisterServer")
              End If
              
              If lpDLLEntryPoint = vbNull Then
                  RegUnReg = "ERROR: Failed in obtaining entry point. Not a ActiveX DLL/OCX."
                  'Decrements the reference count of loaded DLL module before leaving
                  FreeLibrary lLib
                  Exit Function
              End If
              
              ' Create a thread to execute within the virtual address space of the calling process
              mThread = CreateThread(ByVal 0, 0, ByVal lpDLLEntryPoint, ByVal 0, 0, lpThreadID)
              If mThread = 0 Then
                  RegUnReg = "ERROR: Failed in creating processing thread."
                  'Decrements the reference count of loaded DLL module before leaving
                  FreeLibrary lLib
                  Exit Function
              End If
              
              ' Use WaitForSingleObject to check the return state (i) when the specified object
              ' is in the signaled state or (ii) when the time-out interval elapses.
              mResult = WaitForSingleObject(mThread, 10000)
              If mResult <> 0 Then
                  RegUnReg = "ERROR: Failed in signaled state or time-out."
                  FreeLibrary lLib
                  ' Terminate the thread to free up resources that are used by the thread
                  ' NOTE: Calling ExitThread for an application's primary thread will cause
                  ' the application to terminate
                  lpExitCode = GetExitCodeThread(mThread, lpExitCode)
                  ExitThread lpExitCode
              End If
              
              ' Don't call the dangerous TerminateThread() VB doesnt like it. After the last handle
              ' to the object is closed, the object is removed from the memory.
              CloseHandle mThread
              FreeLibrary lLib
              
          End Function
          Question?

          Why not just use one of the many free ones on the internet or one of the commercial products?

          "The wheel has been invented."


          ------------------


          [This message has been edited by Shawn Tartaglia (edited March 24, 2000).]

          Comment


          • #6
            Thanks everyone. I really do appreciate your help.

            Shawn - I have a couple of applications for the code. :-) I understand exactly what you are saying about "reinventing the wheel."

            Rich

            ------------------
            _____________________________________________________________________________________
            It's hard when you're up to your armpits in alligators to remember you came here to drain the swamp.
            President Reagan
            February 10, 1982

            Comment


            • #7
              Lance,

              the information about the DllRegisterServer/UnRegisterServer
              COM standard entry points is fine.

              The method to register/unregister an EXE COM server is different: you will have to launch it with a "/REGSERVER" parameter to register , and "/UNREGSERVER" to unregister it.

              Philippe


              ------------------

              Comment

              Working...
              X