nico7nibor has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys

this is my code: # ------------- # Register DLL # -------------

if (! -f "$Value_DLL") { $ERR = 10; &printlog ("Value DLL not found($Value_DLL)...\n"); &printlog (" Execution Terminated!"); exit $ERR; } else { `regsvr32 /s "$Value_DLL"`; &printlog ("SO ($Value_DLL)\n"); }

How do i check if dll is registered properly, coz even if they seem correct it is possible that the file is corrupted. And another way to register aside from using backticks...

Thanks and Happy thanksgiving to the guys in the US...

Replies are listed 'Best First'.
Re: how do i check DLL if registered correctly?
by Marshall (Canon) on Nov 26, 2009 at 13:12 UTC
    I suggest: http://support.microsoft.com/kb/249873, the Microsoft page entitled: Explanation of Regsvr32 usage and error messages.

    Update: I think that some experimentation will be required as to what the /s option (silent..no GUI) does and what is returned if the command doesn't work. Then test on XP, Vista, Win 7 in the "flavors" that you intend to support.

    Yet another update!

    I don't understand the necessity of this code:

    if (! -f "$Value_DLL") { $ERR = 10; &printlog ("Value DLL not found($Value_DLL)...\n"); &printlog (" Execution Terminated!"); exit $ERR; }
    I assume that this is an installation program. In that case, the copy did work and the file named $Value_DLL does exist at this point. So this file test will never fail. I would separate the dirpath from the DLL name. $dir_path/$Value_DLL rather than combining this into a single $Value_DLL name value. But this is just a detail.

    Then we are going to essentially run the Windows command, regsvr32 /s "$dir_path/$Value_DLL" and want to know what the return value is of that. I would think that system() is the right way to go with that and check the return value: http://perlhowto.org/executing_external_commands. Some fiddling with "/" to "\" is required for the Windows path name as this is a command that will go to the Windows shell. But you should be able to get the value that would be returned to the shell and can make decisions based upon that, ie did the regsvr32 command work or not?

    Some experimentation and testing is going to be required, but I think that this approach will work.

Re: how do i check DLL if registered correctly?
by cdarke (Prior) on Nov 26, 2009 at 11:34 UTC
    So far as I can tell, regsvr32 only has a GUI interface, it does not appear to write anything to stdout, so using `backticks` will not help - might as well use system instead. A well-behaved program will return non-zero on error, however I cannot find the return value of this program documented.

    Your alternatives are to drive the GUI using something like Win32:GuiTest. Alternatively, find out which registry keys are being updated by the regsvr32 program and do it yourself using one of the Win32 Registry modules, probably Win32::TieRegistry. The later would be my choice.