Am I calling my interface correctly?
I have the following excerpts from a XXX_TLB.pas file:
unit XXX_TLB;
interface
uses Windows, ActiveX, Classes, Graphics, OleCtrls, StdVCL,
YYY_TLB, ZZZ_TLB, VBA_TLB;
_HPFile = interface(IDispatch)
['{43F0CE3B-54AC-11D3-803C-00104BB6FB94}']
procedure Load(const Path: WideString); safecall;
end;
CoHPFile = class
class function Create: _HPFile;
class function CreateRemote(const MachineName: string): _HPFile;
end;
implementation
uses ComObj;
class function CoHPFile.Create: _HPFile;
begin
Result := CreateComObject(CLASS_HPFile) as _HPFile;
end;
end.
When I execute the following code:
function SomeFunc : Boolean;
var
HPFile : _HPFile;
begin
HPFile := CoHPFile.Create;
try
path := 'c\001.xxx';
HPFile.Load (path);
ShowMessage('Success');
except
One e.exception do
ShowMessage (e.message);
end; //try except
end;
CoHPFile.Create returns a pointer ($XXXXXX) as _HPFile as I would
expect, but calling the load method generates an Access Violation.
I am able to debug the DLL and the EXE at the same time and have found
that control is not leaving the calling function when the AV occurs.
This seems to indicate that the pointer returned by CoHPFile.Create
is not really a valid pointer to an _HPFile interface.
My questions are:
1. Am I calling the method correctly?
2. Am I calling CoHPFile.Create correctly?
3. When I step into COHPFile.Create (f7) CreateComObject
is called, however, the compiler doesn't step into that
function. Is CreateComObject being called from somewhere
else?
4. Is there another step necessary to call methods on the
interface, _HPfile?
5. If I declare HPFile as a variant, the file loads without
incident (almost). In the IDE I get a couple of inexact
result errors and then the Success messagebox. Outside the
IDE, these errors are apparently ignored, because the
Success message comes up without incident.