J'ai un .NET (4.0) interface qui est mis en œuvre avec un ServicedComponent
COM + classe:Comment appeler une méthode .NET COM avec un tableau de Delphi en utilisant PSafeArray?
interface DotNetIface
{
void MethodRef(var System.Guid guid);
void MethodArray(System.Guid[] guids, params object[] parameters);
void MethodCStyle([MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.Struct, SizeConst=5)]System.Guid[] guids);
}
Maintenant, je l'assistant d'importation Delphi 2007 pour importer la bibliothèque de types, et comme prévu j'obtenir les signatures suivantes :
procedure MethodRef(var guid : TGuid);
procedure MethodArray(guids : PSafeArray);
procedure MethodCStyle(var guids : ClrGuid /* from mscorlib_TLB */);
Si j'appelle maintenant la méthode "ref" comme cela, il fonctionne très bien:
procedure CallByRef(guid : TGuid);
var
test : TGuid;
begin
test := ...
comRef.MethodRef(guid);
end;
Maintenant, je dois aussi la méthode de tableau
procedure CallArray();
var
localGuid : TGuid;
arrayVariant : OleVariant;
begin
arrayVariant := VarArrayCreate([0,4], varVariant /* dont know here */);
arrayVariant[0] := localGuid; /* compile error, cannot cast implicitly */
comRef.MethodArray(PSafeArray(TVarData(arrayVariant.VArray)), /* here this object... PSafeArray works actually*/);
end;
Maintenant enfin je l'ai essayé avec un tableau de c
procedure CallCStyle();
var
localGuid : TGuid;
arrayOfGuid : array [0..4] of ClrGuid;
begin
arrayOfGuid[0] := ClrGuid(localGuid);
comRef.MethodCStyle(PSafeArray(/* now i dont know put it*/, /* here this object... PSafeArray works actually*/);
end;
Je ne sérieusement savoir comment faire ce travail. J'espère que quelqu'un a plus d'expérience avec marshaling COM thx
noeud latéral:
J'ai trouvé VT_CLSID que je pense peut être passé pour SafeArrayCreate, mais je ne suis pas sûr de savoir comment poursuivre cette
personne une idée comment passer le tableau C-style? – Sebastian