views:

169

answers:

1

Hello. 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

+1  A: 

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

Robert Love
thanks i hope this one helps: http://blog.virtec.org/2008/07/the-mysteries-of-psafearray/anyway one up for now
Sebastian Godelet
@Robert, I wonder if its generally possible to pass structs (what GUIDs are in the end anyways), even using a variant
Sebastian Godelet
You can store a list of pointers to the TGuids. Don't know if that will work for you situation.
Robert Love
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 Godelet
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 Godelet