Sign in to follow this  
Followers 0
chazg82

DllOpen bug

9 posts in this topic

DllOpen bug

The way it is supposed to work for example $dll=DllOpen("dllname.dll")

if it succeeds then

$dll=Dll handle

if it fails

$dll=-1

it works fine when I run it uncompiled but when I complie it I almost always get $dll=-1

I tried to post on the general forum to get suggestions before I posted here but for some reason I could not post.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

DllOpen bug

The way it is supposed to work for example $dll=DllOpen("dllname.dll")

if it succeeds then

$dll=Dll handle

if it fails

$dll=-1

it works fine when I run it uncompiled but when I complie it I almost always get $dll=-1

I tried to post on the general forum to get suggestions before I posted here but for some reason I could not post.

You haven't validated your account ...

Moving this to support first ...

As to the issue: are you sure the script can find the DLL ?

Try supplying the fully qualified path...

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Blah... I was posting as Jdeb was moving :whistle:

DllOpen bug

The way it is supposed to work for example $dll=DllOpen("dllname.dll")

if it succeeds then

$dll=Dll handle

if it fails

$dll=-1

it works fine when I run it uncompiled but when I complie it I almost always get $dll=-1

I tried to post on the general forum to get suggestions before I posted here but for some reason I could not post.

Are you using the full path to the DLL?

Without seeing a script, I would guess you are doing this.

1. When in script form, the DLL and script are in the same directory.

2. When in exe form, the exe and DLL are not in the same directory.

3. You are probably calling it like DLLOpen('MyDll.dll') vs. DLLOpen('PathToDirectory\MyDll.dll')


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Blah... I was posting as Jdeb was moving :whistle:

Are you using the full path to the DLL?

Without seeing a script, I would guess you are doing this.

1. When in script form, the DLL and script are in the same directory.

2. When in exe form, the exe and DLL are not in the same directory.

3. You are probably calling it like DLLOpen('MyDll.dll') vs. DLLOpen('PathToDirectory\MyDll.dll')

Cant the OP just register the DLL and it will work?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

Cant the OP just register the DLL and it will work?

Have you tried your suggestion without putting the DLL in the system files directory?

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Blah... I was posting as Jdeb was moving :whistle:

Are you using the full path to the DLL?

Without seeing a script, I would guess you are doing this.

1. When in script form, the DLL and script are in the same directory.

2. When in exe form, the exe and DLL are not in the same directory.

3. You are probably calling it like DLLOpen('MyDll.dll') vs. DLLOpen('PathToDirectory\MyDll.dll')

This is correct and I tried it with the exe in the folder with the dlls and it worked.

So that is obviously the problem, but why can't dllopen find any registered dll.

What I am trying to do is basically create an install file the checks for registered dlls then installs and registers any dll not registered.

I found a bunch of places to check in the registry for dlls but not all registered dlls are in these locations.

And I can't just look for the file because depending on what installed it it may be in a different place.

I though I could use dllopen to tell if the the library was registered.

there is way more to it but here is the the part of the script where I am using it

$found[$j]=0
    $dll=0
    $dll=DllOpen($lib[$j])

    If $dll=-1 Then
        GUICtrlSetData($label, "Finding Component " & $lib[$j] & " -- " & $dll & " " & DllCall("kernel32.dll", "long", "GetLastError"))
        sleep(2000)
        DllClose($dll)
    Else
        $found[$j]=1
        GUICtrlSetData($label, "Found Component " & $lib[$j] & " -- " & $dll  & " " & DllCall("kernel32.dll", "long", "GetLastError"))
        sleep(2000)
        DllClose($dll)
    EndIf

edit:

And about validating my account ... I tried a bunch of time to validate by using the the validation website and typing in the code and id instead of the link in the email and it didn't work. I am almost positive I didn't mistype anything.

I wasn't using the link in the email because I was reading the email off my smartphone and I couldn't validate from there and I wanted to avoid forwarding the email to my work email (I am at work now).

Edited by chazg82

Share this post


Link to post
Share on other sites

This is correct and I tried it with the exe in the folder with the dlls and it worked.

So that is obviously the problem, but why can't dllopen find any registered dll.

What I am trying to do is basically create an install file the checks for registered dlls then installs and registers any dll not registered.

I found a bunch of places to check in the registry for dlls but not all registered dlls are in these locations.

And I can't just look for the file because depending on what installed it it may be in a different place.

I though I could use dllopen to tell if the the library was registered.

there is way more to it but here is the the part of the script where I am using it

You might want to give this site the once over. This guy has done something similar in VB that looks fairly trival to convert to AutoIt. If not spot on, it might give you some ideas.

Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

You might want to give this site the once over. This guy has done something similar in VB that looks fairly trival to convert to AutoIt. If not spot on, it might give you some ideas.

After a quick look it seems he/she has done something very similar to what I ended up doing to try and work around my dllopen issue but I found that it doesn't find every registered dll (as I stated above)

He is looking at the same sections of the registry as I am but it seems he is checking the library object name I was checking for the file name (like mylib.dll) and he also uses the GUID.

Is the GUID the sure-fire way of recognizing a library?

Earlier I tried to avoid showing all the code and stick to the Dllopen issues I was having.

If you look at the part where I look through the reg I loop through two parts of the Reg which I read would show me all the registered libraries and still not all of them turn up. I will try and identify them by the GUID.

all the code:

GUICreate("Registering Components",300,150,-1,-1,800000)
$progressbar = GUICtrlCreateProgress (10,80,280,30,1)
$label = GUICtrlCreateLabel("Registering Components",30,10,240,70,1)
GUISetState ()

$strComputer = "."
$strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDlls"
$strKeyPath2="CLSID"
$pgrmfl="c:\Program Files\AbsenteeDesk"
DirCreate($pgrmfl)



Dim $lib[12]
Dim $found[12]



$lib[0]="VBE6.dll"
$lib[1]="cic.dll"   
$lib[2]="crviewer.dll"  
$lib[3]="dao360.dll"        
$lib[4]="FPDTC.dll"     
$lib[5]="OWC11.dll" 
$lib[6]="MSCOMCT2.OCX"  
$lib[7]="MSCOMCTL.OCX"  
$lib[8]="MSCAL.OCX"     
$lib[9]="MSACC.OLB"     
$lib[10]="msado21.tlb"  
$lib[11]="stdole2.tlb"      
$bar=0
FileInstall("regtlib.exe", $pgrmfl & "\" & "regtlib.exe")


For $j=0 to 11
    $bar=$bar+5
    GUICtrlSetData($label, "Finding Component " & $lib[$j])
    GUICtrlSetData($progressbar, $bar)
    $found[$j]=0
    $dll=0
    $dll=DllOpen($lib[$j])

    If $dll=-1 Then
        GUICtrlSetData($label, "Finding Component " & $lib[$j] & " -- " & $dll & " " & DllCall("kernel32.dll", "long", "GetLastError"))
        sleep(2000)
        DllClose($dll)
    Else
        $found[$j]=1
        GUICtrlSetData($label, "Found Component " & $lib[$j] & " -- " & $dll  & " " & DllCall("kernel32.dll", "long", "GetLastError"))
        sleep(2000)
        DllClose($dll)
    EndIf

    If $found[$j]=0 Then
       For $i = 1 to 999999999
            
        $strValueName = RegEnumVal( "HKEY_LOCAL_MACHINE\" & $strKeyPath,$i)
        If @error =-1 Then ExitLoop
        If @error<>1 or @error<>2 or @error<>3 Then
            If StringLower(StringRight($strValueName,stringLen($lib[$j])))=StringLower($lib[$j])  and $found[$j]=0 then 
                $found[$j]=1
                GUICtrlSetData($label, "Finding Component " & $lib[$j] & Chr(10) & "-- Found at " & $strValueName)
                Sleep(1000)
                ExitLoop
            EndIf
        EndIf
        GUICtrlSetData($label, "Finding Component " & $lib[$j] & Chr(10) & "-- Looking at " & Chr(10) & $strValueName)
       Next
    EndIf

    
    


    If $found[$j]=0 Then
        For $k = 1 to 9999999999
            $Key=RegEnumKey ("HKEY_CLASSES_ROOT\" & $strKeyPath2,$k)
            If @error=-1 Then ExitLoop
            If @error<>1 and @error<>2 and @error<>3 Then 
                $strKey="HKEY_CLASSES_ROOT\CLSID\" & $Key & "\InprocServer32"
                $strValue = RegRead($strKey, "")
                If @error<>1 and @error<>2 and @error<>3 and @error<>-1 Then 
                    If StringLower(StringRight($strValue,StringLen($lib[$j])))=StringLower($lib[$j]) and $found[$j]=0 then 
                        $found[$j]=1
                        GUICtrlSetData($label, "Finding Component " & $lib[$j] & Chr(10) & "-- Found at " & $strValue)
                        Sleep(1000)
                        ExitLoop
                    EndIf
                EndIf
            EndIf
            GUICtrlSetData($label, "Finding Component " & $lib[$j] & Chr(10) &"-- Looking at " & $strValue)
        Next
    EndIf

    

    

    If $found[$j]=0 Then
        For $m=0 to 99999999999
            $Key2=RegEnumKey("HKEY_CLASSES_ROOT\TypeLib\",$m)
            If @error=-1 Then ExitLoop
            If @error<>1 and @error<>2 and @error<>3 Then
                $strKeyPath3="TypeLib\" & $Key2
     
              For $n=0 to 99999999999
                $arrSubKey3=RegEnumKey("HKEY_CLASSES_ROOT\" & $strKeyPath3, $n)
                If @error=-1 Then ExitLoop
                If @error<>1 and @error<>2 and @error<>3 Then
                    $strValue = RegRead("HKEY_CLASSES_ROOT\" & $strKeyPath3 & "\" & $arrSubKey3 & "\win32","")
                    If $strValue<>1 and $strValue<>2 and $strValue<>3 and $strValue<>-1 Then 
                            If StringLower(StringRight($strValue,StringLen($lib[$j])))=StringLower($lib[$j]) and $found[$j]=0 then 
                                $found[$j]=1
                                GUICtrlSetData($label, "Finding Component " & $lib[$j] & Chr(10) & "-- Found at " & $strValue)
                                Sleep(1000)
                                ExitLoop
                            EndIf
                    EndIf
                EndIf
              Next
          EndIf
          GUICtrlSetData($label, "Finding Component " & $lib[$j] & Chr(10) & "-- Looking at " $strValue)
        Next
    EndIf
Sleep(500)
Next


    $OutputData=""
For $p = 0 to 11
    $bar=$bar+2
    GUICtrlSetData($progressbar, $bar)
        If $found[$p]=1 then
            $OutputData= StringUpper($lib[$p]) & " has been found and is registered."
        Else
            If $lib[$p]="VBE6.DLL" Then
            FileInstall("VBE6.DLL", $pgrmfl & "\" & "ATP.DLL")
            RunWait("regsvr32 VBE6.DLL")
            ElseIf $lib[$p]="cic.dll" Then  
            FileInstall("cic.dll" , $pgrmfl & "\" & "cic.dll" )
            RunWait("regsvr32 cic.dll" )
            ElseIf $lib[$p]="crviewer.dll" Then     
            FileInstall("crviewer.dll", $pgrmfl & "\" & "crviewer.dll")
            RunWait("regsvr32 crviewer.dll")
            ElseIf $lib[$p]="dao360.dll" Then
            FileInstall("dao360.dll", $pgrmfl & "\" & "dao360.dll")
            RunWait("regsvr32 dao360.dll")
            ElseIf $lib[$p]="FPDTC.dll" Then
            FileInstall("FPDTC.dll", $pgrmfl & "\" & "FPDTC.dll")
            RunWait("regsvr32 FPDTC.dll")
            ElseIf $lib[$p]="OWC11.dll" Then
            FileInstall("OWC11.dll", $pgrmfl & "\" & "OWC11.dll")
            RunWait("regsvr32 OWC11.dll")
            ElseIf $lib[$p]="MSCOMCT2.OCX" Then
            FileInstall("MSCOMCT2.OCX", $pgrmfl & "\" & "MSCOMCT2.OCX")
            RunWait("regsvr32 MSCOMCT2.OCX")
            ElseIf $lib[$p]="MSCOMCTL.OCX" Then
            FileInstall("MSCOMCTL.OCX", $pgrmfl & "\" & "MSCOMCTL.OCX")
            RunWait("regsvr32 MSCOMCTL.OCX")
            ElseIf $lib[$p]="MSCAL.OCX" Then
            FileInstall("MSCAL.OCX", $pgrmfl & "\" & "MSCAL.OCX")
            RunWait("regsvr32 MSCAL.OCX")
            ElseIf $lib[$p]="MSACC.OLB" Then
            FileInstall("MSACC.OLB", $pgrmfl & "\" & "MSACC.OLB")
            RunWait("regtlib MSACC.OLB")
            ElseIf $lib[$p]="msado21.tlb" Then
            FileInstall("msado21.tlb", $pgrmfl & "\" & "msado21.tlb")
            RunWait("regtlib msado21.tlb")
            ElseIf $lib[$p]="stdole2.tlb" Then
            FileInstall("stdole2.tlb", $pgrmfl & "\" & "stdole2.tlb")
            RunWait("regtlib stdole2.tlb")
            EndIf
            $OutputData= StringUpper($lib[$p]) & " has been installed and is now registered."
        EndIf
    GUICtrlSetData($label, $OutputData)
Sleep(500)
Next


$bar=100
GUICtrlSetData($progressbar, $bar)
GUICtrlSetData($label, "Component Registration Complete")
Sleep(2500)

edit:

missing word

Edited by chazg82

Share this post


Link to post
Share on other sites

If any one is interested here is what I ended up with.

I abandoned DllOpen because it seems I was assuming incorrectly how it worked.

I wrote two Functions 1 looks in the registry under "HKCR\TypeLib" and the other looks for the libraries in "HKCR\CLSID".

All you have to do is provide the library file name and it can find if the library is registered. I separated them into 2 functions because I wanted to be able to control which ran first, because the majority of the libraries I was looking for appeared in TypeLib I ran that first.

Here is a snippet including the functions and the code I used to call them.

$add=LibInTypeLib($lib[$j],$found[$j],$label)
    If $found[$j]=1 Then
        GUICtrlSetData($label, "Found Component " & $lib[$j] & " in TypeLib" & Chr(10) & "Adress: " & $add)
        Sleep(1500)
    Else
        $add=LibInCLSID($lib[$j],$found[$j],$label)
        If $found[$j]=1 Then
            GUICtrlSetData($label, "Found Component " & $lib[$j] & "in CLSID" & Chr(10) & "Adress: " & $add)
            Sleep(1500)
        Else
            GUICtrlSetData($label, "Component " & $lib[$j] & " Not found in CLSID or TypeLib")
            Sleep(1500)
        EndIf
    EndIf

Func LibInCLSID($LibName,ByRef $f,$lbl=0)
    ;Returns the location in the Registry
    ;$LibName is the file name of the library, example: VBE6.dll
    ;$f will indicate if the library is registered 0 = no, 1 = yes
    ;$lbl is the Label handle if you use a GUI this is optional
    If $f=0 Then

        For $k = 1 to 9999999999
            $Key=RegEnumKey ("HKEY_CLASSES_ROOT\CLSID",$k)
            If @error=-1 Then ExitLoop
            If @error<>1 and @error<>2 and @error<>3 Then 
                $strKey="HKEY_CLASSES_ROOT\CLSID\" & $Key & "\InprocServer32"
                If $lbl<>0 Then GUICtrlSetData($lbl, "Looking for  " & $LibName & " in: " & Chr(10) & $strKey)
                $strValue = RegRead($strKey, "")
                
                If @error=1 or @error=2 or @error=3 or @error=-1 Then
                    $strKey="HKEY_CLASSES_ROOT\CLSID\" & $Key & "\LocalServer32"
                    If $lbl<>0 Then GUICtrlSetData($lbl, "Looking for  " & $LibName & " in: " & Chr(10) & $strKey)
                    $strValue = RegRead($strKey, "")
                EndIf   
                
                If @error<>1 and @error<>2 and @error<>3 and @error<>-1 Then 
                    If StringLower(StringRight($strValue,StringLen($LibName)))=StringLower($LibName) and $f=0 then 
                        $f=1
                        Return $strKey
                        ExitLoop
                    EndIf
                EndIf
            EndIf
        Next
    EndIf   
EndFunc

Func LibInTypeLib($LibName,ByRef $f,$lbl=0)
    ;Returns the location in the Registry
    ;$LibName is the file name of the library, example: VBE6.dll
    ;$f will indicate if the library is registered 0 = no, 1 = yes
    ;$lbl is the Label handle if you use a GUI this is optional
    If $f=0 Then
        For $m=1 to 99999999999
            $Key2=RegEnumKey("HKEY_CLASSES_ROOT\TypeLib",$m)
            If @error=-1 Then ExitLoop
            If @error<>1 and @error<>2 and @error<>3 Then
                $strKey2="HKEY_CLASSES_ROOT\TypeLib\" & $Key2
              For $n=1 to 99999999999
                $strSubKey=RegEnumKey($strKey2, $n)
                $strKey3=$strKey2 & "\" & $strSubKey
                If @error=-1 Then ExitLoop
                If @error<>1 and @error<>2 and @error<>3 Then
                    For $o=1 to 99999999999
                        $strSubKey2=RegEnumKey($strKey3, $o)
                        If @error=-1 Then ExitLoop
                        If @error<>1 and @error<>2 and @error<>3 Then
                            
                            $strKey4=$strKey3 & "\" & $strSubKey2 & "\win32"
                            $strValue = RegRead($strKey4,"")
                            If $lbl<>0 Then GUICtrlSetData($lbl, "Looking for  " & $LibName & " in: " & Chr(10) & $strKey4 & Chr(10) & $strValue & Chr(10) & $o)
                            If $strValue<>1 and $strValue<>2 and $strValue<>3 and $strValue<>-1 Then 
                                If StringLower(StringRight($strValue,StringLen($LibName)))=StringLower($LibName) and $f=0 then 
                                    $f=1
                                    Return $strKey4
                                    ExitLoop
                                EndIf
                            EndIf
                        EndIf
                    Next
                EndIf
                If $f=1 Then ExitLoop
              Next
            EndIf
          If $f=1 Then ExitLoop
        Next
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0