BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using array of objects in COM DLL

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi ActiveX Controls Development
View previous topic :: View next topic  
Author Message
Fernanda
Guest





PostPosted: Wed Oct 15, 2003 8:44 pm    Post subject: Using array of objects in COM DLL Reply with quote



Hi,
Im trying to call a property from my COM DLL made in Delphi into a C#
Application. The detail is that this property is an array of objects. It's
defined in Delphi's type library like:


Attributes - Name: Vetor
- Type: SAFEARRAY(IUnknown)
Parameters - Return Type: HRESULT
- Type: SAFEARRAY(IUnknown)*
- Modifier: [out, retval]


Delphi's function to get this property is described as:

function TAtivos.Get_Vetor(out Value: PSafeArray): HResult;
var
i: Integer;
ArrayBounds: TSafeArrayBound;
ArrayData: Pointer;
begin
ArrayBounds.lLbound := 0;
ArrayBounds.cElements := FArraySize; //............ where FArraySize is
an integer property in class
Value := SafeArrayCreate (varUnknown, 1, ArrayBounds);
if SafeArrayAccessData (Value, ArrayData) = S_OK then begin
for i:=0 to 4 do
Vetor(ArrayData)[i] := FVetAtivo[i]; //....... array inicialized
with the objects which I want to export
SafeArrayUnaccessData (Value);
end;
Result := S_OK;
end;

I tested if Vetor was receiving data in function above and it's ok but I get
an NullReferenceException in C# application when function Get_Vetor tries to
return Value.

Is there any good sould to help me ? ;-)

Fernanda Menks


Back to top
krisztian pinter
Guest





PostPosted: Mon Oct 20, 2003 8:39 am    Post subject: Re: Using array of objects in COM DLL Reply with quote





hey, I did once stuck with safe arrays, and i'm still don't familiar with these animals, but i've found a very wierd solution.

just use a variant array, and then cast it's VArray member to PSafeArray

Value := PSafeArray(TVarData(YourArray).VArray);

i don't have the faintest clue why does it work, but it did for me.


"Fernanda" <fernanda (AT) luz-ef (DOT) com> wrote:
Quote:
Hi,
Im trying to call a property from my COM DLL made in Delphi into a C#
Application. The detail is that this property is an array of objects. It's
defined in Delphi's type library like:


Attributes - Name: Vetor
- Type: SAFEARRAY(IUnknown)
Parameters - Return Type: HRESULT
- Type: SAFEARRAY(IUnknown)*
- Modifier: [out, retval]


Delphi's function to get this property is described as:

function TAtivos.Get_Vetor(out Value: PSafeArray): HResult;
var
i: Integer;
ArrayBounds: TSafeArrayBound;
ArrayData: Pointer;
begin
ArrayBounds.lLbound := 0;
ArrayBounds.cElements := FArraySize; //............ where FArraySize is
an integer property in class
Value := SafeArrayCreate (varUnknown, 1, ArrayBounds);
if SafeArrayAccessData (Value, ArrayData) = S_OK then begin
for i:=0 to 4 do
Vetor(ArrayData)[i] := FVetAtivo[i]; //....... array inicialized
with the objects which I want to export
SafeArrayUnaccessData (Value);
end;
Result := S_OK;
end;

I tested if Vetor was receiving data in function above and it's ok but I get
an NullReferenceException in C# application when function Get_Vetor tries to
return Value.

Is there any good sould to help me ? ;-)

Fernanda Menks




Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi ActiveX Controls Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.