fanvivian
路人甲
路人甲
  • 注册日期2003-09-08
  • 发帖数3
  • QQ
  • 铜币117枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1413回复:1

vc中引用AO库的错误?

楼主#
更多 发布于:2004-07-14 13:29
<P>在头文件中添加了:</P>
<P>#import "D:\arcgis\arcexe83\bin\esriCore.olb" raw_interfaces_only, raw_native_types, no_namespace, named_guids, exclude("OLE_COLOR", "OLE_HANDLE")</P>
<P>之后,编译总报错(如下),出现在'OLE_HANDLE'和'OLE_COLOR' 出现的地方,怎么回事呢?
:</P>
<P>d:\microsoft visual studio\vc98\include\ocidl.h(4482) : error C2061: syntax error : identifier 'OLE_HANDLE'</P>
<P>或者</P>
<P>d:\microsoft visual studio\vc98\mfc\include\afxctl.h(561) : error C2501: 'OLE_COLOR' : missing storage-class or type specifiers

</P>
喜欢0 评分0
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
1楼#
发布于:2004-07-15 10:58
<H4>Summary</H4><DIV>Instructions provided describe how to implement an event sink object for ArcObjects using ATL IDispEventSimpleImpl template interface with Microsoft Visual C++ 6.0.

Event sink is the process by which events raised in a COM object are handled by callback functions on a special interface of another object. Fundamentally, both Visual C++ and Visual Basic use event sinks to monitor COM object's state and respond to the predefined events generated by them. Both of the above programming environments have complete and practical events handling mechanisms for COM objects and especially for ActiveX controls. Custom implementations of event sink are occasionally required for a particular need.</DIV>
<H4>Procedure</H4><DIV><OL><LI>Create a new MFC AppWizard project called EventSink. At Step 1 of the wizard, select Dialog based as the application type, accept all the default settings of the remainder of the wizard and click on Finish to create the project. <LI>Right-click on the EventSink project in the project explorer and select New ATL Object… in the context menu to add ATL support to the MFC project. No COM objects or controls must be added to the project, only ATL support is required. <LI>Add an ESRI MapControl to the project main dialog box IDD_EVENTSINK_DIALOG. <LI>Add a new class named CMCEventSinkObj. In the header file of CMCEventSinkObj class, add the following at the top,

<DIV #cccccc 2px solid; PADDING-RIGHT: 0.5em; BORDER-TOP: #cccccc 2px solid; PADDING-LEFT: 0.5em; PADDING-BOTTOM: 0.5em; BORDER-LEFT: #cccccc 2px solid; WIDTH: 500px; PADDING-TOP: 0.5em; BORDER-BOTTOM: #cccccc 2px solid; FONT-FAMILY: courier; BACKGROUND-COLOR: whitesmoke"><PRE 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px">#include "resource.h"
#pragma warning(push)
#pragma warning(disable : 4146)
#pragma warning(disable : 4192)
#import "C:\Program Files\arcgis\arcexe83\bin\esriCore.olb" raw_interfaces_only, raw_native_types, named_guids, exclude("OLE_COLOR", "OLE_HANDLE")
#import "C:\Program Files\arcgis\arcexe83\bin\MapControl.ocx" no_namespace, named_guids
#pragma warning(pop)</PRE></DIV>

<DIV 500px"><img src="http://support.esri.com/common/style/graphics/icons/note.gif"> Import esriCore.olb before importing MapControl.ocx because MapControl.ocx relies on the types defined in the esriCore.olb.</DIV>
<LI>Derive the CMCEventSinkObj from IDispEventSimpleImpl<…> class template as following:

<DIV #cccccc 2px solid; PADDING-RIGHT: 0.5em; BORDER-TOP: #cccccc 2px solid; PADDING-LEFT: 0.5em; PADDING-BOTTOM: 0.5em; BORDER-LEFT: #cccccc 2px solid; WIDTH: 500px; PADDING-TOP: 0.5em; BORDER-BOTTOM: #cccccc 2px solid; FONT-FAMILY: courier; BACKGROUND-COLOR: whitesmoke"><PRE 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px">class CMCEventSinkObj : public IDispEventSimpleImpl<IDC_MAPCONTROL1, CMCEventSinkObj, ;DIID_IMapControlEvents2>
</PRE></DIV>
IDC_ MAPCONTROL1 is the ID of the map control, CMCEventSinkObj is the name of this event sink class, and DIID_IMapControlEvents2 is the GUID of the map control’s event interface. In COM, events are actually outbound methods defined on a special interface. When events are fired, these outbound methods invoke the corresponding handlers defined in the event sink to process the events. So events in COM are nothing more than a group of methods in a special interface. <LI>Open the OLE/COM Object Viewer, or OLE View by name, to study the Map Control event interface. Select View TypeLib and open the Map Control (MapControl.ocx) located under C:\arcgis\arcexe83\bin\. Expand Dispinterface and locate IMapControlEvents2. Define a static object of type _ATL_FUNC_INFO about the event method to respond to. In this example, select to catch the onMouseDown event. In OLE View, OnMouseDown takes 6 parameters, 4 or type long and 2 of type double. So the declaration is the following:

<DIV #cccccc 2px solid; PADDING-RIGHT: 0.5em; BORDER-TOP: #cccccc 2px solid; PADDING-LEFT: 0.5em; PADDING-BOTTOM: 0.5em; BORDER-LEFT: #cccccc 2px solid; WIDTH: 500px; PADDING-TOP: 0.5em; BORDER-BOTTOM: #cccccc 2px solid; FONT-FAMILY: courier; BACKGROUND-COLOR: whitesmoke"><PRE 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px">static _ATL_FUNC_INFO MCOnMouseDownInfo = {CC_STDCALL, VT_I4, 6, {VT_I4, VT_I4, VT_I4, VT_I4, VT_R8, VT_R8}};</PRE></DIV>
Refer to the MSDN for more information about _ATL_FUNC_INFO. <LI>Define a member variable and a class constructor as following in class CMCEventSinkObj:

<DIV #cccccc 2px solid; PADDING-RIGHT: 0.5em; BORDER-TOP: #cccccc 2px solid; PADDING-LEFT: 0.5em; PADDING-BOTTOM: 0.5em; BORDER-LEFT: #cccccc 2px solid; WIDTH: 500px; PADDING-TOP: 0.5em; BORDER-BOTTOM: #cccccc 2px solid; FONT-FAMILY: courier; BACKGROUND-COLOR: whitesmoke"><PRE 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px">HWND m_hWndList;
CMCEventSinkObj(HWND hWnd = NULL) : m_hWndList(hWnd)
{
}
</PRE></DIV>
<LI>Define the event sink map as following in class CMCEventSinkObj:

<DIV #cccccc 2px solid; PADDING-RIGHT: 0.5em; BORDER-TOP: #cccccc 2px solid; PADDING-LEFT: 0.5em; PADDING-BOTTOM: 0.5em; BORDER-LEFT: #cccccc 2px solid; WIDTH: 500px; PADDING-TOP: 0.5em; BORDER-BOTTOM: #cccccc 2px solid; FONT-FAMILY: courier; BACKGROUND-COLOR: whitesmoke"><PRE 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px">BEGIN_SINK_MAP(CMCEventSinkObj)
SINK_ENTRY_INFO(IDC_MAPCONTROL1, DIID_IMapControlEvents2, 1, MCOnMouseDown, ;MCOnMouseDownInfo)
END_SINK_MAP()
</PRE></DIV>
Because the id of method onMouseDown in IMapControlEvents2 is 1, in decimal value, specify 1 as the entry id for this method. MCOnMouseDown is the event handler that would be invoked on this event. <LI>Define the MCOnMouseDown method as following in class CMCEventSinkObj:

<DIV #cccccc 2px solid; PADDING-RIGHT: 0.5em; BORDER-TOP: #cccccc 2px solid; PADDING-LEFT: 0.5em; PADDING-BOTTOM: 0.5em; BORDER-LEFT: #cccccc 2px solid; WIDTH: 500px; PADDING-TOP: 0.5em; BORDER-BOTTOM: #cccccc 2px solid; FONT-FAMILY: courier; BACKGROUND-COLOR: whitesmoke"><PRE 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px">HRESULT __stdcall MCOnMouseDown(short iButton, short iShift, long iX, long iY, double dMapX, double dMapY)
{
TCHAR buf[1024];
sprintf(buf, "You clicked at point (%i, %i).", iX, iY);
::SendMessage(m_hWndList, LB_ADDSTRING,0, (LPARAM)buf);
return S_OK;
}
</PRE></DIV>
This event handler obtains the point at which the user clicked the mouse on the map control and sends a message string 'You clicked at point (X, Y)' to a listbox in which this string will be displayed.

<DIV 500px"><img src="http://support.esri.com/common/style/graphics/icons/note.gif"> The parameter signature corresponds to the COM interface definition.</DIV>
<LI>The event sink object for the map control is finished. The following is the code to test this sink object. Add a listbox to the dialog and name it as IDC_LIST1. Uncheck Sort on the Style tab in the property page. <LI>Define a CMCEventSinkObj in CEventSinkDlg class:

<DIV #cccccc 2px solid; PADDING-RIGHT: 0.5em; BORDER-TOP: #cccccc 2px solid; PADDING-LEFT: 0.5em; PADDING-BOTTOM: 0.5em; BORDER-LEFT: #cccccc 2px solid; WIDTH: 500px; PADDING-TOP: 0.5em; BORDER-BOTTOM: #cccccc 2px solid; FONT-FAMILY: courier; BACKGROUND-COLOR: whitesmoke"><PRE 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px">CMCEventSinkObj* m_pMCEventSink;</PRE></DIV>
<LI>In the CEventSinkDlg::OnInitDialog() method, add the following at the bottom:

<DIV #cccccc 2px solid; PADDING-RIGHT: 0.5em; BORDER-TOP: #cccccc 2px solid; PADDING-LEFT: 0.5em; PADDING-BOTTOM: 0.5em; BORDER-LEFT: #cccccc 2px solid; WIDTH: 500px; PADDING-TOP: 0.5em; BORDER-BOTTOM: #cccccc 2px solid; FONT-FAMILY: courier; BACKGROUND-COLOR: whitesmoke"><PRE 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px">m_pMCEventSink = new CMCEventSinkObj((GetDlgItem(IDC_LIST1))->m_hWnd );
HRESULT hr = m_pMCEventSink->DispEventAdvise((GetDlgItem(IDC_MAPCONTROL1)->GetControlUnknown()));
</PRE></DIV>
Run the program. The listbox displays the message sent from the event sink object. </LI></OL></DIV>
<H4>Related Information</H4><DIV><UL><LI><a href="http://msdn.microsoft.com/" target="_blank" ><FONT color=#0a8161>Microsoft Developer Network</FONT></A></LI></UL></DIV>
GIS麦田守望者,期待与您交流。
举报 回复(0) 喜欢(0)     评分
游客

返回顶部