U
U
unreturned2010-11-15 10:42:31
Delphi
unreturned, 2010-11-15 10:42:31

Can't return string from COM (Delphi)?

There is a task to write a COM server, it should have a string at the output.
This is what the interface looks like in the _TLB.pas file

// *********************************************************************//<br/>
// Interface: ITMyCOM<br/>
// Flags: (256) OleAutomation<br/>
// GUID: {D94769D0-F4AF-41E9-9111-4D8BC2F42D69}<br/>
// *********************************************************************//<br/>
 ITMyCOM = interface(IUnknown)<br/>
 ['{D94769D0-F4AF-41E9-9111-4D8BC2F42D69}']<br/>
 function MyDrawWS(a: Integer; b: Integer): WideString; stdcall;<br/>
 end;<br/>

This is how it looks like in Windows OS
[<br/>
 odl,<br/>
 uuid(D94769D0-F4AF-41E9-9111-4D8BC2F42D69),<br/>
 version(1.0),<br/>
 helpstring(&quot;Interface for TMyCOM Object&quot;),<br/>
 oleautomation<br/>
]<br/>
interface ITMyCOM : IUnknown {<br/>
 BSTR _stdcall MyDrawWS(<br/>
 [in] long a, <br/>
 [in] long b);<br/>
};<br/>

those. WideString is BSTR, as it should be.
The function itself in the COM server has the following form
function TTMyCOM.MyDrawWS(a, b: Integer): WideString;<br/>
begin<br/>
 Result := WideString(IntToStr(a+b));<br/>
end;<br/>

I call it like this
Edit1.Text := String(MyCOM.MyDrawWS(1,1));<br/>
and get an error like First chance exception at $75A9FBAE. Exception class EAccessViolation with message 'Access violation at address 75A409A4 in module 'RPCRT4.dll'. Read of address FFFFFFF8'. Process Project1.exe (2296)
Returning numbers works fine. I tried to translate from type to type in different ways, but nothing happens.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
Horse, 2010-11-15
@Horse

And you didn't forget to initialize MyCOM and Edit1 for an hour?

M
Majnik, 2010-11-23
@Majnik

Try returning the result via StringToOleStr().

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question