views:

72

answers:

1

Hi,

I wrote a function in Delphi 2010 COM object. This function will return string using PChar. I tried to use the COM object in C# .net. So, i added the reference to the COM DLL in my C#. NET application.

I found out that the function is not visible in the References explorer list, whereas the other functions which i wrote earlier are available.

I could not figure out the reason for this strange issue. I unregistered and registered the COM object again but still same issue contd?

We faced some issues earlier in using String type. So, we tried pchar.

Sample code in Delphi 2010

function TILCalculation.TestString(out Rslt: PChar): WordBool; Var sRes : String ; begin sRes := 'This is my Test data!!!'; StrPCopy(Rslt,sRes); end;

I tried the following in C# .net Selected References Under WindowsFormApplication Selected Add references and choosen COM tab Selected the COM object.

I noticed that my COM object is visible in the object browser. So, i expanded the object and checked. Alas!!! This function is not visible in C# .net references. All the functions created earlier are visible

Any help would be very much appreciated

Tks in adv Ven

+1  A: 

PChar is not a normal type in COM. Have you tried using WideString instead?

PS: See Rob's suggestion to include some code examples for a better answer.

Lars Truijens
It'll need to be a WideString for any Delphi versions. WideStrings are COM strings, which are not the same as Delphi's **string** type. It's a bad idea to try to pass a Delphi **string** to external code.
Mason Wheeler
@Mason: Thanks. I've updated my answer
Lars Truijens
Tks for the suggestions. i tried passing Widestring and that the issue is solved now.
Great. Glad to be able to help. Here at StackOverflow we appreciate if you reward good answers with an upvote and marking the right answer. Would you please?
Lars Truijens