Jump to content
Sign in to follow this  

Problems with DllCall function

Recommended Posts



I'm building some automated tests for Internet Explorer 9 with AutoIT. I'm currently using keyboard shortcuts to control IE9, but I need these tests to run under any language. Since the shortcuts vary through different languages, I'm trying not to hardcode the key combinations but to take them from the IE9 .mui (internationalization) files. The file I'm trying to use right now is ieframe.dll.mui (which is under %windows%\%system32%\En-us). Supposedly, I should be able to get the information I want from this file using Windows API functions such as LoadAccelerators (MSDN). I'm not very C nor C++ experienced, so I'm having trouble both with the Windows API and with the AutoIT function DllCall.

This what I have so far:

Global $kernel32 = OpenDll("kernel32.dll")
Global $user32 = OpenDll("user32.dll")
Global $ieframe = OpenDll("ieframe.dll")

Local $accelerators = LoadAccelerators($ieframe, "")

ConsoleWrite($accelerators & @LF)

; ================= user32.dll functions ====================

Func LoadAccelerators($moduleHandle, $acceleratorTable)

Local $result = DllCall($user32, "HANDLE", "LoadAccelerators", "HANDLE", $moduleHandle, "str", $acceleratorTable)
ConsoleWriteIfNull($result, "The accelerator is null")
Return $result


; ================= kernel32.dll functions ====================

Func FindResource($moduleHandle, $resourceId, $resourceType)

Local $result = DllCall($kernel32, "HANDLE", "FindResource", "HANDLE", $moduleHandle, "int", $resourceId, "int", $resourceType)
ConsoleWriteIfNull($result, "The resource handle is null")
Return $result


Func LoadResource($moduleHandle, $resourceHandle)

Local $result = DllCall($kernel32, "HANDLE", "LoadResource", "HANDLE", $ieframe, "HANDLE", $resourceHandle)
ConsoleWriteIfNull($resource, "The resource is null")
Return $result


; ================= Utils ====================

Func ConsoleWriteIfNull($var, $message)

If not $var Then

ConsoleWriteError($message & @LF)



Func CheckDLLCallError($error)

Switch $error

Case 1
ConsoleWriteError("Unable to use the DLL file" & @LF)
Case 2
ConsoleWriteError("Unknown return type" & @LF)
Case 3
ConsoleWriteError("Function not found in the DLL file" & @LF)
Case 4
ConsoleWriteError("Bad number of parameters" & @LF)
Case 5
ConsoleWriteError("Bad parameter" & @LF)
Case Else



Func OpenDll($dllName)
Local $dll = DllOpen($dllName)
If ($dll = -1) Then
ConsoleWriteError("Could not load " & $dllName & @LF)
Return $dll

It seems that LoadAccelerators is returning a null value. I guess that I'm not passing the right argument/argument types, but I already tried several things to no avail.

Any help would be appreciated!

Share this post

Link to post
Share on other sites

What is it you're trying to accomplish with the shortcut keys? There is an Internet Explorer UDF that might help with this and eliminate using hotkeys all together.

Also, LoadAccelerators loads the accellerators, I don't believe it will give you anything back. Another thing, you're sending this a blank accelerator table, you're probably unsetting them with that. I'm not that familiar with what that does, so I could be guessing here. :)

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post

Link to post
Share on other sites

We are making test scripts for IE9. The company in which I'm working is making compatibility layers for different versions of IE (i.e. these layers could let you run IE6 in Windows 7). We were also asked to ship a (weak) test suit in AutoIT. These test suit should try every possibility that the IE UI gives (i.e. Try doing File -> open, Try doing Edit -> Select all, etc, etc, etc). I'm using the hotkeys to simulate these user inputs.

You're right about that function. I'm pretty lost messing around with the Windows API :P. Anyway, I can't figure out how to translate the (darn confusing) data types I see in the WinAPI documentation to the data types specified in the DllCall function documentation.

Also, yes, I know that the arguments I used in the code for the LoadAccelerators are obviously wrong and will never ever work... I tried several other things before, that was just testing.

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