I have one application with a Dialogbox as main and with 3 editcontrols.

I have a second application which reads data from the serial port. This app also have data occasionally painted in a childwindow depending on the mousepointer position.

Both apps loads the same dll in order to retrieve data from the second app and send it to the first app. This is the dll in principle.
DllEntry proc hInst:HINSTANCE, reason:DWORD, reserved1:DWORD


DllEntry ENDP

Capture proc
.
.
call ReadFile ;Call kernel32.dll function
invoke GetFileType,hFile
.if eax==FILE_TYPE_CHAR ;serial port
invoke SendMessage,hWin,WM_COPYDATA,0,lpBuffer
.endif
.
.
ret
Capture endp

Capture2 proc
.
.
call DrawTextA ;Call user32.dll function
.
invoke SendMessage,hWin,WM_COPYDATA,0,lpBuffer2
.
.
ret
Capture2 endp

End DllEntry

The Capture proc retrieves the serial data and SendMessage COPY_DATA to the DlgProc, more exactly to the editcontrol hEdt3.

The Capture2 proc retrieves two data strings which should be destinated to editcontrols hEdt1 and hEdt2.
DlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

.
.elseif eax==WM_COPYDATA
.
invoke SendMessage,hEdt1,WM_SETTEXT,FALSE,lParam
invoke SendMessage,hEdt2,WM_SETTEXT,FALSE,lParam
invoke SendMessage,hEdt3,EM_REPLACESEL,FALSE,lParam
.endif
mov eax,TRUE
ret
DlgProc endp

How do I do to link the 3 data strings to their predestinated editcontrols? Is it possible to use the wParam to separate the data strings? Or should I subclass the editcontrols? Any bright suggestions?

Regards
Posted on 2003-03-13 15:33:23 by minor28
You don't seem to use the wParam for anything else. You can certainly use it to specify which edit control the string should go to.

Raymond
Posted on 2003-03-14 00:23:38 by Raymond
Still not working as I want.

This is what I have done.
Capture2 proc [color=green];dll function[/color]

.
mov ecx,[esp+(3*4)] [color=green];address of structure with formatting dimensions[/color]
.if ecx==12f9e0h
invoke RtlZeroMemory,addr lpBuffer2,100h
mov ecx,[esp+(2*4)] [color=green];string length, in characters[/color]
mov esi,[esp+(1*4)] [color=green];address of string to draw[/color]
lea edi,lpBuffer2
rep movsb
mov ecx,[esp+(2*4)] [color=green];string length, in characters[/color]
.if ecx==4
invoke SendMessage,hWin,WM_COPYDATA,1020,addr lpBuffer2
.elseif ecx==7
invoke SendMessage,hWin,WM_COPYDATA,1021,addr lpBuffer2
.elseif ecx==11
invoke SendMessage,hWin,WM_COPYDATA,1009,addr lpBuffer2
.elseif ecx==12
invoke SendMessage,hWin,WM_COPYDATA,1010,addr lpBuffer2
.endif
.endif
call DrawTextA [color=green];Call user32.dll function[/color]
.
Capture2 endp

DlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
.
.elseif eax==WM_COPYDATA
.if wParam==IDC_EDT6 [color=green];=1020[/color]
invoke SendMessage,hEdt6,WM_SETTEXT,FALSE,lParam
.elseif wParam==IDC_EDT7 [color=green];=1021[/color]
invoke SendMessage,hEdt7,WM_SETTEXT,FALSE,lParam
.elseif wParam==IDC_EDT3 [color=green];=1009[/color]
invoke SendMessage,hEdt4,WM_SETTEXT,FALSE,lParam
.elseif wParam==IDC_EDT4 [color=green];=1010[/color]
invoke SendMessage,hEdt3,WM_SETTEXT,FALSE,lParam
.
DlgProc endp

I don't understand why the two latter SendMessages in the Capture2 proc not are sent to the DlgProc. First DrawText is the 12 characters string, the second is the 11 char, the third is the 4 char and last the 7 char.

When debugging I can follow the whole procedure. For each of the four messages I can see that hWin, VM_COPYDATA, constant and string at addr lpBuffer2 are correct.

But in the DlgProc the two first messages, i.e. messages to IDC_EDT3 and IDC_EDT4 are not recieved at all. Only the two later messages are received and shown correctly.

Any idea what could be wrong.

Regards
Posted on 2003-03-15 14:27:06 by minor28
I notice in your DlgProc that when wParam==IDC_EDT3, you send the message to hEdt4.

And when wParam==IDC_EDT4, you send the message to hEdt3. Is that by design? (Your two other IDC_ constants have the suffix related to the Edit handle.)

Have you checked the validity of your equates?

And lastly, why don't you use the the same reference for the wParam (either numbers or equates) in both the dll and the DlgProc??

Raymond
Posted on 2003-03-15 22:51:35 by Raymond
Raymond, thank you for your helpfulness.

I notice in your DlgProc that when wParam==IDC_EDT3, you send the message to hEdt4.

And when wParam==IDC_EDT4, you send the message to hEdt3. Is that by design? (Your two other IDC_ constants have the suffix related to the Edit handle.)

You are right, they should be switched. However this should only cause the text to land up in wrong editcontrol.

Have you checked the validity of your equates?

And lastly, why don't you use the the same reference for the wParam (either numbers or equates) in both the dll and the DlgProc??

Yes they are valid in the Dlgproc. The reason why I don't use equates in the dll function is just because I haven't declared them. As I understand, this could not be the reson to failure. Two of the four are correct.

The first two strings (for example "145?" and "0.245nm") are correctly sent and recieved. These are the two blue lines. The two latter strings (for example 46?25.245 N" and "018?33.245 E") are sent but not recieved. If I insert a breakpoint on the red line, only the two first arrives to the breakpoint but never the two latter.
.elseif eax==WM_COPYDATA

[color=red].if wParam==IDC_EDT6[/color]
[color=blue]invoke SendMessage,hEdt6,WM_SETTEXT,FALSE,lParam[/color]
.elseif wParam==IDC_EDT7
[color=blue]invoke SendMessage,hEdt7,WM_SETTEXT,FALSE,lParam[/color]
.elseif wParam==IDC_EDT3
invoke SendMessage,hEdt4,WM_SETTEXT,FALSE,lParam
.elseif wParam==IDC_EDT4
invoke SendMessage,hEdt3,WM_SETTEXT,FALSE,lParam

I have followed each step in the dll function and I have establish the fact that every argument of the four SendMessages are correct. So I can't understand why just these two strings not reaches the DlgProc.

Regards
Posted on 2003-03-16 11:11:32 by minor28
Is lpbuffer2 a global var?
Posted on 2003-03-16 11:22:30 by roticv
Is lpbuffer2 a global var?


.data?

lpBuffer2 dd 100h dup (?)
Posted on 2003-03-16 11:50:38 by minor28
I came to think of that only strings less than 8 characters were sent. WM_COPYDATA structure declare lParam as a pointer to a COPYDATASTRUCT. in light of this fact I Changed the code (red lines).
Capture2 proc [color=green];dll function[/color]

.
mov ecx,[esp+(3*4)] [color=green];address of structure with formatting dimensions[/color]
.if ecx==12f9e0h
[color=red]mov eax,[esp+(1*4)][/color] [color=green];address of string to draw[/color]
[color=red]mov eax,[eax][/color]
[color=red]mov cds.dwData,eax[/color] [color=green];cds = COPYDATASTRUCT[/COLOR]
mov ecx,[esp+(2*4)] [color=green];string length, in characters[/color]
.if ecx==4
invoke SendMessage,hWin,WM_COPYDATA,1020,addr cds
.elseif ecx==7
invoke SendMessage,hWin,WM_COPYDATA,1021,addr cds
.elseif ecx==11
invoke SendMessage,hWin,WM_COPYDATA,1009,addr cds
.elseif ecx==12
invoke SendMessage,hWin,WM_COPYDATA,1010,addr cds
.endif
.endif
call DrawTextA [color=green];Call user32.dll function[/color]
.
Capture2 endp

DlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
.
.elseif eax==WM_COPYDATA
[color=red]mov eax,lParam
assume eax:ptr COPYDATASTRUCT[/color]
.if wParam==IDC_EDT6 [color=green];=1020[/color]
invoke SendMessage,hEdt6,WM_SETTEXT,FALSE,[color=red]addr [eax].dwData[/color]
.elseif wParam==IDC_EDT7 [color=green];=1021[/color]
invoke SendMessage,hEdt7,WM_SETTEXT,FALSE,[color=red]addr [eax].dwData[/color]
.elseif wParam==IDC_EDT3 [color=green];=1009[/color]
invoke SendMessage,hEdt4,WM_SETTEXT,FALSE,[color=red]addr [eax].dwData[/color]
.elseif wParam==IDC_EDT4 [color=green];=1010[/color]
invoke SendMessage,hEdt3,WM_SETTEXT,FALSE,[color=red]addr [eax].dwData[/color]
.
DlgProc endp

As the code now are, the four editboxes show "145?", "0.24", "46?2" respective ""018?" i.e. only 4 characters. I have tried both lpData and dwData with different points of application, but the code above is the nearast I came. Perhaps line "mov eax, is the reason but I don't know how to solve it. Any suggestens?

Regards
Posted on 2003-03-16 15:38:25 by minor28
mov eax, ;address of string to draw
mov eax,
mov cds.dwData,eax ;cds = COPYDATASTRUCT

What you are doing with the mov eax, instruction is moving the first 4 characters of the string into eax. You are then storing those 4 characters in the variable "dwData" in the cds structure.

You are then using the address of the dwData variable to set the text in your edit boxes. The byte following that dwData variable in the structure (or in the memory following that structure if dwData is the last item) is most probably a zero since you are displaying only the 4 characters.

Try this:
1) remove the mov eax, instruction so that you will store the string address in the dwData variable.
2) remove the "addr" from the addr .dwData when you send the WM_SETTEXT message to send whatever you stored as the actual buffer address.

Raymond
Posted on 2003-03-16 22:54:29 by Raymond
My mistake. I thought it was a local var as invoke RtlZeroMemory,addr lpBuffer2,100h was used. I would normally use invoke RtlZeroMemory,OFFSET lpBuffer2,100h. Furthermore working on your previous code, I think that line is not needed. You could do



.
.if ecx==12f9e0h
; invoke RtlZeroMemory,addr lpBuffer2,100h
mov ecx,[esp+(2*4)] ;string length, in characters
mov esi,[esp+(1*4)] ;address of string to draw
lea edi,lpBuffer2
rep movsb
mov ecx,[esp+(2*4)] ;string length, in characters
mov BYTE PTR[ecx+edi+1], '0' ; terminate the string
.
.
.
Posted on 2003-03-17 01:46:32 by roticv
What you suggest isn't it only another way to set the memory to zero with the difference that the whole space not is set to zero but only one byte after the string.

BTW shouldn't it be
mov BYTE PTR, 0h

Regards
Posted on 2003-03-17 02:17:46 by minor28
yesyes... just that i should not be using the '
Posted on 2003-03-17 04:57:45 by roticv
Hi Raymond,

I tried what you suggested, but it didn't work. The next thing to do was to closly scrutinize the COPYDATASTRUCT.


As you can see dwData passes up to 32 bits to the receiving app, i.e. 4 characters. What to do is to specify the sise in bytes in cbData and to store the address to the lpBuffer2 in lpData. Now it works. The code is as follows.
typedef struct tagCOPYDATASTRUCT {  // cds 

DWORD dwData;
DWORD cbData;
PVOID lpData;
} COPYDATASTRUCT;

[b]dwData[/b]=Specifies up to 32 bits of data to be passed to the receiving application.
[b]cbData[/b]=Specifies the size, in bytes, of the data pointed to by the lpData member.
[b]lpData[/b]=Points to data to be passed to the receiving application. This member can be NULL

Capture2 proc [color=green];dll function[/color]

.
mov ecx,[esp+(3*4)] [color=green];address of structure with formatting dimensions[/color]
.if ecx==12f9e0h
invoke RtlZeroMemory,addr lpBuffer2,100h
mov ecx,[esp+(2*4)] [color=green];string length, in characters[/color]
add ecx,1 [color=green];add 1 byte to get the zero termination[/color]
mov cds.cbData,ecx
mov esi,[esp+(1*4)] [color=green];address of string to draw[/color]
lea edi,lpBuffer2 [color=green];address of buffer[/color]
mov cds.lpData,edi
rep movsb
mov ecx,[esp+(2*4)] [color=green];string length, in characters[/color]
.if ecx==4
[color=green];Course[/color]
invoke SendMessage,hWin,WM_COPYDATA,1020,addr cds
.elseif ecx>4 && ecx<=7
[color=green];Distance[/color]
invoke SendMessage,hWin,WM_COPYDATA,1021,addr cds
.elseif ecx==11
[color=green];Latitude[/color]
invoke SendMessage,hWin,WM_COPYDATA,1009,addr cds
.elseif ecx==12
[color=green];Longitude[/color]
invoke SendMessage,hWin,WM_COPYDATA,1010,addr cds
.endif
.endif
.
Capture2 endp

DlgProc proc
.
.elseif eax==WM_COPYDATA
mov eax,lParam
assume eax:ptr COPYDATASTRUCT
.if wParam==IDC_EDT6
invoke SendMessage,hEdt6,WM_SETTEXT,FALSE,[eax].lpData
.elseif wParam==IDC_EDT7
invoke SendMessage,hEdt7,WM_SETTEXT,FALSE,[eax].lpData
.elseif wParam==IDC_EDT3
invoke SendMessage,hEdt3,WM_SETTEXT,FALSE,[eax].lpData
.elseif wParam==IDC_EDT4
invoke SendMessage,hEdt4,WM_SETTEXT,FALSE,[eax].lpData
.
DlgProc endp

Thank you Raymond and roticv for your help. Problems are much easier to solve when one have access to mutual exchange of experience and knowledge.
Best regards
Posted on 2003-03-17 10:53:06 by minor28
You're welcome.

Trying to find and correct errors in one's own text can be frustrating, whether it's only a plain letter or source code. Some of these errors just seem to jump out like a red marker for someone else when sufficient information is available.

I have learned to rely early on my debugger before I get too frustrated trying to find why results are not as expected.

Raymond
Posted on 2003-03-17 12:30:36 by Raymond