What's Wrong with my code ?

Everything else that doesn't fall into one of the other PB categories.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Denis.

Hi all,

i try Paul's code to uncompresse rar files (code snippet). His code is Ok

I want to use it in my app and i modify it for my use like this (i copy unrar.dll to C:\windows\system\ folder).

Code: Select all

Procedure.b InitUnrarPointers()#UnRar_dll = 1
result.b = 0

  If OpenLibrary(#UnRar_dll,"C:\windows\system\unrar.dll")
     MessageRequester("OpenLibrary","Ok",16)

     *RAROpenArchive   = IsFunction(#UnRar_dll ,"RAROpenArchive"  ) 
     *RARCloseArchive  = IsFunction(#UnRar_dll ,"RARCloseArchive" ) 
     *RARReadHeader    = IsFunction(#UnRar_dll ,"RARReadHeader"   )  
     *RARProcessFile   = IsFunction(#UnRar_dll ,"RARProcessFile"  ) 
     *RARGetDllVersion = IsFunction(#UnRar_dll ,"RARGetDllVersion")

     If *RAROpenArchive And *RARCloseArchive And *RARReadHeader And *RARProcessFile And *RARGetDllVersion
         result = 1
     EndIf 

  Else
    MessageRequester("OpenLibrary", "Not Ok",16)
  EndIf

  ProcedureReturn result 
  
EndProcedure
i call this procedure like this :

Code: Select all

Global Unrarpointers.b

 Unrarpointers = InitUnrarPointers()
It still doesn't work :cry:, OpenLibrary always failed. So i verify if the dll is in the folder, all is Ok.

But OpenLibrary always failed.

I try with different values of #UnRar_dll (0 to 10). It still failed.

I change with a - for next - loop like this

Code: Select all

Procedure.b InitUnrarPointers()
#UnRar_dll = 1
result.b = 0

For  i = 1 To 1

  If OpenLibrary(#UnRar_dll,"C:\windows\system\unrar.dll")
  MessageRequester("OpenLibrary","Ok",16)

     *RAROpenArchive   = IsFunction(#UnRar_dll ,"RAROpenArchive"  ) 
     *RARCloseArchive  = IsFunction(#UnRar_dll ,"RARCloseArchive" ) 
     *RARReadHeader    = IsFunction(#UnRar_dll ,"RARReadHeader"   )  
     *RARProcessFile   = IsFunction(#UnRar_dll ,"RARProcessFile"  ) 
     *RARGetDllVersion = IsFunction(#UnRar_dll ,"RARGetDllVersion")
     If *RAROpenArchive And *RARCloseArchive And *RARReadHeader And *RARProcessFile And *RARGetDllVersion
         result = 1
     EndIf 
  Else 
   MessageRequester("OpenLibrary", "Not Ok",16)
  EndIf

Next i

  ProcedureReturn result 
  
EndProcedure
With this loop (for i = 1 to 1), Openlibrary always success.
I don't know at all why.

May be i forget something, but what ?

Any idea :)


Denis

Bonne journée.