Hello,
I am trying to implement COM object in Delphi. This is test COM object and its main module looks like this:
unit MyCOM;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
Windows, ActiveX, Classes, ComObj, TestCOM_TLB, StdVcl;
type
TMyCOM = class(TAutoObject, IMyCOM)
public
function DoIt: WideString; stdcall;
end;
TMyComObjectFactory = class(TAutoObjectFactory)
protected
function GetProgID: string; override;
end;
const
SValue: WideString = 'It works!';
implementation
uses ComServ;
function TMyCOM.DoIt: WideString; stdcall;
begin
Result := SValue;
end;
{ TMyComObjectFactory }
function TMyComObjectFactory.GetProgID: string;
begin
Result := 'DeNovo.MyCOM';
end;
initialization
TMyComObjectFactory.Create(ComServer, TMyCOM, Class_MyCOM,
ciMultiInstance, tmApartment);
end.
I register this DLL with regsvr32 without problem. Then I try to invoke COM function via the following code in separate application:
procedure TForm1.btnInvokeMyCOMClick(Sender: TObject);
var
MyCOM: Variant;
begin
MyCOM := CreateOleObject('DeNovo.MyCOM');
ShowMessage(MyCOM.DoIt);
end;
I contantly get the memorry access error.
Meanwhile when I am trying to exchange integer data - everything works fine.
Can you give me some clues how to cope with this WideString memory issue?