• Registering Dlls programatically (VB6)

    Author
    Topic
    #409455

    Im trying to register dll’s programatically, however so far i’ve only been able to find examples written in C, or examples where you need to know the name of the dll at design time.

    I want to be able to pass a dll/ocx with its path to a function which will then register/unregister it (depending on what I specify) and have a return code if it fails, i.e. the example I saw in C returned a -3 when the user ran it and he was then told that the -3 meant the file was in use.

    Alternatively, if anyone knows where I can download a dll that already does this could you post the link (it doesnt have to be a free dll).

    Any help would be much appreciated as im this ‘ ‘ close to giving it up as a bad job and using regsvr32 in silent mode and ignoring the errors completely – but that would be completely unprofessional of me!

    Viewing 3 reply threads
    Author
    Replies
    • #872599

      Phil

      Creating a package with the Package and Deployment wizard, will register any dependent dll’s or ocx’s.
      Just creating an EXE won’t.

      I use coding in my project of a known local location, to copy the library or control and then register it programatically as below.
      But, if I create a distributable package, the code is not required because any dependencies are automatically registered.
      Although I copy my control to the local folder, this code registers each time the EXE is run , hence I dropped it out of my project.

       'Copy MSMAPI32.ocx File
      If Dir(strLocalFolder & "MSMAPI32.ocx") = "" Then
             FileCopy "D:UtilitiesMSMAPI32.ocx", strLocalFolder & "MSMAPI32.ocx"
             'strLocalFolder is C:MM-Utilities
      End If
      'Register It
      Shell ("C:MM-Utilitiesregsvr32.exe /s MSMAPI32.ocx")
      • #872613

        Thanks for your reply but I think you missed my point.

        Firstly, I was under the impression using regsvr32 either gave a message box or no error at all if running in silent. Due to the nature of the program I need to put the error message in a caption on a form so I need to be able to actually capture the error code if there is one.

        Secondly, im not using the deployment wizard. My program is an update program which downloads files from our FTP site when they are updated (similar to norton live update if you want a comparison).

        The user installs our program using the installshield application I have created.
        The updater then is used to update existing files and possibly add new files.
        Where a dll is concerned, it is entirely possible something could happen while running the app, so I’d prefer to un-register the current dll, archive it, copy over the new dll then register it.

        This method does produce a few issues regarding uninstalling the product, but we already have such issues which wont be resolved in the near future, so adding to them wont hurt!
        In an ideal world i’d create update files using installshield and have them so they can be run from the web, but I had to wing it when creating the installer as it was, so i’ll definately need a few courses in installshield before tackling the update scenario! Unfortunately, there just isnt time at the moment.

        • #872625

          Sorry I couldn’t help Phil, and I don’t have a Dodge Viper either evilgrin

          • #872641

            Edited by StuartR to make link active – see Help 19

            No probs Dave thanks all the same though. Bit of a weird one to explain! However, i’ve been given the following link which im just testing now:
            http://www.codeguru.com/vb/controls/vb_act…icle.php/c3479/%5B/url%5D

            As for the Viper, i’m still hoping for that elusive lottery win!

            • #873550

              Don’t know if you got this sorted out yet, but if interested see attached text file, demonstrates one way to register COM components (.DLL, .OCX) w/o relying on RegSvr32.exe and w/o having to “hard code” the API function declarations for DllRegisterServer and DllUnregisterServer, which RegSvr32 calls from the file being registered (all inprocess COM servers are “required” to export these two functions for self-registration purposes). See RegisterDLL function, which can be used for both registering & unregistering component. The function returns zero on success, or an error code (WIN32 or user-defined constant) which may be helpful in troubleshooting errors. Note that I had to resort to some user-defined errors because if you check the MSDN documentation for DllRegisterServer (some excerpts included in attached file), upon error the function can return several error codes, some general, some specific such as SELFREG_E_TYPELIB and SELFREG_E_CLASS – but if you look these up in the applicable C++ header file (OLECTL.H) (they aren’t found in the standard WIN32API.TXT file) the DEFINE statements make use of the C++ MAKE_SCODE macro to define value (no relation to a VBA macro!) – and I am not sure of how to translate this type of #DEFINE to a VB CONST declaration (and am too lazy to look it up in some incomprehensible C++ text). So simply used a user-defined error constant if call to DllRegisterServer failed. Note also, to avoid “hard-coding”, use of GetProcAddress to get function address in target DLL, and CallWindowProc to call function “indirectly”. This code worked OK on my system (VB/VBA 6.0, WIN XP).

              HTH

            • #873568

              Thanks for the file Mark. I have found a solution (the link in my last post) but havent tested it yet, so if it doesnt work i’ll give you’re code a go.

            • #873569

              Thanks for the file Mark. I have found a solution (the link in my last post) but havent tested it yet, so if it doesnt work i’ll give you’re code a go.

            • #873551

              Don’t know if you got this sorted out yet, but if interested see attached text file, demonstrates one way to register COM components (.DLL, .OCX) w/o relying on RegSvr32.exe and w/o having to “hard code” the API function declarations for DllRegisterServer and DllUnregisterServer, which RegSvr32 calls from the file being registered (all inprocess COM servers are “required” to export these two functions for self-registration purposes). See RegisterDLL function, which can be used for both registering & unregistering component. The function returns zero on success, or an error code (WIN32 or user-defined constant) which may be helpful in troubleshooting errors. Note that I had to resort to some user-defined errors because if you check the MSDN documentation for DllRegisterServer (some excerpts included in attached file), upon error the function can return several error codes, some general, some specific such as SELFREG_E_TYPELIB and SELFREG_E_CLASS – but if you look these up in the applicable C++ header file (OLECTL.H) (they aren’t found in the standard WIN32API.TXT file) the DEFINE statements make use of the C++ MAKE_SCODE macro to define value (no relation to a VBA macro!) – and I am not sure of how to translate this type of #DEFINE to a VB CONST declaration (and am too lazy to look it up in some incomprehensible C++ text). So simply used a user-defined error constant if call to DllRegisterServer failed. Note also, to avoid “hard-coding”, use of GetProcAddress to get function address in target DLL, and CallWindowProc to call function “indirectly”. This code worked OK on my system (VB/VBA 6.0, WIN XP).

              HTH

          • #872642

            Edited by StuartR to make link active – see Help 19

            No probs Dave thanks all the same though. Bit of a weird one to explain! However, i’ve been given the following link which im just testing now:
            http://www.codeguru.com/vb/controls/vb_act…icle.php/c3479/%5B/url%5D

            As for the Viper, i’m still hoping for that elusive lottery win!

        • #872626

          Sorry I couldn’t help Phil, and I don’t have a Dodge Viper either evilgrin

      • #872614

        Thanks for your reply but I think you missed my point.

        Firstly, I was under the impression using regsvr32 either gave a message box or no error at all if running in silent. Due to the nature of the program I need to put the error message in a caption on a form so I need to be able to actually capture the error code if there is one.

        Secondly, im not using the deployment wizard. My program is an update program which downloads files from our FTP site when they are updated (similar to norton live update if you want a comparison).

        The user installs our program using the installshield application I have created.
        The updater then is used to update existing files and possibly add new files.
        Where a dll is concerned, it is entirely possible something could happen while running the app, so I’d prefer to un-register the current dll, archive it, copy over the new dll then register it.

        This method does produce a few issues regarding uninstalling the product, but we already have such issues which wont be resolved in the near future, so adding to them wont hurt!
        In an ideal world i’d create update files using installshield and have them so they can be run from the web, but I had to wing it when creating the installer as it was, so i’ll definately need a few courses in installshield before tackling the update scenario! Unfortunately, there just isnt time at the moment.

    • #872600

      Phil

      Creating a package with the Package and Deployment wizard, will register any dependent dll’s or ocx’s.
      Just creating an EXE won’t.

      I use coding in my project of a known local location, to copy the library or control and then register it programatically as below.
      But, if I create a distributable package, the code is not required because any dependencies are automatically registered.
      Although I copy my control to the local folder, this code registers each time the EXE is run , hence I dropped it out of my project.

       'Copy MSMAPI32.ocx File
      If Dir(strLocalFolder & "MSMAPI32.ocx") = "" Then
             FileCopy "D:UtilitiesMSMAPI32.ocx", strLocalFolder & "MSMAPI32.ocx"
             'strLocalFolder is C:MM-Utilities
      End If
      'Register It
      Shell ("C:MM-Utilitiesregsvr32.exe /s MSMAPI32.ocx")
    • #874269

      Here’s a little VB project from a while back. The specific code you want is in Module1.bas. (You’ll need to comment out the messages in there). Of all the little VB utilities I have written, I use this the most, since a lot of my development time is spent in ASP with VB .dll’s, I get to reregister new .dll’s on various IIS servers WAY too frequently! grin

    • #874270

      Here’s a little VB project from a while back. The specific code you want is in Module1.bas. (You’ll need to comment out the messages in there). Of all the little VB utilities I have written, I use this the most, since a lot of my development time is spent in ASP with VB .dll’s, I get to reregister new .dll’s on various IIS servers WAY too frequently! grin

    Viewing 3 reply threads
    Reply To: Registering Dlls programatically (VB6)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: