delphi调用VC动态库,动态库向窗体发送自定义消息。请问怎么接收消息,并显示接收到的字符
procedure TTestVcDLLForm.WMBarIcon(var Message:TMessage);
var
  b:byte;
  buffer:pchar;
begin
  GetMem(Buffer,86*2+1);  StrCopy(Buffer,Pchar(Message.LParam));
  edit1.Text:=inttostr(Message.LParam);
  edit2.Text:=Buffer;
  FreeMem(Buffer);
//b:=strtoint(Pchar(Message.LParam));
//edit2.Text:=inttostr(b);
  //edit2.Text:=inttostr(Message.WParam);showmessage('ok');
end;

解决方案 »

  1.   

    procedure TTestVcDLLForm.WMBarIcon(var Message:TMessage);
    begin
      edit1.Text:=PChar(Pointer(Message.LParam));
    end;
      

  2.   

    谢谢楼上的,但怎么是空的,应该有一个字节的内容:LParam:268526603
    WParam:1           //长度
      

  3.   

    LParam 应该是个指针而已,看不出什么的,
    要看它指向的内存,那才是你的字符所在要贴出vc代码看看
      

  4.   

    还有一个问题当我关闭程序时又出问题了,错误如下:
    PProject Project1.exe raised exception class EInvalidPointer with message'Invalid pointer operation' Process stopped.Use Step or Run to continue.
    这好象是指针问题,可我没有定义指针啊
      

  5.   

    dispose (Message.LParam);
    showmessage('ok');大概如此试下,不是很确定
      

  6.   

    问题不在Delphi代码,我试过写一个VC的动态库发一个NULL结尾字符串没问题的,不过有一点要声明,VC的动态库不要使用局部变量,要使用堆变量,并且不要释放内存,让调用者释放。
      

  7.   

    靠, Type
      TTestVdDLLForm=Class(TForm)
      private
        //以下面必须定义
        procedure WMBarIcon(var Msg:TMessage); message WMBarIcon;
      end;procedure TTestVcDLLForm.WMBarIcon(var Msg:TMessage);
    begin
      ShowMessage(IntToStr(Msg.lParam));
    end;
      

  8.   

    //以下是我的VC测试代码
    const MYMSG_SENDSTR=WM_USER+1981;
    extern "C" __declspec(dllexport) void WINAPI SendMsgTo(HWND wnd)
    {
    char * a=new char[20];
    a="quanqi";
    SendMessage(wnd,MYMSG_SENDSTR,(int)a,0);
    }
    //以下是我的Delphi测试代码
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    const
      MYMSG_SENDMSG=WM_USER+1981;
    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        procedure VCMSG(var Msg:TMessage);message MYMSG_SENDMSG;
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    procedure SendMsgTo(wnd:THandle);stdcall;external 'pro3.dll' index 1;procedure TForm1.Button1Click(Sender: TObject);
    begin
      SendMsgTo(Handle);
    end;procedure TForm1.VCMSG(var Msg: TMessage);
    begin
      ShowMessage(PChar(Pointer(Msg.WParam)));
    end;end.