调用EXCEL的COM:
在stdafx.h里添加
#include <ole2.h>
#include <stdio.h>
#pragma warning (disable:4146)
#pragma warning (disable:4192)
#pragma warning (disable:4049)#import "d:\Program Files\Microsoft Office\Office\MSO9.dll"
#import "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB" no_namespace 
//#import "d:\Program Files\Microsoft Office\Office\MSWORD9.OLB" rename("ExitWindows","_ExitWindows")
#import "d:\Program Files\Microsoft Office\Office\excel9.olb" rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") \
         rename("DocumentProperties", "DocumentPropertiesXL") exclude("IFont","IPicture")调用ADO:
在MYVIEW里添加
#import "C:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","ADOEOF")程序出现很多错误;
Compiling...
DEMOView.cpp
e:\myproject\demo\debug\msado15.tlh(26) : error C2367: 'Properties' : redefinition; different uuid specifiers
        e:\myproject\demo\debug\vbe6ext.tlh(92) : see declaration of 'Properties'
e:\myproject\demo\debug\msado15.tlh(28) : error C2367: 'Property' : redefinition; different uuid specifiers
        e:\myproject\demo\debug\vbe6ext.tlh(1308) : see declaration of 'Property'
e:\myproject\demo\debug\msado15.tlh(849) : error C2367: 'Properties' : redefinition; different uuid specifiers
        e:\myproject\demo\debug\msado15.tlh(849) : see declaration of 'Properties'
e:\myproject\demo\debug\msado15.tlh(875) : error C2011: 'Property' : 'struct' type redefinition
e:\myproject\demo\debug\msado15.tli(76) : error C2084: function 'class _variant_t __thiscall Property::GetValue(void)' already has a body
e:\myproject\demo\debug\msado15.tli(84) : error C2084: function 'void __thiscall Property::PutValue(const class _variant_t &)' already has a body
e:\myproject\demo\debug\msado15.tli(89) : error C2084: function 'class _bstr_t __thiscall Property::GetName(void)' already has a body
e:\myproject\demo\debug\msado15.tli(96) : error C2039: 'GetType' : is not a member of 'Property'
        e:\myproject\demo\debug\vbe6ext.tlh(1308) : see declaration of 'Property'
e:\myproject\demo\debug\msado15.tli(98) : error C2065: 'get_Type' : undeclared identifier
e:\myproject\demo\debug\msado15.tli(99) : error C2673: 'GetType' : global functions do not have 'this' pointers
e:\myproject\demo\debug\msado15.tli(99) : error C2673: 'GetType' : global functions do not have 'this' pointers
e:\myproject\demo\debug\msado15.tli(103) : error C2039: 'GetAttributes' : is not a member of 'Property'
        e:\myproject\demo\debug\vbe6ext.tlh(1308) : see declaration of 'Property'
e:\myproject\demo\debug\msado15.tli(105) : error C2065: 'get_Attributes' : undeclared identifier
e:\myproject\demo\debug\msado15.tli(106) : error C2673: 'GetAttributes' : global functions do not have 'this' pointers
e:\myproject\demo\debug\msado15.tli(106) : error C2673: 'GetAttributes' : global functions do not have 'this' pointers
e:\myproject\demo\debug\msado15.tli(110) : error C2039: 'PutAttributes' : is not a member of 'Property'
        e:\myproject\demo\debug\vbe6ext.tlh(1308) : see declaration of 'Property'
e:\myproject\demo\debug\msado15.tli(111) : error C2065: 'put_Attributes' : undeclared identifier
e:\myproject\demo\debug\msado15.tli(112) : error C2673: 'PutAttributes' : global functions do not have 'this' pointers
e:\myproject\demo\debug\msado15.tli(112) : error C2673: 'PutAttributes' : global functions do not have 'this' pointers
Error executing cl.exe.
我该怎么办???

解决方案 »

  1.   

    don't use no_namespace attribute
      

  2.   

    #pragma warning (disable : 4146 4049)#define __OFFICE_XP#ifdef __OFFICE_XP
    #import "E:\Program Files\Common Files\Microsoft Shared\Office10\MSO.DLL" 
    #import "E:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB" \
    rename_namespace("VBIDE")
    #import "E:\Program Files\Microsoft Office\Office10\Excel.EXE" \
    rename("DialogBox", "DialogBoxXL") \
    rename("RGB", "RGBXL") \
    rename("ExitWindows", "ExitWindowsXL") \
    rename("DocumentProperties", "DocumentPropertiesXL") \
    no_auto_exclude
    #import "E:\Program files\Microsoft Office\Office10\MSWORD.OLB" \
    rename("DialogBox", "DialogBoxDoc") \
    rename("RGB", "RGBDoc") \
    rename("ExitWindows", "ExitWindowsDoc") \
    rename("DocumentProperties", "DocumentPropertiesDoc") \
    no_auto_exclude
    #endif#ifdef __OFFICE_2000
    #import "E:\Program Files\Microsoft Office\Office\MSO9.DLL" 
    #import "E:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB" \
    rename_namespace("VBIDE")
    #import "E:\Program Files\Microsoft Office\Office\EXCEL9.OLB" \
    rename("DialogBox", "DialogBoxXL") \
    rename("RGB", "RGBXL") \
    rename("ExitWindows", "ExitWindowsXL") \
    rename("DocumentProperties", "DocumentPropertiesXL") \
    no_auto_exclude
    #import "E:\Program files\Microsoft Office\Office\MSWORD9.OLB" \
    rename("DialogBox", "DialogBoxDoc") \
    rename("RGB", "RGBDoc") \
    rename("ExitWindows", "ExitWindowsDoc") \
    rename("DocumentProperties", "DocumentPropertiesDoc") \
    no_auto_exclude
    #endif#ifdef __OFFICE_97
    #define IMPATTRS rename("DocumentProperties", "DocProps")
    #import "mso97.dll" IMPATTRS
    #import "vbeext1.olb" rename_namespace("VBIDE")
    #import "excel8.olb" IMPATTRS rename("DialogBox", "DialogBoxXL") \
    rename("RGB", "RGBXL") \
    rename("ExitWindows", "ExitWindowsXL") \
    rename("DocumentProperties", "DocumentPropertiesXL") \
    rename("_CommandBars", "CommandBarsXL") \
    no_auto_exclude
    #import "msword8.olb" rename("DialogBox","dialogBoxDOC") \
    rename("RGB","RGBDOC") no_auto_exclude \
    rename("ExitWindows","WordExitWindows") no_auto_exclude
    #endif#import "msado21.tlb" rename("EOF", "adoEOF")