 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Fernanda Guest
|
Posted: Wed Oct 15, 2003 8:44 pm Post subject: Using array of objects in COM DLL |
|
|
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
|
Posted: Mon Oct 20, 2003 8:39 am Post subject: Re: Using array of objects in COM DLL |
|
|
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 |
|
 |
|
|
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
|
|