本人刚开始学习使用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中这些重复定义的内容删除,重新编译,奇怪的是删除的内容又重新生成。问题依旧谢谢各位高手帮忙
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中这些重复定义的内容删除,重新编译,奇怪的是删除的内容又重新生成。问题依旧谢谢各位高手帮忙
如果是vc6的话
import "oaidl.idl";
import "ocidl.idl";
#include "olectl.h"
////////////////////
//自定义结构 //
////////////////////
typedef enum DataTypeEnum_
{
.....
}DataTypeEnum;
如果是.net下
[export,v1_enum]
typedef enum DataTypeEnum_
{
.....
}DataTypeEnum;
就好了!哈哈
ADOAccessor.idl(80) : error MIDL2009 : undefined symbol : [ Parameter 'type' of Procedure 'AppendParameter' ( Interface 'IADOTier' ) ]
ADOAccessor.idl(80) : warning MIDL2039 : interface does not conform to [oleautomation] attribute : [ Parameter 'type' of Procedure 'AppendParameter' ( Interface 'IADOTier' ) ]
。
//// This file will be processed by the MIDL tool to
// produce the type library (ADOAccessor.tlb) and marshalling code.import "oaidl.idl";
import "ocidl.idl";enum DataTypeEnum
{
adEmpty = 0,
adTinyInt = 16,
adSmallInt = 2,
adInteger = 3,
adBigInt = 20,
adUnsignedTinyInt = 17,
adUnsignedSmallInt = 18,
adUnsignedInt = 19,
adUnsignedBigInt = 21,
adSingle = 4,
adDouble = 5,
adCurrency = 6,
adDecimal = 14,
adNumeric = 131,
adBoolean = 11,
adError = 10,
adUserDefined = 132,
adVariant = 12,
adIDispatch = 9,
adIUnknown = 13,
adGUID = 72,
adDate = 7,
adDBDate = 133,
adDBTime = 134,
adDBTimeStamp = 135,
adBSTR = 8,
adChar = 129,
adVarChar = 200,
adLongVarChar = 201,
adWChar = 130,
adVarWChar = 202,
adLongVarWChar = 203,
adBinary = 128,
adVarBinary = 204,
adLongVarBinary = 205
};enum ParameterDirectionEnum
{
adParamUnknown = 0,
adParamInput = 1,
adParamOutput = 2,
adParamInputOutput = 3,
adParamReturnValue = 4
};
[
object,
uuid(377A70AC-BE30-4B43-82F3-9704F683015A),
dual,
helpstring("IADOTier Interface"),
pointer_default(unique)
]interface IADOTier : IDispatch
{
[id(1), helpstring("method Open")] HRESULT Open([in] BSTR source, [in] BSTR user, [in] BSTR pwd);
[id(2), helpstring("method OpenRecordset")] HRESULT OpenRecordset([in] VARIANT query);
[id(3), helpstring("method CloseRecordset")] HRESULT CloseRecordset(void);
[id(4), helpstring("method ExecuteConnection")] HRESULT ExecuteConnection([in] BSTR query, [in] VARIANT_BOOL bChangeRec);
[id(5), helpstring("method ExecuteCommand")] HRESULT ExecuteCommand([in] VARIANT_BOOL bStoredProcedure, [in] VARIANT_BOOL bChangeRec);
[propget, id(6), helpstring("property CommandText")] HRESULT CommandText([out, retval] BSTR *pVal);
[propput, id(6), helpstring("property CommandText")] HRESULT CommandText([in] BSTR newVal);
[id(7), helpstring("method AppendParameter")] HRESULT AppendParameter([in] enum DataTypeEnum type, [in] VARIANT value, [in] enum ParameterDirectionEnum where, [in] long size);
[id(8), helpstring("method Update")] HRESULT Update();
[id(9), helpstring("method Delete")] HRESULT Delete();
[propget, id(10), helpstring("property Field")] HRESULT Field([in] VARIANT idx, [out, retval] VARIANT *pVal);
[propput, id(10), helpstring("property Field")] HRESULT Field([in] VARIANT idx, [in] VARIANT newVal);
[propget, id(11), helpstring("property FieldCount")] HRESULT FieldCount([out, retval] long *pVal);
[propput, id(11), helpstring("property FieldCount")] HRESULT FieldCount([in] long newVal);
[id(12), helpstring("method Close")] HRESULT Close();
[id(13), helpstring("method First")] HRESULT First();
[id(14), helpstring("method Next")] HRESULT Next();
[id(15), helpstring("method Last")] HRESULT Last();
[id(16), helpstring("method Prev")] HRESULT Prev();
[propget, id(17), helpstring("property EOF")] HRESULT EOF([out, retval] VARIANT_BOOL *pVal);
[propget, id(18), helpstring("property BOF")] HRESULT BOF([out, retval] VARIANT_BOOL *pVal);
[id(19), helpstring("method ParamQuery")] HRESULT ParamQuery([in] BSTR query, [in] long idx1, [in] BSTR idx2, [in] BSTR idx3);
[id(20), helpstring("method CallStoredProc")] HRESULT CallStoredProc([in] long idx1, [in] BSTR idx2, [in] BSTR idx3);
[propput, id(21), helpstring("property StoredProc")] HRESULT StoredProc([in] BSTR newVal);
[id(22), helpstring("method ChangeParameter")] HRESULT ChangeParameter([in] long idx, [in] enum DataTypeEnum type, [in] VARIANT value, [in] enum ParameterDirectionEnum where, [in] long size);
[id(23), helpstring("method Requery")] HRESULT Requery();
[id(24), helpstring("method ADORelease")] HRESULT ADORelease();
[propget, id(25), helpstring("property Empty")] HRESULT Empty([out, retval] VARIANT_BOOL *pVal);
}; [
uuid(B62083EC-55E2-4A2E-AE00-494872E8880A),
version(1.0),
helpstring("ADOAccessor 1.0 Type Library")
]
library ADOACCESSORLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb"); [
uuid(DD964E96-CD72-4834-BB33-5476D8059D53),
helpstring("ADOTier Class")
]
coclass ADOTier
{
[default] interface IADOTier;
};
};
在你的客户端程序(调用ADOAccessor的程序)上试着用using namespace ADOAccessor
doaccessor.tli(56) : error C2511: 'AppendParameter' : overloaded member function 'long (enum ADOAccessor::DataTypeEnum,const class _variant_t &,enum ADOAccessor::ParameterDirectionEnum,long)'
not found in 'ADOAccessor::IADOTier'adoaccessor.tli(160) : error C2511: 'ChangeParameter' : overloaded member function 'long (long,enum ADOAccessor::DataTypeEnum,const class _variant_t &,enum ADOAccessor::ParameterDirectionEnum,l
ong)' not found in 'ADOAccessor::IADOTier'好像使用了这两种enum type 的methord都会产生error c2511错误!
#import "..\ADOAccessor.tlb" no_namespace rename( "DataTypeEnum", "DataTypeEnum1" ) rename( "ParameterDirectionEnum", "ParameterDirectionEnum1" )
// 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;
};
};
我的控件中一直都这么用!我的项目已经交了!哈哈!很简单的!