Excalibur Posted October 20, 2006 Posted October 20, 2006 (edited) Remove the DllCall, it works, put the DllCall in, wont even get to the first TrayTip statementWhile 1=1 TrayTip("Start of Loop", "", 30); $StartMenu = WinGetHandle(""); $Square = DllStructCreate("dword;dword;dword;dword"); DllStructSetData( $Square, 1, 10 ); DllStructSetData( $Square, 2, 10 ); DllStructSetData( $Square, 3, 200 ); DllStructSetData( $Square, 4, 200 ); TrayTip("Executeing DLL Call", "", 30); ;$result = DllCall("user32.dll", "int", "MessageBox", "hwnd", 0, "str", "Some text", "str", "Some title", "int", 0) $result = DllCall("user32.dll", "int", "DrawText", "hwnd", $StartMenu, "str", "Some text", "int", 9, "ptr", $Square, "int", 8) ;$result = 0; TrayTip("Return:", $result, 30); WEndhttp://windowssdk.msdn.microsoft.com/en-us...909(VS.80).aspx <--- Link to the API Documentation. Note: loads very slowly for some reason, like taking 2 minutes to load! (just me?) Edited October 21, 2006 by Excalibur Ooo Ëxçã¿îbúr ooO"Information Is Not Knowledge." ~Albert Einstein
this-is-me Posted October 20, 2006 Posted October 20, 2006 .... Not exactly answering your question here I know, but why go through the trouble of using DllCall? Also, you are overwriting the return value from the messagebox anyway. If you really didn't want a return value, don't use $result at all on the messagebox. While 1=1 TrayTip("Start of Loop", "", 30); $StartMenu = WinGetHandle(""); $Square = DllStructCreate("dword;dword;dword;dword"); DllStructSetData( $Square, 1, 10 ); DllStructSetData( $Square, 2, 10 ); DllStructSetData( $Square, 3, 200 ); DllStructSetData( $Square, 4, 200 ); TrayTip("Executeing DLL Call", "", 30); $result = MsgBox(0, "Some Title", "Some Text") $result = DllCall("user32.dll", "int", "DrawText", "hwnd", $StartMenu, "str", "Some text", "int", 9, "ptr", $Square, "int", 8) $result = 0; TrayTip("Return:", $result, 30); WEnd Who else would I be?
Excalibur Posted October 21, 2006 Author Posted October 21, 2006 Larry: 1) I thought DllStructCreate returned the pointer of the struct. 2) Even with the modification you suggested, same thing happens. Just sits there locked, ever getting to the first TrayTip message. This-is-me: the messagebox was commented out, I used it to test just to see if other dllcalls to user32 would work. Ooo Ëxçã¿îbúr ooO"Information Is Not Knowledge." ~Albert Einstein
GaryFrost Posted October 21, 2006 Posted October 21, 2006 Your tray tip calls are incorrect to begin with While 1 TrayTip("","Start of Loop", 30); $StartMenu = WinGetHandle(""); $Square = DllStructCreate("dword;dword;dword;dword"); DllStructSetData( $Square, 1, 10 ); DllStructSetData( $Square, 2, 10 ); DllStructSetData( $Square, 3, 200 ); DllStructSetData( $Square, 4, 200 ); TrayTip("","Executeing DLL Call", 30); ;~ $result = DllCall("user32.dll", "int", "MessageBox", "hwnd", 0, "str", "Some text", "str", "Some title", "int", 0) $result = DllCall("user32.dll", "int", "DrawText", "hwnd", $StartMenu, "str", "Some text", "int", 9, "ptr", DllStructGetPtr($Square), "int", 8) Sleep ( 3000 ) ;$result = 0; TrayTip("Return:", '"' & $result[0] & '"', 30); Sleep ( 3000 ) WEnd SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
PaulIA Posted October 21, 2006 Posted October 21, 2006 The prototype for DrawText is: int DrawText( HDC hDC, // handle to device context LPCTSTR lpString, // pointer to string to draw int nCount, // string length, in characters LPRECT lpRect, // pointer to structure with formatting dimensions UINT uFormat // text-drawing flags ); Problems: 1) Your passing a window handle instead of a handle to the window's device context. 2) You need to pass a pointer to a string, not a string. 3) You need to pass a pointer to the RECT structure as previously mentioned. Here is a working example: $DT_LEFT = 0; $aResult = DllCall("user32.dll", "hwnd", "GetDC", "hwnd", 0) $hDC = "0x" & Hex($aResult[0]) ConsoleWrite("hDC handle ....: " & $hDC & @CR) $rRect = DllStructCreate("int;int;int;int") $pRect = DllStructGetPtr($rRect) $rBuffer = DllStructCreate("char[4096]") $pBuffer = DllStructGetPtr($rBuffer) DllStructSetData($rRect, 1, 10) DllStructSetData($rRect, 2, 10) DllStructSetData($rRect, 3, 400) DllStructSetData($rRect, 4, 30) DllStructSetData($rBuffer, 1, "Some text that you want to display on the desktop") $aResult = DllCall("user32.dll", "int", "DrawText", "hwnd", $hDC, "ptr", $pBuffer, "int", -1, "ptr", $pRect, "int", $DT_LEFT) ConsoleWrite("Text height ...: " & $aResult[0] & @CR) $aResult = DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "hwnd", $hDC) Make sure the upper left corner of your display is not covered by anything when you run this or you'll never see any results. Auto3Lib: A library of over 1200 functions for AutoIt
Excalibur Posted October 21, 2006 Author Posted October 21, 2006 gafrost: There is nothing wrong with my TrayTip functions. They were written in that fashion intentionally and they are not causing the malfunction in the program. Thanks for your input. PaulIA: Thanks alot. I can never seem to get the windows API to work for me. Guess thats what years of being a Java programmer gets me. :-P Ooo Ëxçã¿îbúr ooO"Information Is Not Knowledge." ~Albert Einstein
Valik Posted October 21, 2006 Posted October 21, 2006 PaulIA, what exactly do you think the "str" type for DllCall() does? It allocates a char[] buffer and passes the pointer to that buffer because that's what a C-style string is. In other words, don't over-complicate things by using DllStruct() when it's not needed.
PaulIA Posted October 21, 2006 Posted October 21, 2006 @Excalibur: Your welcome Auto3Lib: A library of over 1200 functions for AutoIt
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now