Jump to content

GUIRegisterMsg usage


VicTT
 Share

Recommended Posts

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

 

Link to comment
Share on other sites

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

);

Parameters

lpString

Points to a null-terminated string that specifies the message to be registered.

Return Values

If 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.

Remarks

The 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.)

SendMessage

The 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

);

Parameters

hWnd

Identifies 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.

Msg

Specifies the message to be sent.

wParam

Specifies additional message-specific information.

lParam

Specifies additional message-specific information.

Return Values

The return value specifies the result of the message processing and depends on the message sent.

Remarks

Applications 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.

Link to comment
Share on other sites

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 :D...It only took you 30 minutes, while others have been ignoring it for 5 days..

Quote

Together we might liveDivided we must fall

 

Link to comment
Share on other sites

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 :D...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 :D

EDIT: you should say what message is 0x0401

Now I know it's WM_USER + 1 but I must search it in AutoIt helpfile

Edited by Zedna
Link to comment
Share on other sites

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 by Zedna
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

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

 

Link to comment
Share on other sites

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 by VicTT
Quote

Together we might liveDivided we must fall

 

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...