Question

J'ai une interface .NET (4.0) qui est mis en œuvre avec un ServicedComponent COM + classe:

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 Je reçois les signatures suivantes:

procedure MethodRef(var guid : TGuid);
procedure MethodArray(guids : PSafeArray);
procedure MethodCStyle(var guids : ClrGuid /* from mscorlib_TLB */);

Si je l'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;

Enfin j'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 sais sérieusement comment faire Ne ce travail. J'espère que quelqu'un a plus d'expérience avec COM marshalling thx

nœud côté:

J'ai trouvé VT_CLSID que je pense peut être passé pour SafeArrayCreate, mais je ne suis pas sûr de savoir comment poursuivre en justice que

Était-ce utile?
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top