Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-14-2012, 07:13 AM
lars lars is offline
Member
 
Join Date: Apr 2002
Posts: 34
Question Convert small vb code

Can someone convert this piece of vb code to delphi ?

the find window part just workes fine, somthing goes wrong because vb code use byte array?

In delphi i used SendMessage(receiverHandle,WM_COPYDATA, 0, LongInt(PChar('"BEES1113";"ON"'))); between delphi aps this just worked fine but de vb program wont see my command.

also tried:
DataStruct.dwData := 3;
DataStruct.cbData := length(s)+1;
DataStruct.lpData := pchar(s);
SendMessage(FindWindowExt(apptitle'),WM_CopyData,f orm14.handle,Integer(@DataStruct)); doesnt work either.

Someone give some help please?

Lars

Working vb code:
Code:
~      Private Sub Command1_Click()
          Dim cds As COPYDATASTRUCT
          Dim ThWnd As Long
          Dim buf(1 To 255) As Byte
          Dim a$
          Dim i

      ' Get the hWnd of the target application
          ThWnd = FindWindow(vbNullString, "apptitle")
          a$ = "BEES1113;ON"
      ' Copy the string into a byte array, converting it to ASCII
          Call CopyMemory(buf(1), ByVal a$, Len(a$))
          cds.dwData = 3
          cds.cbData = Len(a$) + 1
          cds.lpData = VarPtr(buf(1))
          i = SendMessage(ThWnd, WM_COPYDATA, Me.hwnd, cds)
      End Sub
Delphi code:
this workes but gives only the first char of the string

Code:
 var
a:   pByteArray ;
begin
recievewindow:=FindWindowExt('app title');
s:=edit1.text;
a := @s[1];
DataStruct.dwData := 3;
DataStruct.cbData := length(s)+1;
DataStruct.lpData := a;
SetString(s, PAnsiChar(DataStruct.lpData), 100);
SendMessage(recievewindow,WM_CopyData,form14.handle,Integer(@DataStruct));

Last edited by lars; 06-14-2012 at 02:28 PM.
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 12:36 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.