Re: C# app with COM Interface for array of COM structs

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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

.



Relevant Pages

  • Please confirm my c to c# structs
    ... [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] ... public struct iaxc_ev_levels ... int callNo; /* call number for IAX text */ ... public int callNo; ...
    (microsoft.public.dotnet.framework.interop)
  • Need help using Raw Input under C#
    ... Unfortunately it seems that time has moved on and more and more GPS devices are native "HID" devices connected to a USB port. ... I thought I would try to use GetRawInputDeviceList to get a list of all the RawInput devices and then take each device in the list and call GetRawDeviceInfo with the RIDI_DEVICEINFO flag in order to get the RID_DEVICE_INFO struct populated with the detailed information I need in order to create a proper RAWINPUTDEVICE. ... public int dwProductId; ... GetRawInputDeviceInfo(rid.hDevice, RIDI_DEVICEINFO, IntPtr.Zero, ref pcbSize); ...
    (microsoft.public.dotnet.languages.csharp)
  • DEVMODE and Infragistics
    ... private struct PRINTER_DEFAULTS ... // DEVMODE supporting unions ...
    (microsoft.public.dotnet.framework.interop)
  • Why does my PrinterSettings.GetHdevmode() returns garbage ???
    ... IntPtr pDevMode = GlobalLock; ... // I tried with 3 different printers as default printers and I still get the ... here is the definition of my DEVMODE struct. ... public int dmPelsWidth; ...
    (microsoft.public.dotnet.framework.interop)
  • Why does my PrinterSettings.GetHdevmode() returns garbage ???
    ... IntPtr pDevMode = GlobalLock; ... // I tried with 3 different printers as default printers and I still get the ... here is the definition of my DEVMODE struct. ... public int dmPelsWidth; ...
    (microsoft.public.dotnet.languages.csharp)