[
object,
uuid(02422C99-E924-4D06-9695-3771075467EB),
dual,
helpstring("Iyyy Interface"),
pointer_default(unique) -------------????
]
interface Iyyy : IDispatch
{
};

解决方案 »

  1.   

    The default is always overridden when a pointer attribute is supplied. If all pointers are supplied with pointer attributes, the default attribute is ignored.The [pointer_default] attribute is an optional attribute in the IDL file. The [pointer_default] attribute is required only in the interface header when: A parameter with more than one asterisk (*) appears in a function. 
    A structure member or union arm with a pointer declarator does not have a pointer attribute. 
    A function returns a pointer type and does not have a pointer attribute as a function attribute. 
    If the [pointer_default] attribute appears in the interface header and is not required, it is ignored.Example
    [
        uuid(6B29FC40-CA47-1067-B31D-00DD010662DA), 
        version(3.3), 
        pointer_default(unique)

    interface dictionary 
    {
        // Interface definition statements.
    }
      

  2.   

    好久没回答问题了,今天有空,挣点分。
    pointer_default属性只在发生跨进程或跨机器通讯时起作用,这时组件的客户与组件不在同一个地址空间。客户调用组件方法的指针参数时,不能只传指针的值,还要把指针所指向的内容一起传到组件端。如果组件修改了指针所指的内容,则还要把指针所指的内容传回客户端。为了减少在进程边界间或网络(不同机器)间的传输量,COM把指针归纳为三类:
    ref:这类指针总是指向一个合法的已申请来的内存,不能为NULL值;无论在调用前后,指针都指向同一个地址;组件服务器端返回的数据总能写到指针所指的已存在的内存;指针所指的内存不能同时被其它指针和变量引用着。
    unique:它可以是NULL值;它可以在调用前后由NULL变为非NULL,这时系统为你申请内存;它可以在调用前后由非NULL变为NULL,这时客户端必须负责释放原来的内存;指针值在调用前后可以被改变;指针指向的内存不能同时被其它指针和变量引用着;如果指针值非空,则组件方返回的数据写入已经存在的内存。
    pointer:与unique相同,但是指针指向的内存可以被其它指针和变量引用。
    这三种类型一个比一个复杂,对于ref,COM的proxy/stub在marshalling时处理最简单,而pointer最复杂。
    接口中涉及指针的地方都可以设置ref/unique/pointer属性,就象in/out属性一样。如果指针没设置属性,则不同的情况有不同的缺省值:
    方法的参数中的一级指针是ref
    结构体中的指针或指向指针的指针,由pointer_default的设置决定。