我有几个程序在使用msxml3.dll时在一些机器上能编译,但在另一台机器上能编译的问题,总是出现名字空间问题。
如下我在一个Com组件中要用到一个IXMLDOMDocument接口指针为参数的方法。于是我在IDL文件中加入一个方法,并导入msxml3.dll,内容如下:
import "oaidl.idl";
//import "ocidl.idl";[
uuid(52A59983-A57D-468D-96BC-B8C2468F21A3),
version(1.0),
helpstring("curInfo 1.0 Type Library")
]
library CURINFOLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
importlib("msxml3.dll");
[
object,
uuid(E0BBABFB-3672-45D3-9824-D3FA7F801092),
dual,
helpstring("ICurrentInfo Interface"),
pointer_default(unique)
]
interface ICurrentInfo : IDispatch
{
[id(1), helpstring("method getCurrentInfo")] HRESULT getCurrentInfo([in]IUnknown* pUnk,[out,retval]IXMLDOMDocument** pXMLDoc);
}; [
uuid(54BD61C8-2C41-4AA1-AE39-1EEA99CF86FA),
helpstring("CurrentInfo Class")
]
coclass CurrentInfo
{
[default] interface ICurrentInfo;
};
};另外在工程的stdaf.h文件中同时导入msxml3.dll并使用名字空间MSXML2内容如下:
#include <afxwin.h>
#include <afxdisp.h>#include <atlbase.h>
//You may derive a class from CComModule and use it if you want to override
//something, but do not change the name of _Module
extern CComModule _Module;
#include <atlcom.h>
#include <msxml.h>
#import "msxml3.dll" 
using namespace MSXML2;编译时出现错误:
D:\ATPATH Automation Server\Update\Application Designer\Processinfo\curInfo.h(82) : error C2872: 'IXMLDOMDocument' : ambiguous symbol
D:\ATPATH Automation Server\Update\Application Designer\Processinfo\curInfo.h(186) : error C2872: 'IXMLDOMDocument' : ambiguous symbol
D:\ATPATH Automation Server\Update\Application Designer\Processinfo\CurrentInfo.h(61) : error C2872: 'IXMLDOMDocument' : ambiguous symbol
D:\ATPATH Automation Server\Update\Application Designer\Processinfo\CurrentInfo.h(65) : error C2872: 
......其中curInfo.h为编译时生成的头文件。我在其它地方还可以把名字空间加在IXMLDOMDocument前面如:MSXML2::IXMLDOMDocument,但是在接口定义文件中时却不知如何使用名字空间,请指教。另外请分析为何在一些机器上能编译通过但在另一些机器上不能通过。