Sign in to follow this  
Followers 0
Capel

Importing a DLL

21 posts in this topic

#1 ·  Posted (edited)

I'm trying to launch a 3rd party application using a vendor supplied dll. Here are some details:

MRWStartup

The purpose of this API is to launch the MEDITECH 32 Bit MAGIC Workstation and set up communication between the MAGIC Workstation and the scripting program.

Syntax

int MRWStartup(lpszProgram,Boolean Minimize)

example: MRWStartup("C:\Path\T.EXE",Null)

Return

-1 = Returned if error occurs during the launching of MAGIC Workstation.

Comments: This API is called by the scripting application to launch the MEDITECH 32 Bit MAGIC Workstation.

Here is my AutoIT script:

$result = DllCall("mrwscript.dll","int", "MRWStartup", "C:\Program Files\MEDITECH\Workstation4.x\t.exe",False)

When I run this it returns 0 but the application does not launch. What am I missing?

[edit to correct typo]

Edited by Capel

Share this post


Link to post
Share on other sites



Oops! That was a typo on my part.

I still get the same behavior when I reference the dll.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Oops! That was a typo on my part.

I still get the same behavior when I reference the dll.

Your dllcall syntax is wrong. You never specify the types for each parameter.

DllCall ( "dll", "return type", "function" [, "type1", param1 [, "type n", param n]]

So maybe something like

DllCall("mrwscript.dll","int", "MRWStartup","str", "C:\Program Files\MEDITECH\Workstation4.x\t.exe","?",False)

I'm not sure which type boolean would use in au3 so I put a ?. Anyone wanna chime in with the type?

Edited by P5ych0Gigabyte

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

Ok, but it is not clear what type I should use for the last parameter which is a boolean.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Ok, but it is not clear what type I should use for the last parameter which is a boolean.

try BOOL and see if that works.

Edit:Not sure if you need the latest beta

Edited by P5ych0Gigabyte

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

$result = DllCall("mrwscript.dll","int", "MRWStartup", "str","C:\Program Files\MEDITECH\Workstation4.x\t.exe","bool",False)

Nope, still nothing.

Share this post


Link to post
Share on other sites

$result = DllCall("mrwscript.dll","int", "MRWStartup", "str","C:\Program Files\MEDITECH\Workstation4.x\t.exe","bool",False)

Nope, still nothing.

Are you using the latest beta?


HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

Yes

Share this post


Link to post
Share on other sites

Nope, none of these worked either.

Share this post


Link to post
Share on other sites

In the documentation it suggests passing a Null.

example: MRWStartup("C:\Path\T.EXE",Null)

How do I pass a null from AutoIT to this dll?

Share this post


Link to post
Share on other sites

A BOOLEAN is in reality an ordinary int.

NULL should be just 0 (a zero) in autoit.


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Thanks. I've tried the following:

$dll = DllOpen("mrwscript.dll")

$result = DllCall($dll,"int", "MRWStartup", "str","C:\Program Files\MEDITECH\Workstation4.x\t.exe","int",0)

to no avail. The app still won't launch.

Share this post


Link to post
Share on other sites

This little routine after the DllCall may give you information that will indicate what needs to be rectified.

See the help file - DllCall for the meaning of the return error values.

;
$result = DllCall("mrwscript.dll", "int", "MRWStartup", "str", "C:\Program Files\MEDITECH\Workstation4.x\t.exe", "int", False)

Local $sRes = "MRWStartup @ERROR Return Value = " & @error & @CRLF
For $x = 0 To UBound($result) - 1
    $sRes &= $x & "   " & $result[$x]
Next
;ConsoleWrite($sRes & @CRLF)
MsgBox(0, "", $sRes)
;

When run, I get:-

MRWStartup @ERROR Return Value = 1

Because I don't have mrwscript.dll on my system. (@error = 1 unable to use the DLL file,)

Share this post


Link to post
Share on other sites

The example wrapper I saw ( here: http://www.toop.ca/muse2007/ ) points to the dll here:

"C:\Program Files\Meditech\Workstation3.x\mrwscript.dll"

However, you seem to be calling the dll from the system directory or the script directory. Are you sure the path is correct?

Based on the wrapper I looked at:

; This may work, or the dll may still need to be registered if it doesn't
#Region find dll
Global $s_mrw_dll = "mrwscript.dll"
Global $s_mrw_dir = @ProgramFilesDir & "\Meditech\Workstation3.x"
If FileExists($s_mrw_dll) = 0 Then
    If FileExists($s_mrw_dir & "\" & $s_mrw_dll) = 0 Then
        MsgBox(16, "Error", "Cannot find mrwscript.dll")
        Exit
    EndIf
    $s_mrw_dll = $s_mrw_dir & "\" & $s_mrw_dll
EndIf
#EndRegion find dll

Global $i_mrw_startup = MRWStartup($s_mrw_dir & "\T.exe", False)
MsgBox(64, "Info", "Return value = " & $i_mrw_startup)

Func MRWStartup($s_str, $f_minimize)
    Local $a_mrw_startup = DllCall($s_mrw_dll, "int", "MRWStartup", "str", $s_str, "int", $f_minimize)
    If Not @error And $a_mrw_startup[0] <> 0 Then Return 1
    Return 0    
EndFunc
May work.

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.

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Ok, here is what I tried:

$dll = DllOpen("mrwscript.dll")

$result = DllCall($dll,"int", "MRWStartup", "str","C:\Program Files\MEDITECH\Workstation4.x\t.exe","int",0)

ConsoleWrite( "MRWStartup @ERROR Return Value = " & @error & @CRLF)
For $x = 0 To UBound($result) - 1
ConsoleWrite("return[" &$x & "]=  " & $result[$x] & @CRLF)
Next

This yielded the following output:

MRWStartup @ERROR Return Value = 0

return[0]= -1

return[1]= C:\Program Files\MEDITECH\Workstation4.x\t.exe

return[2]= 0

I was confusing the AutoIT return value with the function return value. The only documentation I have says "-1 = Returned if error occurs during the launching of Remote Workstation."

The dll is in both the sytem and script directory. Since AutoIT returns 0, it must be finding the dll, however the function is returning an error. The odd thing is that I can get this dll to work when I call it from vb.net. (both Workstation3.x and Workstation4.x) Do I need to put AutoIT in some sort of wait loop?

Also, this dll can not be registered with regsvr32.

Edited by Capel

Share this post


Link to post
Share on other sites

What calling method does that library use ?

Share this post


Link to post
Share on other sites

I don't know. How would I determine this. I know it's not COM.

Share this post


Link to post
Share on other sites

I don't know. How would I determine this. I know it's not COM.

Can you post the dll ? I can try to call it or debug it.

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