Jump to content

DllCall problems


dadamoid
 Share

Recommended Posts

I am trying to read data from a PicoTechnologies HumidiProbe. It comes with a DLL called "humidiprobe.dll".

Their example Excel macro code works fine but when I try to call it with AutoIt3 it returns no handle or anything.

Have used AutoIt3 successfully to call another DLL written by one of our software developers and that works fine.

Any Ideas ??

Link to comment
Share on other sites

My first thought would be to post a bit more info. Maybe the excel macro & your autoit code. And if possible, a link to the documentation for this DLL.

~cdkid

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

Ok. Here's the Excel Macro (which works):

*****************************************************************************************

Declare Function HumidiProbeOpenUnit Lib "C:\Program Files\Pico Technology\Pico Full\Examples\Humidiprobe\HumidiProbe.DLL" () As Boolean

Declare Function HumidiProbeGetUnitInfo Lib "C:\Program Files\Pico Technology\Pico Full\Examples\Humidiprobe\HumidiProbe.DLL" (ByVal handle As Integer, str As String, ByVal stringLength As Integer, ByVal info As Integer) As Integer

Declare Function HumidiProbeGetSingleValue Lib "C:\Program Files\Pico Technology\Pico Full\Examples\Humidiprobe\HumidiProbe.DLL" (ByVal handle As Integer, temp As Single, ByVal filterTemp As Integer, humidity As Single, ByVal filterHumidity As Integer) As Integer

Declare Function HumidiProbeCloseUnit Lib "C:\Program Files\Pico Technology\Pico Full\Examples\Humidiprobe\HumidiProbe.DLL" (ByVal handle As Integer) As Integer

Declare Function GetTickCount Lib "kernel32" () As Long

Dim Port As Integer

Dim version As Integer

Dim value As Long

Dim handle As Integer

Dim ok As Integer

Dim humidity As Single

Dim temp As Single

Sub GetData()

Port = 1

Cells(17, "E").value = "Opening the HumidiProbe"

handle = HumidiProbeOpenUnit()

If handle > 0 Then

Cells(17, "E").value = "HumidiProbe Opened"

Else

Cells(17, "E").value = "Cannot open the HumidiProbe"

Exit Sub

End If

' Get 20 readings at 2-second intervals

For i = 1 To 20

ticks = GetTickCount()

While GetTickCount() < ticks + 2000

' Let Excel do other things

' And poll the driver because Excel doesn't let timer ticks thru to the driver

DoEvents

Wend

' Get the reading

' ch1 = temperature

' ch2 = humidity

ok = HumidiProbeGetSingleValue(handle, temp, 0, humidity, 0)

If ok > 0 Then

Cells(i + 4, "A").value = temp

Cells(i + 4, "B").value = humidity

Else

Cells(1 + 4, "A").value = "****"

Cells(1 + 4, "B").value = "****"

End If

Next i

' Close the driver

Call HumidiProbeCloseUnit(handle)

End Sub

*****************************************************************************************

Now here's my little script:

$dll = DllOpen("humidiprobe.dll")

While 1

$handle = DllCall($dll, "int", "HumidiProbeOpenUnit")

PrintDebug($handle)

Sleep(2000)

WEnd

and nothing is returned by $handle (PrintDebug just prints to a GUI Ctrl edit window). Details of humidiprobe.dll are below:

http://www.picotech.com/document/pdf/humidiprobe044.pdf

Link to comment
Share on other sites

I'm not sure if this is your problem, but you've got

HumidiProbeOpenUnit declared to return an int, but in the excel macro you have

Declare Function HumidiProbeOpenUnit Lib "C:\Program Files\Pico Technology\Pico Full\Examples\Humidiprobe\HumidiProbe.DLL" () As Boolean

to return a boolean.

--Hope this helps

~cdkid

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

  • Moderators

I'm not sure if this is your problem, but you've got

HumidiProbeOpenUnit declared to return an int, but in the excel macro you have

Declare Function HumidiProbeOpenUnit Lib "C:\Program Files\Pico Technology\Pico Full\Examples\Humidiprobe\HumidiProbe.DLL" () As Boolean

to return a boolean.

--Hope this helps

~cdkid

What was he supposed to use there? :) :)

@OP ... A dllcall returns an array, if something is actually returned, it would look like:

While 1
  $handle = DllCall($dll, "int", "HumidiProbeOpenUnit")
  $nError = @error
  If IsArray($handle) Then
    ConsoleWrite('Handle = ' & $handle[0] & @CRLF)
  Else
    MsgBox(16, 'Error = ' & $nError, 'Are you sure there is not more to this DLLCall?')
  EndIF
  Sleep(2000)
WEnd

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...