Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to receive SendMessage Api
Message
From
31/08/2016 10:56:24
 
 
To
31/08/2016 02:25:32
Metin Emre
Ozcom Bilgisayar Ltd.
Istanbul, Turkey
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Miscellaneous
Thread ID:
01640177
Message ID:
01640258
Views:
97
This message has been marked as the solution to the initial question of the thread.
>>>Hi All,
>>>
>>>I have to use Sendmessage Winapi and receive message from opposite application. I found this code from internet:
>>>
>>>
>>>
>>>
>>>Declare Long FindWindowA In Win32API String cNULL, String cWinName
>>>DECLARE LONG SendMessage IN user32 AS WinAPI_SendMessage ; 
>>>	LONG,; 
>>>	LONG,; 
>>>	LONG,; 
>>>	STRING @
>>>sTitle = "kl_ecrsunucu"
>>>iHwnd = FindWindowA(0, sTitle)
>>>#DEFINE WM_COPYDATA 	0x004A
>>>*  _vfp.hWnd
>>>xstr="qqq"
>>>lnRetVal = WinAPI_SendMessage(ihWnd, WM_COPYDATA, this.HWnd , @xstr)
>>>WAIT WINDOW lnretval 
>>>
>>>
>>>opposite application look for kl_ecrclient caption at my form. What I should do for receive message after change my forms caption? How can I read message from opposite?
>>
>>Metin,
>>
>>If you use COPYDATA, then
>>the string ( xstr ) must respect the format - length is 12 bytes
>>
>>
>>
>>typedef struct tagCOPYDATASTRUCT {
>>  ULONG_PTR dwData;	&& any data: The data to be passed to the receiving application
>>  DWORD     cbData; && The size, in bytes, of the data pointed to by the lpData member
>>  PVOID     lpData; && The data to be passed to the receiving application. This member can be NULL.	
>>} COPYDATASTRUCT, *PCOPYDATASTRUCT;
>>
>>
>>dwData : see above
>>cbData: see above
>>lpData: since this is a pointer to the data (ie the address, you have to allocate this space with an api - eg HeapAlloc(). Do not forget to free the buffer on exit : HeapFree)
>>
>>Sending:
>>
>>You can copy data to the allocated lpdata buffer with sys(2600)
>>
>>Receive:
>>
>>function ReceiveDetailMessage(hwnd, msg, wparam, lparam)
>>
>>	local dwdata, cbdata , lpData, s
>>		
>>	dwdata = ctobin(Sys(2600, m.lparam+0, 4), '4rs')
>>	cbdata = ctobin(Sys(2600, m.lparam+4, 4), '4rs')
>>	lpData = ctobin(Sys(2600, m.lparam+8, 4), '4rs')
>>	s= sys(2600, m.lpData, m.cbdata )
>>	
>>
>
>When you saying "length is 12 bytes", what you mean?
>
>Thank you,

Your xstr must be exactly 12 bytes - see the COPYDATASTRUCT

( copied from above)
>>typedef struct tagCOPYDATASTRUCT {
>>  ULONG_PTR dwData;	&& any data: The data to be passed to the receiving application
>>  DWORD     cbData; && The size, in bytes, of the data pointed to by the lpData member
>>  PVOID     lpData; && The data to be passed to the receiving application. This member can be NULL.	
>>} COPYDATASTRUCT, *PCOPYDATASTRUCT;
>>
>>
>>dwData : see above
>>cbData: see above
>>lpData: since this is a pointer to the data (ie the address, you have to allocate this space with an api - eg HeapAlloc(). Do not forget to free the buffer on exit : HeapFree)

So
bytes 1-4 : anything you need - or do not use it
bytes 4-8 : the length of the string
bytes 9-12: the address ( or a pointer) of a buffer allocated by HeapAlloc(). -if the length of the strings change, allocate the maximum you will need, and change bytes 4-8 for each message

You put the data starting at the address of the buffer ( allocated with HeapAlloc()) and copy the data using sys(2600)
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform