描述:
本人刚开始学习使用ATL制作ADO组件,遇到以下的怪问题:
1。建立ADOAccessor工程
2。#import "d:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
3.按照书上说的“为了便于编写代码,我在ADOAccessor.idl文件的头部添加了:
enum DataTypeEnum{....}
enum ParameterDirectionEnum{...}
4.添加方法和属性,编译连接通过,创建了ADOAccessor.DLL等文件
5。在同样的工作区中新建工程以进行测试:
在文件中
#import "..\ADOAccessor.tlb" no_namespace rename("EOF", "ADOEOF")
#include <tchar.h>
...
并利用ADOAccessor进行数据库操作,一切正常
但是我新建工作区,并同样重复以下工作
#import "..\ADOAccessor.tlb" no_namespace rename("EOF", "ADOEOF")
#include <tchar.h>
...
并利用ADOAccessor进行数据库操作,在编译时就出现如下问题:
g:\test\debug\adoaccessor.tlh(191) : error C2011: 'DataTypeEnum' : 'enum' type redefinition
g:\test\debug\adoaccessor.tlh(230) : error C2011: 'ParameterDirectionEnum' : 'enum' type redefinition
我每次把adoaccessor.tlh中这些重复定义的内容删除,重新编译,奇怪的是删除的内容又重新生成。问题依旧。。。
谢谢各位高手帮忙
解决方案1:
你的enum做参数的时候写得不对!给你一个例子!
// ZBase6.idl : IDL source for ZBase6.dll
//
// This file will be processed by the MIDL tool to
// produce the type library (ZBase6.tlb) and marshalling code.
import "oaidl.idl";
import "ocidl.idl";
#include "olectl.h"
////////////////////
//自定义结构 //
////////////////////
typedef enum ZView_
{
VIEW_KIND_NORMAL =0,
VIEW_KIND_FLY =1,
VIEW_KIND_LINE =2
}ZView;
[
object,
uuid(5328DDB8-FFA3-4E25-998B-50683F119A7A),
dual,
helpstring("ISPace6 Interface"),
pointer_default(unique)
]
interface ISPace6 : IDispatch
{
[id(1), helpstring("method SetView")] HRESULT SetView([in]ZView ptr);
[id(2), helpstring("method GetView")] HRESULT GetView([out]ZView* ptr);
}
[
uuid(13878BFE-E2C7-45D1-A201-FF31889E0267),
version(1.0),
helpstring("ZBase6 1.0 Type Library")
]
library ZBASE6Lib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
uuid(868E6B82-EE78-48B0-9F73-736F01908DB1),
helpstring("_ISPace6Events Interface")
]
dispinterface _ISPace6Events
{
properties:
methods:
[id(1), helpstring("method MouseDown")] HRESULT MouseDown(long x,long y);
[id(2), helpstring("method MouseUp")] HRESULT MouseUp(long x,long y);
[id(3), helpstring("method MouseWheel")] HRESULT MouseWheel(long x,long y);
[id(4), helpstring("method OnRender")] HRESULT OnRender();
};
[
uuid(A683E743-1A7E-41AC-98FA-6D23213B7792),
helpstring("SPace6 Class")
]
coclass SPace6
{
[default] interface ISPace6;
[default, source] dispinterface _ISPace6Events;
};
};
我的控件中一直都这么用!我的项目已经交了!哈哈!很简单的!
楼主的错误需要详细查看ADOAccessor.tlb中的内容以确定,不过楼主可以试下下面的方法能不能暂时的排除错误:
#import "..\ADOAccessor.tlb" no_namespace rename( "DataTypeEnum", "DataTypeEnum1" ) rename( "ParameterDirectionEnum", "ParameterDirectionEnum1" )
还用你原来的方式
在你的客户端程序(调用ADOAccessor的程序)上试着用using namespace ADOAccessor
不可能有错的!你怎么写的呢?在vc6还是.net下呢?
解决方案5: 错误的意思ParameterDirectionEnum重定义了,你定义enum时候不能像平常一样定义!在idl中emum有自己的属性,你把它改成:
如果是vc6的话
import "oaidl.idl";
import "ocidl.idl";
#include "olectl.h"
////////////////////
//自定义结构 //
////////////////////
typedef enum DataTypeEnum_
{
.....
}DataTypeEnum;
如果是.net下
[export,v1_enum]
typedef enum DataTypeEnum_
{
.....
}DataTypeEnum;
就好了!哈哈