Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-06

Array of byte from a COM object

6 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marcos Douglas

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

Marcos Douglas
to Marcos Douglas
Marcos Douglas wrote 5 lines
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).

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

Ludo Brands
to 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

Show quoted text 45 lines
-----Message d'origine----- De : De la part de Marcos Douglas Envoyé : jeudi 9 juin 2011 17:21 À : FPC-Pascal users discussions Objet : [fpc-pascal] Re: Array of byte from a COM object On Thu, Jun 9, 2011 at 11:26 AM, Marcos Douglas wrote: > > 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). 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 _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Marcos Douglas
to Ludo Brands
Ludo Brands wrote 5 lines
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].

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

Ludo Brands
to 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

Marcos Douglas
to Ludo Brands
Ludo Brands wrote 8 lines
> 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".

I didn't know about OleView (I will search for that, thanks). Well, the code is working perfectly.

Marcos Douglas