How to Use structs in COM interfaces when Automation
compatibility is not an issue?

Answer Posted / krishna akkulu

Structs, also known as User Defined Types (UDTs), can be
used in Automation- compatible interfaces
An Automation- compatible struct may contain only primitive
Automation types as its members.

Nesting structs is not allowed, but VARIANT is allowed thus
enabling nested structs (you can store a struct in a
VARIANT).

In order for a struct to be usable for Automation-
compatible interfaces, the struct must be described in a
type library and it must be declared with its own GUID:

[uuid(21602F40-CC62-11d4-AA2B-00A0CC39CFE0)]
struct MyStruct
{
[helpstring("A long value")]
long nLongValue;

[helpstring("A string")]
BSTR bstrStringValue;
};

// Later in the IDL file
[uuid(...), version(...), helpstring(...)]
library MyLib
{
...
struct MyStruct;
};
For more info see : http://vcfaq.mvps.org/com/4.htm

Is This Answer Correct ?    0 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Once I have developed the com wrapper do I have to still register the com in registry?

839


Which namespace do the classes, allowing you to support COM functionality, are located?

2305


how to call a dll as a COM dll?

895


How to create an instance of the object in COM?

739


Define and explain about COM?

800


Does .net replace com?

719


Can I use com components from .net programs?

788


Is dcom dead?

789


Suppose we have object B and aggregated object C (in- proc server), created by B. Can you access any interface of B from C?

759


What is dcom?

695


How do we create dcom object in vb6?

870


What is reference counting in com?

714


Can I use .net components from com programs?

765


Can you explain what is dcom?

686


What is the use of com component in .net?

757