Re: C# app with COM Interface for array of COM structs
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Tue, 11 Mar 2008 17:21:29 +0100
"Sharon" <SharonG@xxxxxxxxxxxxxxxxx> wrote in message news:EF08A4A2-96A5-4437-BEF8-85F8A59FD21C@xxxxxxxxxxxxxxxx
Hello Experts
I'm exporting COM interface from within my C# application (VS2005 .NET 2.0).
One of my exported function GetROI() return type is a struct defined in a
native COM object.
The method signature is (viewed by the OLE View):
[id(0x60020001)]
HRESULT GetROI(
[in] long partID,
[in] BSTR roiName,
[out, retval] SAFEARRAY(PhysicalLocation_t)* pRetVal);
In the native COM object, the struct is defined as (viewed by the OLE View):
typedef struct tagPhysicalLocation_t {
long ScanLine;
long Pixel;
long Value;
} PhysicalLocation_t;
In the interop of the native COM object, the struct is defined as:
namespace USDALib
{
public struct PhysicalLocation_t
{
public int Pixel;
public int ScanLine;
public int Value;
}
}
This struct is also shown on my C# application by using the OLE View as:
typedef [uuid(7B61D653-82C0-33E9-94AA-913FE5290BC0), version(1.0),
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, USDALib.PhysicalLocation_t)]
struct tagPhysicalLocation_t {
long ScanLine;
long Pixel;
long Value;
} PhysicalLocation_t;
But at the native unmanaged application that invoke this my COM method
GetROI() is crushing with exception when trying to assign the return value to
any kind of variable is end with exception.
What do you mean with any kind of variable? The return type is an array (SAFEARRAY) of strucures, the structures being of type PhysicalLocation_t. This means that you have to declare a variable of type SAFEARRAY at the client side.
It looks like it's impossible to transfer array of structs from my interface
to the native application.
Sure it's possible, but not all kind of native COM clients can handle arrays of user defined types (UDT's), so it's better not to expose such types to COM.
Willy.
.
- References:
- C# app with COM Interface for array of COM structs
- From: Sharon
- C# app with COM Interface for array of COM structs
- Prev by Date: Iterate and List Members of an NT Group with LDAP
- Next by Date: Max length of code snippet?
- Previous by thread: C# app with COM Interface for array of COM structs
- Next by thread: Re: C# app with COM Interface for array of COM structs
- Index(es):
Relevant Pages
|