1
votes

I've used midl to convert a .idl file to a .tlb. When I import this .tlb file into Delphi (XE7), it converts this Write function which is part of

interface IWTSVirtualChannel : IUnknown
...

HRESULT Write(
    [in]            ULONG               cbSize,
    [in, size_is(cbSize)] BYTE          *pBuffer,
    [in]            IUnknown            *pReserved          // must be NULL
    );

into this Delphi code in the _TLB.pas file.

function Write(
 cbSize: LongWord; 
 var pBuffer: Byte; 
 const pReserved: IUnknown): HResult; stdcall;

However the 2nd parameter is clearly incorrect. To my mind it should be something like

 pBuffer : PAnsiChar;

The parameter is a c-type string, passed into the Write to send.

So it seems to me that I should just edit the _TLB.pas file and fix it. There's a couple of other procedures that also have this problem.

But I'm reluctant, as I'd have to redo the edit any time I changed the .idl (hopefully not too often; with the associated hassle of unregistering the .tlb type library before re-importing it) but it doesn't seem right and yet I'm fairly certain that it will not work as is.

What's the best thing I should do? Sticking with C++ is not an option!

1
"To my mind it should be PAnsiChar" => Wrong. COM types are almost always using some types that the framework already knows how to marshal, i.e. BYTE* , BSTR, SAFEARRAY etc. Strings are almost always wid and never plain pointers. (Stick with C++). - Michael Chourdakis
As I understand it a pAnsiChar is effectively a typedef (the Delphi equivalent) for byte *. - David Bolton
Okay,then what's the problem with the automatically generated source? - Michael Chourdakis
"As I understand it a pAnsiChar is effectively a typedef (the Delphi equivalent) for byte *." The Delphi equivalent is PByte. If it had to be PAnsiChar, it should have been coded as char *. - Rudy Velthuis
FWIW, the description of Write says: "A pointer to a buffer on the channel to which to write the data. You can reuse this buffer as soon as the call returns.". ISTM that you are meant to write bytes, not text. The bytes may contain text, of course. - Rudy Velthuis

1 Answers

1
votes

This is a pointer to an array of bytes whose size is provided in the first argument. The correct translation of the second argument is

pBuffer: PByte