I need to declare Pointer variables in Type Library for an ActiveX
component. But I don't know which data type is corresponding to Pointer in
Type Library. Please give me some suggestions. Thank you very much.
Best regards.
Xiaoming
> I need to declare Pointer variables in Type Library for
> an ActiveX component.
Why? Untyped pointers are safe in ActiveX. What are you trying to
accomplish exactly?
> But I don't know which data type is corresponding to
> Pointer in Type Library.
void*
Gambit
> Why? Untyped pointers are safe in ActiveX. What are you trying to
> accomplish exactly?
One of my friend asked me to encapsulate component MCDBurner in ActiveX.
In this component, it has the following method:
function InsertMemoryFile(DestinationPath, LongFileName, ShortFileName:
String; Attr: Byte; Memory: Pointer; Size: Cardinal): Integer;
So, I need to declare this method in Type Library, and with which to call
the original method.
That's why I need to declare Pointer variable (actually Pointer
parameter) in Type Library.
May thanks for your help.
Best regards.
Xiaoming
> void*
I can not specify void* as the data type in Type Library. Give me some
suggestions, please. Thank you very much.
Best regards.
Xiaoming
> Untyped pointers are safe in ActiveX.
I meant *unsafe*.
Gambit
> One of my friend asked me to encapsulate component
> MCDBurner in ActiveX. In this component, it has the following
> method:
>
> function InsertMemoryFile(DestinationPath, LongFileName, ShortFileName:
> String; Attr: Byte; Memory: Pointer; Size: Cardinal): Integer;
>
> So, I need to declare this method in Type Library, and with
> which to call the original method.
I suggest you implement your ActiveX object to accept an IStream as input
instead of trying to use a raw memory pointer (which you can't do in ActiveX
anyway). The VCL has a TStreamAdapter class available that exposes IStream
access to a TStream. Your friend can load his data into any TStream he
wants, such as a TMemoryStream or TFileStream, then use TStreamAdapter to
pass an IStream to your ActiveX, which can extract the raw bytes and pass
them to MCDBurner as needed, ie (untested):
public
function InsertData(DestinationPath, LongFileName, ShortFileName:
WideString; Attr: Byte; Data: IStream): Integer; safecall;
function TMyActiveXObject.InsertData(DestinationPath, LongFileName,
ShortFileName: WideString; Attr: Byte; Data: IStream): Integer; safecall;
var
statstg: TStatStg;
Buf: PByte;
NumRead: ULONG
begin
Data.Stat(statstg, STATFLAG_NONAME);
GetMem(Buf, statstg.cbSize.LowPart);
try
Data.Read(Buf, statstg.cbSize.LowPart, NumRead);
Result := Burner.InsertMemoryFile(DestinationPath, LongFileName,
ShortFileName, Attr, Buf, NumRead);
finally
FreeMem(Buf);
end;
end;
Gambit
Many thanks for your detailed and patient explanations.
Best regards.
Xiaoming