DLL中的函数的参数是个结构体,如下:
   typedef struct _tmp {
     int num;
     union {
       int a;
       float b;
       char c[256];
     } value;
  } tmp;我在VB中用type定义的类型来表示,但这个union如何来实现?

解决方案 »

  1.   

    Type _tmp1
     num as integer
     a as integer
    End Type
    Type _tmp2
     num as integer
     b as single
    end typetype _tmp3
     num as integer
     c as string *256
    end type
      

  2.   

    Type _tmp
     num as long'int 相当与long ,都是4个字节
     value(255) as byte '取最大的一个 然后 使用CopyMemory把数组格式化成相应的 类型 
    End Type
      

  3.   

    如果Type中取最大的定义:value(255) as byte , 之后怎样把Integer,String,Single的值赋进去?
    CopyMemory的用法能不能说明一下。
      

  4.   

    type tmp
      num as long
      value(255) as byte
    end typedim a as long
    dim b as single
    dim x as tmp
    ...
    copymemory a,x.value(0),4
    copymemory b,x.value(0),4
      

  5.   

    我试过了,但是报copymemory没有定义的错,该怎样用啊??
      

  6.   

    头上写
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
      

  7.   

    union 是个公用型!!
    union中的成员的首地址相同,占用字节数取成员中占用最大那个!!