用bool而不要用BOOL,bool是8位BOOL是16位long是16位,所以COM会把BOOL看成bool.
在MFC中你可能经常用BOOL,但在COM中最好别用它,BOOL不是COM规范的数据类型.

解决方案 »

  1.   

    BOOL就是int,而在vc中int为32位,在vb中int为16位,long为32位
    所以vc的bool=vc的int=vb的long
    看来programan (金蛇郎君) 还没有把vc和vb融为一体
      

  2.   

    说错了,bool是16位,BOOL是32位,long是32位.别用BOOL,用bool就是了。
      

  3.   

    被fantong(饭桶)搞糊涂了,又说错了,不好意思,bool是8位。
    顺便说一下BOOL和bool的小插曲:
    在VC4.2的时候,bool被typedef成了int,既在win32平台下占32位内存。这显然是太浪费了,一种只有两种状态的变量居然占了32位内存。
    在VC5.0后,bool被定义成了一个字节即8位,制止了这种浪费。但以前用VC4.2时编译成的OBJ文件中bool已经占了32位。为了兼容过去而诞生了BOOL,BOOL等于VC4.2的bool。
    当我们拿到了VC4.2的dll,lib和头文件时,第一件事就是把老的头文件中所有的bool替换成BOOL。
    以下摘自msdn:
    In Visual C++4.2, the Standard C++ header files contained a typedef that equated bool with int. In Visual C++ 5.0 and later, bool is implemented as a built-in type with a size of 1 byte. That means that for Visual C++ 4.2, a call of sizeof(bool) yields 4, while in Visual C++ 5.0 and later, the same call yields 1. This can cause memory corruption problems if you have defined structure members of type bool in Visual C++ 4.2 and are mixing object files (OBJ) and/or DLLs built with the 4.2 and 5.0 or later compilers. 
      

  4.   

    yeah, and if you want to use the component developed by C++ in VB, for boolean data type, you should use VARIANT_BOOL in C++ code. the VARIANT_BOOL is mapped to Boolean in VB.