关于aumation的一点疑惑

borz 2002-04-07 09:48:43
MSDN上说,如果你要享受automation带来的乐趣的话,你必须使用autionmation所能兼容的参数类型。现在应用要我实现类似这样的东东
ICardInfo
{
get_CardName()..
set_CardNmae()
....
....
} //里面全是一些属性操作

而"我希望"有一个
ICardInfosManager
{
CreateCardInfo(ICardInfo **ci);
...
...
}

很显然我如果放弃automation的想法,绝对可行,但如果我一定要用automation那
似乎只有自己将CardInfo定义成UDT,通过SAFEARRAY或者VARIANT来传递,然后通过IRecordInfo来访问,

由此我有个疑问,ADO里面的对象是如何实现的(顺便问一下:它应该是个应用到Automaion的一个例子吧),比如

con.Provider = "MSDAOSP"
con.Properties("Data Source") = "SampleOSP_VB.MyDataSource"
con.Open
rs.Open " C:\Oledbsdk\Osptk\Samples\Customer.txt", con

很显然,RecordSet在调用Open时传递了一个Connection对象con进去了,
而Connection又不是Automation所兼容的类型,小弟初识COM/ATL,不解其中
含义,请哪个讲讲

另外小弟还有一个问题
我在项目的idl里加了一段
typedef [uuid(6A8EBB1A-57ED-48f4-BE7B-AE74C5206D5A)] struct tag_CardInfo{
short id;
} CardInfo;
然后在下面的interface的method定义中

interface ICardInfosManager : IDispatch
{
[id(1), helpstring("method CreateCardInfo")] HRESULT CreateCardInfo([out]SAFEARRAY(CardInfo) *psa);
};

在编译时出现了下面的问题
E:\Works\BT\V1\client\test\2\2.idl(60) : warning MIDL2039 : interface does not conform to [oleautomation] attribute : [ Parameter 'psa' of Procedure 'CreateCardInfo' ( Interface 'ICardInfosManager' ) ]

midl\oleaut32.dll : warning MIDL2368 : error generating type library, ignored : Could not set UUID : tag_CardInfo

这又是为何?

烦劳高手指点迷津
...全文
127 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
netter_bj 2002-04-10
  • 打赏
  • 举报
回复
我也遇到这样的问题,,HELP ME!
fantong 2002-04-09
  • 打赏
  • 举报
回复
to: borz (习波)
最近比较忙、比较烦,每天上来一观,只要没人打广告没反动言论就撤了
不过本版还比较好,没那么多无聊的人
fantong 2002-04-09
  • 打赏
  • 举报
回复
可以分成两种情况来考虑
1。你传的东西不夸进程,这就好办了,你随便传什么东西都可以,就算你传void * 指针也无所谓,传自己写的COM对象指针也不用考虑太多,能编译过去就OK,怎么骗过midl编译器上面有人说了,或者你看看现在挂的公告
2.要传跨进程或机器,最好是把对象整个传过去,可以考虑支持IStream,用流整个打包传过去,修改完成后再整个传过来
laughsky 2002-04-09
  • 打赏
  • 举报
回复
在IDL文件中定义你的结构体
typedef
[
uuid(AB5526D5-736A-4a3e-BB87-35450C1FC7DF),
version(1.0),

helpstring("存储组信息的数据结构")
]
struct
{
CHAR szGroupName[MAX_NAME_LEN];
CHAR szGroupComment[MAX_COMMENT_LEN];
CHAR szCreatorID[MAX_ID_LEN];
CHAR szCreateTime[MAX_FULL_TIME_LEN];
CHAR szChangeID[MAX_ID_LEN];
CHAR szChangeTime[MAX_FULL_TIME_LEN];
INT nGroupNo;
}GroupInfo;

如果接口在编译时出现warning ,则不必理会,因为这是编译器的bug
borz 2002-04-09
  • 打赏
  • 举报
回复
void write叉()
{
cout << '一撇' << '一点' <<endl;
}
void write爽()
{
cout << "写爽字" <<endl
cout << '一横' << '一撇' << '一捺' <<endl;
for(int i=0;i<4;i++)
{
write叉();
}
}
void run()
{
while(1,write爽()){;}
}

void main()
{
run();
}
感谢感谢,,,加分了

小弟的qq是 57226475,大侠如果不嫌弃的话,就把我加为好友吧
fantong 2002-04-09
  • 打赏
  • 举报
回复
再给你个例子吧,这是我写的
FAINT,为了20分这么费劲,强烈要求加到2000分:)
有些废话,无关大局,注意偶就能在DRClient中使用CommArea指针做参数
注意此方法只能在同一个进程中用,因为我传的是指针
还有注意如果不在同一IDL中的话,看公告上的那个recordset如何导入的
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(C5C91DEF-91B0-494B-9B4F-E4EC385FFA7D),
dual,
helpstring("ICommArea Interface"),
pointer_default(unique)
]
interface ICommArea : IDispatch
{
[id(1), helpstring("method SetValue")] HRESULT SetValue([in]BSTR Key,[in]BSTR Value);
[id(2), helpstring("method GetValue")] HRESULT GetValue([in]BSTR Key,[out,retval]BSTR * Value);
[id(3), helpstring("method DelValue")] HRESULT DelValue([in]BSTR Key);
[id(4), helpstring("method SetCommArea")] HRESULT SetCommArea([in]BSTR AreaString);
[id(5), helpstring("method GetAreaString")] HRESULT GetAreaString([out,retval]BSTR * AreaString);
[id(6), helpstring("method BeginWrite")] HRESULT BeginWrite();
[id(7), helpstring("method BeginRead")] HRESULT BeginRead();
[id(8), helpstring("method GetCommLen")] HRESULT GetCommLen([out,retval]long * Len);

};
[
object,
uuid(41E61164-94DA-4909-B512-073457937EFE),
dual,
helpstring("IDRClient Interface"),
pointer_default(unique)
]
interface IDRClient : IDispatch
{
[propget, id(1), helpstring("property ServiceID")] HRESULT ServiceID([out, retval] BSTR *pVal);
[propput, id(1), helpstring("property ServiceID")] HRESULT ServiceID([in] BSTR newVal);
[id(2), helpstring("method CallDRServer")] HRESULT CallDRServer([in,out]ICommArea **Area,[out,retval]long *nRet);
[id(3), helpstring("method ClearSession")] HRESULT ClearSession();
[id(4), helpstring("method EditConfig")] HRESULT EditConfig([out,retval]VARIANT_BOOL *bRet);
[id(5), helpstring("method GetAllServiceName")] HRESULT GetAllServiceName([in]ICommArea *pArea,[out,retval]VARIANT_BOOL *bRet);

};

[
uuid(474B6631-4682-46BB-A5EB-A9E0D9B0D71D),
version(1.0),
helpstring("DRClientLib2 1.0 Type Library")
]
library DRCLIENTLIB2Lib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");

[
uuid(9E3A4B9D-6D0A-4AB6-9530-E5FAFCAB0D50),
helpstring("CommArea Class")
]
coclass CommArea
{
[default] interface ICommArea;
};
[
uuid(EC64A45E-9D89-4219-A476-FCA94656CD57),
helpstring("_IDRClientEvents Interface")
]
dispinterface _IDRClientEvents
{
properties:
methods:
[id(1), helpstring("method OnCallServerStart")] HRESULT OnCallServerStart([in]BSTR ServerIP,[in]long ServerPort);
[id(2), helpstring("method OnCallServerEnd")] HRESULT OnCallServerEnd([in]long Result,[in]BSTR RESPCODE,[in]BSTR DESCRIPT);
};

[
uuid(4E2BAECD-AB06-4D02-A16C-B680144E2D33),
helpstring("DRClient Class")
]
coclass DRClient
{
[default] interface IDRClient;
[default, source] dispinterface _IDRClientEvents;
};
};
fantong 2002-04-09
  • 打赏
  • 举报
回复
兄台,好像你的idl中并没有导入你的MyRecord定义啊,
还有,你不是真的永了
struct
{
CHAR szGroupName[MAX_NAME_LEN];
CHAR szGroupComment[MAX_COMMENT_LEN];
CHAR szCreatorID[MAX_ID_LEN];
CHAR szCreateTime[MAX_FULL_TIME_LEN];
CHAR szChangeID[MAX_ID_LEN];
CHAR szChangeTime[MAX_FULL_TIME_LEN];
INT nGroupNo;
}GroupInfo;
这种定义吧

你要1.手动写一个MyRecord的COM对象,在里面实现你要的属性
2.在要传递MyRecord指针的IDL中导入MyRecord的IDL定义

我竟然看到在IDL中有用CHAR的,赫赫,真的出了一身汗
borz 2002-04-09
  • 打赏
  • 举报
回复
小弟初识COM/ATL,我这里没有一本关于ATL的书,所有的一切资料均来源于MSDN 98,上面的大侠能否介绍我几本讲ATL的电子书,不甚感激,
再则,我发现本论坛上很多人象我一样对Automation之流不能很好的理解,即使已有的结贴好象都不能切中要害(也许是我天天笨),希望大侠们能专门发一篇贴子,以自己的语言总结一下Automation,特别是自定义参数之类

谢了
borz 2002-04-09
  • 打赏
  • 举报
回复
感觉上面两位,我按 程序应笑我 的方法改了Idl,把该interface的定义放在library段中,如下
[
object,
uuid(F2056B4F-3C63-43F8-AD3E-39DDD20D82BF),
dual,
helpstring("ICreator Interface"),
pointer_default(unique)
]
interface ICreator : IDispatch
{
typedef
[
uuid(AB5526D5-736A-4a3e-BB87-35450C1FC7DF),
version(1.0),

helpstring("存储组信息的数据结构")
]
struct
{
short shortval;
}MyRecord;
[id(2), helpstring("method GetRS")] HRESULT GetRS([in]BSTR query,[out]_Recordset **ppRs);
[id(3), helpstring("method CreateRecord")] HRESULT CreateRecord([out,retval] MyRecord **r);
[id(4), helpstring("method MsgBox")] HRESULT MsgBox();
};

编译果然又出现警告信息
E:\Works\BT\V1\client\test\2\2.idl(110) : warning MIDL2039 : interface does not conform to [oleautomation] attribute : [ Parameter 'r' of Procedure 'CreateRecord' ( Interface 'ICreator' ) ]
midl\oleaut32.dll : warning MIDL2368 : error generating type library, ignored : Could not set UUID : __MIDL_ICreator_0001

不管他了,在vb中写代码测试

Private Sub Command1_Click()
Set creator = CreateObject("Creator.Creator.1")
creator.MsgBox
creator.CreateRecord //3
End Sub

当程序运行到第三行时,出现vb runtime error 458
Variable uses an Automation type not supported in VB



如何是好?
borz 2002-04-07
  • 打赏
  • 举报
回复
[uuid(6A8EBB1A-57ED-48f4-BE7B-AE74C5206D5A)] typedef struct tag_Record{
short grade;
} Record;

这样? 也不行啊
E:\Works\BT\V1\client\test\2\2.idl(60) : warning MIDL2039 : interface does not conform to [oleautomation] attribute : [ Parameter 'psa' of Procedure 'CreateRecord' ( Interface 'ICreator' ) ]
midl\oleaut32.dll : warning MIDL2368 : error generating type library, ignored : Could not set UUID : tag_Record
gxh 2002-04-07
  • 打赏
  • 举报
回复
typedef 放在uuid()後面.

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧