如何将Delphi Stream传递给c / c ++ DLL [英] How to pass a Delphi Stream to a c/c++ DLL

查看:265
本文介绍了如何将Delphi Stream传递给c / c ++ DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以将Delphi流(TStream descendant)传递给用c / c ++编写的DLL吗? DLL将以Microsoft c / c ++编写。如果这是不可能的,我们如何使用C ++ Builder来创建DLL?或者,有没有可以在Microsoft C / C ++和Delphi之间共享的Stream(FIFO)类?

Is it possible to pass a Delphi stream (TStream descendant) to a DLL written in c/c++? DLL will be written in Microsoft c/c++. If that is not possible, how about if we use C++ Builder to create the DLL? Alternatively, are there any Stream (FIFO) classes which can be shared between Microsoft C/C++ and Delphi?

谢谢!

推荐答案

您可以使用 IStream TStreamAdapter 。这是一个快速的例子(在D2007和XE2中测试):

You can do this using IStream and TStreamAdapter. Here's a quick example (tested in D2007 and XE2):

uses
  ActiveX;

procedure TForm1.DoSomething;
var
  MemStream: TMemoryStream;
  ExchangeStream: IStream;
begin
  MemStream := TMemoryFile.Create;
  try
    MemStream.LoadFromFile('C:\Test\SomeFile.txt');
    MemStream.Position := 0;
    ExchangeStream := TStreamAdapter.Create(MemStream) as IStream;
    // Pass ExchangeStream to C++ DLL here, and do whatever else
  finally
    MemStream.Free;
  end;
end;

以防万一,如果你需要去另一种方式(收到一个来自C / C ++的IStream ),您可以使用 TOleStream IStream 获取到Delphi TStream

Just in case, if you need to go the other way (receiving an IStream from C/C++), you can use TOleStream to get from that IStream to a Delphi TStream.

这篇关于如何将Delphi Stream传递给c / c ++ DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆