- UID
- 1
- 积分
- 16111
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-3
- 最后登录
- 1970-1-1
|
发表于 2002-10-27 21:13:41
|
显示全部楼层
关于CAO技术的介绍
最初由 sv300 发布
[B]谢谢楼上几位
这些都是ado方面的例子,有没有cao方面的呢?
我看到cao有些属性和方法,但是不知道怎么在arx 中应用 [/B]
给你贴篇资料,关于CAO技术的介绍:

- [FONT=courier new]
- Samples and documentation for using CAO from VB and Visual LISP are included
- with AutoCAD 2000, but there is no documentation for CAO from C++. However, you
- can access the CAO Object Model in C++ just as any other ActiveX interface. This
- solution contains a simple code sample that illustrates how this can be done.
- CAO is an interface to what were formerly known as ASE links (which still works
- much the same in terms of the AutoCAD drawing database), and it can be used from
- various environments, including C++, VB, VBA and Visual LISP. But it also
- represents the introduction of OLEDB / ADO within AutoCAD and a new terminology
- scheme, so it qualifies as "new technology".
- In AutoCAD 2000 you can currently do more with the C++ ASE API (for instance,
- create Link Templates) than you can with CAO.
- Here's the code sample:
- #include "aced.h"
- #include "migrtion.h"
- #import "e:\\acad2000\\acad.tlb" no_namespace no_ \
- implementation raw_interfaces_only named_guids
- void arxtest()
- {
- IAcadApplication* pAcadApp;
- HRESULT hr = NOERROR;
- CLSID clsid;
- LPUNKNOWN pUnk = NULL;
- LPDISPATCH pDisp = NULL;
- CoInitialize(NULL);
-
- hr = ::CLSIDFromProgID(L"AutoCAD.Application", &clsid);
- if (FAILED(hr))
- {
- ads_alert("Acad.Application is not registered!");
- CoUninitialize();
- return;
- }
- hr = ::GetActiveObject(clsid, NULL, &pUnk);
- if (SUCCEEDED(hr))
- {
- hr = pUnk->QueryInterface(IID_IDispatch, (LPVOID*)&pDisp);
- pUnk->Release();
- if (FAILED(hr))
- {
- CoUninitialize();
- return;
- }
-
- hr = pDisp->QueryInterface(IID_IAcadApplication,
- (void**)&pAcadApp);
- pDisp->Release();
- if (SUCCEEDED(hr))
- {
- LPDISPATCH pCAO = NULL;
- hr =
- pAcadApp->GetInterfaceObject(OLESTR("CAO.DbConnect"), &pCAO);
- pAcadApp->Release();
- if (FAILED(hr))
- ads_printf("\nFailed to get CAO.");
- else
- {
- ads_printf("\nGot CAO!");
- VARIANT varResult;
- //initialize the variant
- VariantInit(&varResult);
- OLECHAR *szMember = L"Version";
- DISPID dispid;
- DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0,
- 0};
- hr = pCAO->GetIDsOfNames(IID_NULL, &szMember, 1,
- LOCALE_USER_DEFAULT, &dispid);
- hr = pCAO->Invoke(dispid, IID_NULL,
- LOCALE_USER_DEFAULT,
- DISPATCH_PROPERTYGET, &dispparamsNoArgs,
- &varResult, NULL, NULL);
- if (SUCCEEDED(hr))
- {
- BSTR version = V_BSTR(&varResult);
- size_t size = SysStringByteLen(version);
- char* szVersion = new char[size];
- wcstombs(szVersion, version, size);
- ads_printf("\nVersion: %s", szVersion);
- SysFreeString(version);
- free(szVersion);
- }
- pCAO->Release();
- }
- }
- }
-
- CoUninitialize();
- }
- [/FONT]
|
|