Issues passing data from DLL to Application

前端 未结 3 1235
我寻月下人不归
我寻月下人不归 2021-02-10 14:35

I\'m a bit puzzled as to how Pointers should be properly used in my scenario. I have a DLL with some embedded resources in it. I expose a function in this DLL which passes binar

3条回答
  •  猫巷女王i
    2021-02-10 15:16

    Another way passing the stream from a DLL to the application could be using interfaced streams.

    implementation
    uses MemoryStream_Interface;
    {$R *.dfm}
    
    Type
    TGetStream = Procedure(var iStream:IDelphiStream);stdcall;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
     h:THandle;
     p:TGetStream;
     ms :IDelphiStream;
     j:TJpegImage;
    begin
       ms := TInterfacedMemoryStream.Create;
       h := LoadLibrary('ShowStream.dll');
       if h <> 0 then
          try
          @p := GetProcAddress(h,'GetJpegStream');
          p(ms);
          ms.Position := 0;
          j := TJpegImage.create;
          Image1.Picture.Assign(j);
          j.Free;
          Image1.Picture.Graphic.LoadFromStream(TInterfacedMemoryStream(ms));
          finally
          FreeLibrary(h);
          end;
    end;
    

    The code for IDelphiStream can be found on http://www.delphipraxis.net.
    I won't copy the content of MemoryStream_Interface to this post, because there are no copyright informations on the code from the mentioned page.

提交回复
热议问题