Jump to content


Photo

LIBGSL.DLL cannot be accessed


  • Please log in to reply
17 replies to this topic

#1 Laszlo

Laszlo
  • Fellows
  • 4713 posts

Posted 13 July 2007 - 09:35 PM

The GNU Scientific Library is available as a Windows dll from http://gnuwin32.sour...ackages/gsl.htm, but AHK cannot access it. Is there a way around?
hModule := DllCall("LoadLibrary", "str","libgsl.dll")

MsgBox %ErrorLevel% ; shows 0 (OK)



c := dllcall("libgsl\gsl_hypot", "double",3.0, "double",4.0, "double")

MsgBox %ErrorLevel% ; shows -3 (The specified DllFile could not be accessed)


#2 Sean

Sean
  • Members
  • 2462 posts

Posted 14 July 2007 - 02:10 AM

The GNU Scientific Library is available as a Windows dll from http://gnuwin32.sour...ackages/gsl.htm, but AHK cannot access it.

It looks like depend on libgslcblas.dll, so this file should be present too.

#3 Laszlo

Laszlo
  • Fellows
  • 4713 posts

Posted 14 July 2007 - 02:19 AM

YES! That solved the problem! Thanks!

However, more informative error information would be very helpful. AHK says that "The specified DllFile could not be accessed", what is not true. In this case another, dependent dll file could not be accessed. If I knew it, I could have found the missing dll file.

This is how it works:
h_liblas := DllCall("LoadLibrary", "str","C:\Program Files\GnuWin32\bin\libgslcblas.dll") ; dependent dll 1st
h_libgsl := DllCall("LoadLibrary", "str","C:\Program Files\GnuWin32\bin\libgsl.dll") ; main library 2nd

c := dllcall("libgsl\gsl_hypot", "double",3, "double",4, "cdecl double")
MsgBox %c%`n%ErrorLevel%


#4 corrupt

corrupt
  • Members
  • 2558 posts

Posted 14 July 2007 - 03:02 PM

I think that more informative error messages in this case are likely out of AutoHotkey's control since it sounds like the dll that AutoHotkey is calling is the one that calls the second dll (just a guess). In other words, it sounds like AutoHotkey knows nothing about the second dll but the error message is being passed along.

#5 Laszlo

Laszlo
  • Fellows
  • 4713 posts

Posted 14 July 2007 - 03:27 PM

It might be the case, but my point was that the explanation of the error in the AHK help explicitly says that "The specified DllFile could not be accessed". At least it has to be corrected, telling about other possible causes of Error -3.

#6 corrupt

corrupt
  • Members
  • 2558 posts

Posted 14 July 2007 - 04:08 PM

I wonder (not sure - just a guess) if this may fall under:

-3: The specified DllFile could not be accessed. If no explicit path was specified for DllFile, the file must exist in the system's PATH or A_WorkingDir. This error might also occur if the user lacks permission to access the file.

if AutoHotkey is denied access if the dll's dependencies haven't been met (although, I agree, not very clear in this case). If I run a smaller version of your sample script without the second dll present:
c := dllcall("libgsl\gsl_hypot", "double",3, "double",4, "cdecl double") 
MsgBox %c%`n%ErrorLevel%
I get the following error message in a msgbox before the -3 AutoHotkey msgbox output.

This application has failed to start because libgslcblas.dll was not found. Re-installing the application may fix this problem.


For comparison, I created a couple of simple dlls for testing where one dll calls a function in the other dll and if I remove or rename the second dll I get 0xc0000005, not -3.

#7 photon

photon
  • Members
  • 5 posts

Posted 09 August 2007 - 02:26 AM

Dears all, I'm new here but not new in age anymore. However, having similar problems wit same library but I try to use:

gsl_sf_polar_to_rect (double r, double theta, gsl_sf_result * x, gsl_sf_result * y); and the vice-versa function gsl_sf_rect_to_polar

I always get 0x0000005 -3 whatever I do and I don't have any idea how I couls make it work.

I also would like to use Foxes Team Xnumbers.dll from <!-- m -->http://digilander.li...areDownload.htm<!-- m -->

Well this dll is written for excel but as far I know a normal dll and I'm looking how to use it in AutoHotKey?

Thanks in advance

#8 Laszlo

Laszlo
  • Fellows
  • 4713 posts

Posted 09 August 2007 - 02:31 AM

Could you post the relevant part of your script? It helps us to reproduce the problem.

#9 photon

photon
  • Members
  • 5 posts

Posted 09 August 2007 - 06:04 AM

Thanks for fast reply. Well, I use little of your code from above to try some function of the Gnu lib. I expected to get back x, y but no way (for me).

h_liblas := DllCall("LoadLibrary", "str","C:\Program Files\GnuWin32\bin\libgslcblas.dll") ; dependent dll 1st
h_libgsl := DllCall("LoadLibrary", "str","C:\Program Files\GnuWin32\bin\libgsl.dll") ; main library 2nd

c := dllcall("libgsl\gsl_sf_polar_to_rect","double",4,"double",5,"double",x,"double",y,"cdecl")

MsgBox, %c%`n,%ErrorLevel%, x = %x%, y = %y%
return

#10 Laszlo

Laszlo
  • Fellows
  • 4713 posts

Posted 09 August 2007 - 12:45 PM

When structures are returned from a C function, the address of the result is passed. Accordingly, we have to reserve room for the structure beforehand, and copy the result from the memory after the call:
VarSetCapacity(x,16), VarSetCapacity(y,16)
dllcall("libgsl\gsl_sf_polar_to_rect","double",sqrt(8),"double",-atan(1),"uint",&x,"uint",&y,"cdecl")
MsgBox % "x = " NumGet(x,0,"double") "  y = " NumGet(y,0,"double")

Edit 20070820: The return values are structures of two doubles: {value, error}

#11 Laszlo

Laszlo
  • Fellows
  • 4713 posts

Posted 09 August 2007 - 01:07 PM

The following could work, if the results were doubles
dllcall("libgsl\gsl_sf_polar_to_rect","double",sqrt(8),"double",-atan(1),"double*",x,"double*",y,"cdecl")
MsgBox % "x = " . x . "  y = " . y
But the results are structures, and so the values of x and y stay unchanged! It could even crash AHK.

Edit 20070820: return values are structs!

#12 Sean

Sean
  • Members
  • 2462 posts

Posted 10 August 2007 - 01:32 AM

According to the AHK help file, the following should work, too

dllcall("libgsl\gsl_sf_polar_to_rect","double",sqrt(8),"double",-atan(1),"double*",x,"double*",y,"cdecl")
MsgBox % "x = " . x . "  y = " . y
But it does not. The values of x and y stay unchanged!

I'd like to hear about the opinion of Chris on this, as I encountered a similar situation recently:
<!-- m -->http://www.autohotke...topic20701.html<!-- m -->

There, I used the following
VarSetCapacity(str,8,0)
DllCall(NumGet(NumGet(1*psf)+44), "Uint", psf, "Uint", pidl, "Uint", 1, "Uint", &str)
instead of

DllCall(NumGet(NumGet(1*psf)+44), "Uint", psf, "Uint", pidl, "Uint", 1, "int64P", str)
If using the second one instead, it crashed AHK (:the var name str didn't matter).

OTOH, exactly the same function worked flawlessly in the second form, in other (:unpublished) script.
The difference between the two situations is that some indirection, the so-called marshalling, is involved in the first situation.
So, I'm currently assuming that this symptom would happen, although not always, if the ByRef parameters were updated via other one/thread than the called function itself.

#13 Laszlo

Laszlo
  • Fellows
  • 4713 posts

Posted 10 August 2007 - 04:01 AM

Just thinking… With a "type*" dllcall parameter AHK should:

- allocate memory for a "type" temporary variable
- write the parameter in binary format there
- pass its address to the dll function
- upon return, convert the binary value (changed by the dll function) to its AHK representation, and store it in the AHK variable table.

In many cases it works. What could go wrong, when it does not? Maybe AHK does not see the temporary variable changed, but this is unlikely. Or, this variable is allocated on the local stack, and when the parameter has to be passed on to another, internally called function, the stack frame changes, and the secondary function updates the wrong memory. (It explains the crash.) When we use the address of an explicit AHK variable (UInt,&x), x resides in the heap (globally allocated), and changing the stack frame does not affect its accessibility.

If it was the case, it would be easy to fix: don't use the stack for the temporary variable.

Edit 20070820: The results are in structures, which explains why "double*" does not work. AHK is innocent!

#14 corrupt

corrupt
  • Members
  • 2558 posts

Posted 10 August 2007 - 05:05 AM

Does this produce the desired results? (I'm too lazy to try and determine what the call is trying to accomplish at the moment... ;) )
VarSetCapacity(x,8), VarSetCapacity(y,8) 
dllcall("libgsl\gsl_sf_polar_to_rect","double",sqrt(8),"double",-atan(1),"uint",&x,"uint",&y,"cdecl") 
VarSetCapacity(x, -1)
VarSetCapacity(y, -1)
MsgBox % "x = " NumGet(x,0,"double") "  y = " NumGet(y,0,"double")
Return

; In v1.0.44.03+, specify -1 for RequestedCapacity to update the variable's internally-stored length 
; to the length of its current contents. This is useful in cases where the variable has been altered 
; indirectly, such as by passing its address via DllCall(). In this mode, VarSetCapacity() returns 
; the length rather than the capacity.


#15 photon

photon
  • Members
  • 5 posts

Posted 10 August 2007 - 06:43 AM

First of all you guys not only fast but also clever. JUST THANKS TO ALL OF YOU!!!

Now Laszlos script together with yours look like this and it really works perfect:

VarSetCapacity(x,8), VarSetCapacity(y,8)

h_liblas := DllCall("LoadLibrary", "str","C:\Program Files\GnuWin32\bin\libgslcblas.dll") ; dependent dll 1st
h_libgsl := DllCall("LoadLibrary", "str","C:\Program Files\GnuWin32\bin\libgsl.dll") ; main library 2nd

dllcall("libgsl\gsl_sf_polar_to_rect","double",sqrt(8),"double",-atan(3),"uint",&x,"uint",&y,"cdecl")

VarSetCapacity(x, -1)
VarSetCapacity(y, -1)

MsgBox % "x = " NumGet(x,0,"double") " y = " NumGet(y,0,"double")
Return

; In v1.0.44.03+, specify -1 for RequestedCapacity to update the variable's internally-stored length
; to the length of its current contents. This is useful in cases where the variable has been altered
; indirectly, such as by passing its address via DllCall(). In this mode, VarSetCapacity() returns
; the length rather than the capacity.

This Open Source math library is very usefull for sure not only for me. And I know how hard it is to get reliable help and information. That's why I would like to suggest making this math library working together with AutoHotKey and providing more info to all AutoHotKey users. Above we have a good start and I hope to see more questions. THANKS TO ALL AGAIN!!