vb写的程序发送消息
SendMessage hwnd, 1234, 4321, "wowwow"delphi中接收到信息
其中msg和WParam都是正常的intLParam应该是"wowwow"这个字符串的指针地址,所以:
Edit1.Text := PChar(Pointer(Message.LParam));
但得到的结果却是乱码。怎样才可以得到正确的字符串?

解决方案 »

  1.   


    //发送消息
    var
      PromptStr: String;
    begin
      PromptStr := 'Export BOM........';
      PostMessage(Application.MainForm.Handle, CM_TestMessage, ADataSet.RecordCount, Integer(PromptStr));
      Application.ProcessMessages;
    end;//Msg的LParam参数为字符串地址
    procedure TfrmMain.TestMessage(var Msg: TMessage);
    var
      PromptStr: String;
    begin
      PromptStr := String(Msg.LParam);
      if not SameText(PromptStr, EmptyStr) then
        staBar.Panels[1].Text := PromptStr;
      Application.ProcessMessages;
      Screen.Cursor := crHourGlass;
    end;
      

  2.   

    SendMessage 函数你是怎么定义的?
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long SendMessage   hwnd,   1234,   4321,   ByVal CStr("wowwow ")  '注意了,要ByVal传递字符串
      

  3.   

    要傳遞"wowwow " 的地址過去,1樓已經說明了
      

  4.   

    不懂就不要乱说!!!
    VB里能取变量地址么???
    所以1楼的Pascal代码对VB来说没用!!!
    用下面的,自然就给你发送地址,把 CStr去掉算了,
    SendMessage       hwnd,       1234,       4321,       ByVal   "wowwow"