1

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
  • anybody an idea how to pass the C-style Array? Commented May 21, 2010 at 8:05

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

7 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.