Board index » cppbuilder » Re: How to return a Stream from a DLL

Re: How to return a Stream from a DLL


2008-01-17 07:41:02 AM
cppbuilder112
"Dan" < XXXX@XXXXX.COM >wrote in message
Quote
In a DLL I'm making, I need to return a list of characters of unlimited
size (couple thousand probably). Which should I store the characters in
before returning it, a stream or char* const?

I'm returning this huge long list of chars to Delphi, where I need to be
able to access the chars and put them into a huge grid. The problem is
that when I return the char * const, in Delphi the only way I know of
working with it, is to turn it into a string. That can be a problem since
there's a limit on the string length in Delphi.

So, what should this really long "string" be stored as in C++ while I'm
making it, and does anyone know what format I should return it to the
calling program as (Delphi)?

- Dan
Ok, so after a bit more thinking I've decided to go with a stream. If I use
a stream, then I can return my entire matrix as a single stream, rather than
calling each row and getting it's values. Now assuming I have a stream
filled with a ton of characters and the occasional "\n" which separates the
rows, what format could I return this to Delphi in?
I am thinking it would be like with strings, I create a buffer in Delphi,
and send it to the C++ DLL, which then would fill the buffer with the stream
that it has created. Although that rests on there being a function that
would convert a stream to a const * char. Is there such a thing? Is there
any good way I can do this?
- Dan
 
 

Re:Re: How to return a Stream from a DLL

"Dan" < XXXX@XXXXX.COM >wrote in message
Quote
"Dan" < XXXX@XXXXX.COM >wrote in message
news:478e91bf$ XXXX@XXXXX.COM ...
>In a DLL I'm making, I need to return a list of characters of unlimited
>size (couple thousand probably). Which should I store the characters in
>before returning it, a stream or char* const?
>
>I'm returning this huge long list of chars to Delphi, where I need to be
>able to access the chars and put them into a huge grid. The problem is
>that when I return the char * const, in Delphi the only way I know of
>working with it, is to turn it into a string. That can be a problem
>since there's a limit on the string length in Delphi.
>
>So, what should this really long "string" be stored as in C++ while I'm
>making it, and does anyone know what format I should return it to the
>calling program as (Delphi)?
>
>- Dan

Ok, so after a bit more thinking I've decided to go with a stream. If I
use a stream, then I can return my entire matrix as a single stream,
rather than calling each row and getting it's values. Now assuming I have
a stream filled with a ton of characters and the occasional "\n" which
separates the rows, what format could I return this to Delphi in?

I am thinking it would be like with strings, I create a buffer in Delphi,
and send it to the C++ DLL, which then would fill the buffer with the
stream that it has created. Although that rests on there being a function
that would convert a stream to a const * char. Is there such a thing? Is
there any good way I can do this?
Sure, you can use a TStringStream and its DataString property, or a
TMemoryStream and its Memory property.
But then again, you still need to give the Delphi app access to this data.
You could probably just return a pointer to a stream and use it directly in
Delphi. For example completely untested -- just ideas):
TStringStream *LocalStream; // must be created and destroyed by the DLL, of
course
TStream *MyDLL_GetSomeData()
{
return LocalStream;
}
In Delphi:
procedure MyProc;
var
pStream : TStream^;
{ I don't remember the Pascal pointer syntax, so this may be wrong }
{ might need to define a type first, but you get the idea }
begin
pStream := MyDLL_GetSomeData();
{ do something with pStream's StringData property }
end;
- Dennis
 

Re:Re: How to return a Stream from a DLL

Hi Dan
Dan says:
Quote

Ok, so after a bit more thinking I've decided to go with a stream. If I use
a stream, then I can return my entire matrix as a single stream, rather than
calling each row and getting it's values. Now assuming I have a stream
filled with a ton of characters and the occasional "\n" which separates the
rows, what format could I return this to Delphi in?

I am thinking it would be like with strings, I create a buffer in Delphi,
and send it to the C++ DLL, which then would fill the buffer with the stream
that it has created. Although that rests on there being a function that
would convert a stream to a const * char. Is there such a thing? Is there
any good way I can do this?
have a look at:
ReadBuffer(void *Buffer, int Count);
or if it is a TMemoryStream You are working with You have
direct acces to the memory by TMemoryStream->Memory just
cast it to (char*) and You can use strcpy, but You would
probably be more safe with ReadBuffer.
Kind regards
Asger
 

{smallsort}