请教关于delphi关于sendmessage接收的问题 ( 积分: 200 )

  • 主题发起人 主题发起人 Emmyling
  • 开始时间 开始时间
E

Emmyling

Unregistered / Unconfirmed
GUEST, unregistred user!
别人用vc做了个dll给我用delphi调用,在dll中他把我需要的数据用sendmessage发出,<br>LParam是指向字符串的地址,请问如何从LParam中取得数据。请大家帮忙
 
别人用vc做了个dll给我用delphi调用,在dll中他把我需要的数据用sendmessage发出,<br>LParam是指向字符串的地址,请问如何从LParam中取得数据。请大家帮忙
 
我以前写的一个例子,供参考<br><br>TInfo = record<br> &nbsp; &nbsp; &nbsp; &nbsp;nPos, nTotal: Integer;<br> &nbsp; &nbsp;end;<br><br>procedure TForm1.Info(var msg: TMessage);<br>var<br> &nbsp; &nbsp;P : TInfo;<br>begin<br> &nbsp; &nbsp;if msg.Msg = WM_Info then begin<br> &nbsp; &nbsp; &nbsp; &nbsp;p := TInfo(Pointer(msg.LParam)^);<br>// 用Pointer(msg.LParam)^ 取出来,然后用一个结构体强制类型转换,这里根据自己的需要,看它传的是什么,也可以把VC的消息发送的代码放上来看<br> &nbsp; &nbsp; &nbsp; &nbsp;ProgressBar1.Max := p.nTotal;<br> &nbsp; &nbsp; &nbsp; &nbsp;ProgressBar1.Min := 0;<br> &nbsp; &nbsp; &nbsp; &nbsp;ProgressBar1.Position := p.nPos;<br> &nbsp; &nbsp;end;<br>end;<br><br>发送消息代码如下<br><br>procedure TMyThread.Execute;<br>var<br> &nbsp; &nbsp;p : TInfo;<br>begin<br> &nbsp; &nbsp;while not Terminated do begin<br> &nbsp; &nbsp; &nbsp; &nbsp;if &nbsp;nPos &lt; nTotal then begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;p.nPos := nPos;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;p.nTotal := nTotal;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Inc(nPos);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if FMainHandle &lt;&gt; 0 then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SendMessage(FMainHandle, WM_Info, 0, Integer(@P));<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end;<br>end;
 
我试了这个方法但是强制转换报错<br>vc的sendmessage是SendMessage( hStatuWnd, SB_SETBKCOLOR, &nbsp;0, 0x0000FF00);SendMessage( hStatuWnd, SB_SETTEXT, (WPARAM)(0),(LPARAM)aucBuf );<br>aucBuf是字符串型,这样的应该怎么去取值呢
 
aucBuf是一个char * 类型的吗?还是char的数组,如果是char *的,可以用<br><br>PChar(msg.LParam)^; <br><br>然后用function StrPas(const Str: PChar): string; 这个函数来取,大概是这样,不烦把aucBuff的相关代码也放上来看看<br><br>这种问题lichengbin大虾很厉害
 
TCHAR aucBuf[60];<br>strcpy( &amp;aucBuf[strlen(aucBuf)], TEXT(&quot;年 &nbsp;/0&quot;) );<br>就是这样用的,我用pchar过,取出来为空
 
感觉自己在误人子弟[:)]<br><br>第一个,看直接设置一个char的数组,然后用上面的方法读取<br><br>第二,在spcomm读取数据里面有个经典的例子,看看对你有用没有,也就是把Buffer这个指针直接转成了char的数组,再不行就只有等高手了,惭愧<br>procedure TReceiveFrm.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;<br> &nbsp;BufferLength: Word);<br>var<br> &nbsp;tmpstr: array [0..2048] of integer;<br> &nbsp;i: integer;<br>begin<br> &nbsp;Move(Buffer^,tmpstr,BufferLength);<br> &nbsp;for i := 0 to BufferLength-1 do<br> &nbsp;Memo1.Lines.Add(char(tmpstr));<br>end;
 
可以了,谢谢
 
后退
顶部