VicTT Posted January 9, 2007 Posted January 9, 2007 Sender: #include <Misc.au3> $x=DllStructCreate("char[6]") DllStructSetData($x,1,"Hello") _SendMessage(WinGetHandle("RECEIVER"),0x0401,DllStructGetPtr($x),DllStructGetSize($x)) #cs Attempted fixes: 1. Using types "dword", or "ptr" as parameter 6 of _SendMessage #ce Receiver: Global $t="RECEIVER" Func Rcvd($hwnd,$msg,$w,$l) if $msg=0x0401 then MsgBox(64,$t,"Got the message..wparam(pointer) is "&$w&" and lparam(size) is "&$l,1) $struct=DllStructCreate("char["&$l&"]",$w) if @error then Return MsgBox(16,$t,"Could not alloc dllstruct") if IsDllStruct($struct) then MsgBox(64,"","We have the structure!",1) if DllStructGetPtr($struct)=$w then MsgBox(64,"","We even have it at the same address!",1) $a=DllStructGetData($struct,1) if @error then MsgBox(48,$t,"Failed to get the data from the dllstruct(WHY??!!)..Failed with error "&@error,3) else MsgBox(32,"","Damn..It worked..Data received: "&$a) endif endif EndFunc GUICreate("RECEIVER") GUIRegisterMsg(0x0401,"Rcvd") while 1 Sleep(50) wend The problem is that I'm getting the structure, apparently at the same address, but I'm getting @error=2 when calling DllStructGetData($struct,1) to get the "hello"..I'm really stuck, and would heartfully appreciate any input on the matter...I'm sure the bigger half of you know more Windows API than me.. Quote Together we might liveDivided we must fall
VicTT Posted January 12, 2007 Author Posted January 12, 2007 *Bump Quote Together we might liveDivided we must fall
Zedna Posted January 14, 2007 Posted January 14, 2007 Only little note: What about RegisterWindowMessage() API?RegisterWindowMessage The RegisterWindowMessage function defines a new window message that is guaranteed to be unique throughout the system. The returned message value can be used when calling the SendMessage or PostMessage function. UINT RegisterWindowMessage( LPCTSTR lpString // address of message string ); ParameterslpStringPoints to a null-terminated string that specifies the message to be registered. Return ValuesIf the message is successfully registered, the return value is a message identifier in the range 0xC000 through 0xFFFF.If the function fails, the return value is zero. RemarksThe RegisterWindowMessage function is typically used to register messages for communicating between two cooperating applications. If two different applications register the same message string, the applications return the same message value. The message remains registered until the Windows session ends. Only use RegisterWindowMessage when more than one application must process the same message. For sending private messages within a window class, an application can use any integer in the range WM_USER through 0x7FFF. (Messages in this range are private to a window class, not to an application. For example, predefined control classes such as BUTTON, EDIT, LISTBOX, and COMBOBOX may use values in this range.)SendMessageThe SendMessage function sends the specified message to a window or windows. The function calls the window procedure for the specified window and does not return until the window procedure has processed the message. The PostMessage function, in contrast, posts a message to a thread's message queue and returns immediately. LRESULT SendMessage( HWND hWnd, // handle of destination window UINT Msg, // message to send WPARAM wParam, // first message parameter LPARAM lParam // second message parameter ); ParametershWndIdentifies the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows. MsgSpecifies the message to be sent. wParamSpecifies additional message-specific information. lParamSpecifies additional message-specific information. Return ValuesThe return value specifies the result of the message processing and depends on the message sent. RemarksApplications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a unique message for inter-application communication.If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the specified window was created by a different thread, Windows switches to that thread and calls the appropriate window procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The sending thread is blocked until the receiving thread processes the message. Resources UDF ResourcesEx UDF AutoIt Forum Search
VicTT Posted January 14, 2007 Author Posted January 14, 2007 I'm sure it could prove useful, and I will implement it as soon as I can..Any ideas on why my program(s) don't work, though? Thank you for answering ...It only took you 30 minutes, while others have been ignoring it for 5 days.. Quote Together we might liveDivided we must fall
Zedna Posted January 14, 2007 Posted January 14, 2007 (edited) I'm sure it could prove useful, and I will implement it as soon as I can..Any ideas on why my program(s) don't work, though?Thank you for answering ...It only took you 30 minutes, while others have been ignoring it for 5 days..They maybe don't ignore it only don't know answer EDIT: you should say what message is 0x0401Now I know it's WM_USER + 1 but I must search it in AutoIt helpfile Edited January 14, 2007 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
VicTT Posted January 14, 2007 Author Posted January 14, 2007 I just picked it as being the first 'untaken' (according to the helpfile) message, and used that.... Quote Together we might liveDivided we must fall
Zedna Posted January 14, 2007 Posted January 14, 2007 (edited) I know reason:For interprocess comunication via messages where are used pointers (DllStructCreate)there must be used memory UDF. See Auto3Lib from PaulIA. There he used it for get text from TreeView in another application.EDIT: Look at _TreeView_GetText() in his A3LTreeView.au3 Edited January 14, 2007 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
VicTT Posted January 14, 2007 Author Posted January 14, 2007 So how would I do it?I'm seeing A3LMemory.au3 as being useful...But with all the funny redefinitions/naming scheme of the functions, I don't really understand how to use it.. Quote Together we might liveDivided we must fall
Zedna Posted January 14, 2007 Posted January 14, 2007 So how would I do it?I'm seeing A3LMemory.au3 as being useful...But with all the funny redefinitions/naming scheme of the functions, I don't really understand how to use it.. This latest syntax of Auto3Lib is for me less readable too. So here is code from older version for you to learn something: Func _TreeView_GetText($hWnd, $hItem) Local $rBuffer Local $pBuffer Local $rMemMap Local $pMemory Local $sResult Local $pText Local $iTVSize Local $pTVItem Local $rTVItem $rTVItem = _DllStructCreate ($TV_ITEM) $iTVSize = _DllStructGetSize($rTVItem) $pTVItem = _DllStructGetPtr ($rTVItem) $rMemMap = _DllStructCreate ($MEM_MAP) $pMemory = _MemInit($hWnd, $iTVSize + 4096, $rMemMap) $pText = $pMemory + $iTVSize _DllStructSetData($rTVItem, $TV_ITEM_MASK , $TVIF_TEXT) _DllStructSetData($rTVItem, $TV_ITEM_HITEM , $hItem ) _DllStructSetData($rTVItem, $TV_ITEM_PSZTEXT , $pText ) _DllStructSetData($rTVItem, $TV_ITEM_CCHTEXTMAX, 4096 ) _MemWrite($rMemMap, $pTVItem) _SendMessage($hWnd, $TVM_GETITEM, 0, $pMemory) $rBuffer = _DllStructCreate("char[4096]") $pBuffer = _DllStructGetPtr($rBuffer) _MemRead($rMemMap, $pText, $pBuffer, 4096) $sResult = _DllStructGetData($rBuffer, 1) _MemFree($rMemMap) $rBuffer = 0 $rTVItem = 0 $rMemMap = 0 Return $sResult EndFunc Resources UDF ResourcesEx UDF AutoIt Forum Search
VicTT Posted January 14, 2007 Author Posted January 14, 2007 Hmm...One big problem...I don't have the def's of _DllStructSetData and don't know how the _Mem's work...Hmmm...If this could be reduced to something more readable so that I wouldn't have to bounce back and forth between UDF definitions, it would be great... As far as I understood, using _Mem_Init() you allocate 4k of memory, and use that as a buffer zone..Anyone can write to that, but it's still not clear how I would do that..You can read it...It's still very unclear.. Quote Together we might liveDivided we must fall
Zedna Posted January 14, 2007 Posted January 14, 2007 _DllStructSetData() is the same as DllStructSetData() only with some more error checking and such. So for your purpose it's not important. Memory functions are the same as in Memory UDF. Did you download that Auto3Lib and looked into it? Resources UDF ResourcesEx UDF AutoIt Forum Search
VicTT Posted January 14, 2007 Author Posted January 14, 2007 (edited) If you are refering to the old one that you copy&pasted from, no I haven't because I have no idea where to get it from... EDIT: I have the latest one, in which the function looks something like: Func _TreeView_GetText($hWnd, $hNode) Local $iItem, $tItem, $pItem, $pBuffer, $tBuffer, $pMemory, $tMemMap, $pText $tBuffer = _tagCHARARRAY(4096) $pBuffer = _tagGetPtr($tBuffer) $tItem = __tagTVITEMEX() $pItem = _tagGetPtr($tItem) _tagSetData($tItem, "Mask" , $TVIF_TEXT) _tagSetData($tItem, "hItem" , $hNode ) _tagSetData($tItem, "TextMax", 4096 ) if _Lib_InProcess($hWnd) then _tagSetData($tItem, "Text", $pBuffer) _API_SendMessage($hWnd, $TVM_GETITEM, 0, $pItem) else $iItem = _tagGetSize($tItem) $pMemory = _Mem_Init($hWnd, $iItem + 4096, $tMemMap) $pText = $pMemory + $iItem _tagSetData($tItem, "Text", $pText) _Mem_Write($tMemMap, $pItem, $pMemory, $iItem) _API_SendMessage($hWnd, $TVM_GETITEM, 0, $pMemory) _Mem_Read($tMemMap, $pText, $pBuffer, 4096) _Mem_Free($tMemMap) endif Return _tagGetData($tBuffer, 1) EndFunc Edited January 14, 2007 by VicTT Quote Together we might liveDivided we must fall
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