0

I have an .NET (4.0) interface which is implemented with a ServicedComponent COM+ class:

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);
}

Now I used the Delphi 2007 import wizard to import the type library, and as expected I get the following signatures:

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

If i now call the "ref" method like this it works fine:

procedure CallByRef(guid : TGuid);
var
    test : TGuid;
begin
    test := ...
    comRef.MethodRef(guid);
end;

Now I also need the array method

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;

Now lastly i tried with a c array

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;

I seriously dont know how to make this work. I hope someone has more experience with COM marshalling thx

Side node:

I found VT_CLSID which i think can be passed for SafeArrayCreate, but I am not sure how to sue that

Sebastian
  • 6,293
  • 6
  • 34
  • 47

1 Answers1

1

I have never tried what you need but a quick search found the following articles:

maf-soft
  • 2,335
  • 3
  • 26
  • 49
Robert Love
  • 12,447
  • 2
  • 48
  • 80
  • thanks i hope this one helps: http://blog.virtec.org/2008/07/the-mysteries-of-psafearray/ anyway one up for now – Sebastian May 21 '10 at 05:52
  • I wonder if its generally possible to pass structs (what GUIDs are in the end anyways), even using a variant – Sebastian May 21 '10 at 08:08
  • You can store a list of pointers to the TGuids. Don't know if that will work for you situation. – Robert Love May 21 '10 at 14:01
  • I found that SafeArrayCreateVector(VT_CLSID, 0, count) works, and using SafeArrayPutElement(psa, indexvar, varname) but i cannot verify, as there is another problem with my system, will post back – Sebastian May 22 '10 at 08:35
  • how would i pass a list to a COM server? im not sure that is defined... a i forgot to mention, the COM server is IN_PROC – Sebastian May 22 '10 at 08:48
  • All 3 links are not valid anymore. That's why an answer should not consist of just links. I fixed the 3rd link by web.archive.org – maf-soft Jan 12 '21 at 09:52