Hi,
How I can a return "array of byte" from a COM object and put in a Stream? I use a OleVariant variable to get the return. But I can not convert in a string (the return is a XML).
Marcos Douglas

Mailing lists / fpc-pascal / 2011-06
6 messages · 2 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi,
How I can a return "array of byte" from a COM object and put in a Stream? I use a OleVariant variable to get the return. But I can not convert in a string (the return is a XML).
Marcos Douglas
I did using this function:
procedure VariantToStream(const V: OleVariant; const Stream: TStream);
var
P: Pointer;
L: Integer;
begin
Assert(VarType(V) = varByte or varArray);
Assert(VarArrayDimCount(V) = 1);
L := VarArrayHighBound(V, 1) - VarArrayLowBound(V, 1) + 1;
Stream.Size := L;
Stream.Position := 0;
P := VarArrayLock(V);
try
Stream.Write(P^, Stream.Size);
finally
VarArrayUnlock(V);
end;
end;Marcos Douglas
If the Assert(VarType(V) = varByte or varArray); is not raising an error then you are not getting a Safearray. VarArrayLock is for safearrays. If you are getting an array of byte, you should be able to access the bytes as V[i].
Do you have the interface definition for the method returning the "array of byte"?
Ludo
Yes, an array of bytes. I can use V[i].
Do you have the interface definition for the method returning the "array of byte"?
No. This method belongs a COM object. I don't have the definition, just know that is a array of byte.
Marcos Douglas
No. This method belongs a COM object. I don't have the definition, just know that is a array of byte.
Use OleView to get the IDL. It is part of MS platform SDK or can be downloaded separately from MS. Talking to COM objects without having the IDL is, well, "adventuruous".
Ludo
I didn't know about OleView (I will search for that, thanks). Well, the code is working perfectly.
Marcos Douglas