找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 615|回复: 1

[ARX函数]:接口问题,高手请进!

[复制链接]
发表于 2002-11-8 19:13:18 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
请看,我从别处抄来的程序,是应用com接口来创建菜单。但运行到标志位置就出现“未处理的异常E06d7363(E06D7363H)地址:77E7E8BBh”错误:
部分代码如下:

IAcadMenuBar                AcadMenuBar;
IAcadPopupMenus                AcadPopupMenus;
IAcadPopupMenu                AcadPopupMenu;
//创建AcadMenuBar接口

AcadMenuBar.AttachDispatch(AcadApplication.GetMenuBar());
//获得菜单栏的个数
NumOfMenu=AcadMenuBar.GetCount();
//创建AcadPopupMenus接口

AcadPopupMenus.AttachDispatch(AcadMenuGroup.GetMenus());
//创建AcadPopupMenu接口

AcadPopupMenu.AttachDispatch(AcadPopupMenus.Add("文具(&Q)"));
//就在上面这一句就出错了!

我想是不是因为地址冲突了呢?但我不知道是为什么,怎么冲突了,怎么解决,请高手帮忙看一下!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-11-8 19:23:08 | 显示全部楼层
给你贴篇用ACTIVEX创建POP菜单的资料,你看看,讲的比较详细了。

你的问题解决后,希望把完整的代码贴到论坛和大家分享。


  1. [FONT=courier new]
  2. How to create a pull-down popup menu through ActiveX?  
  3. ID    17818  
  4. Applies to:    AutoCAD

  5. This document is part of    ObjectARX   COM-ActiveX Interfaces   Menus and Toolbars   MFC     


  6. Question
  7. I'm trying to access the menu groups and popup menus exposed through Automation,
  8. but there are so many different objects, menu groups, menu group, popup menus,
  9. and popup menu item. Is there a client sample in C++?
  10. Answer
  11. It can be confusing to sort through so many objects and use them. A good way to
  12. understand their relationships is to look at the Automation Object Model because
  13. it depicts a hierarchical relationship among the menu objects as well as with
  14. others.

  15. The following code creates a dialog-based client application, assigns a button
  16. to handle "Start Acad", and assigns a button to handle "Add a menu item". (The
  17. following code assumes you know how to create a dialog-based MFC application.)

  18. In the dialog's header file, the following member variables were declared (you
  19. need to import interface classes from the acad.tlb file using the ClassWizard,
  20. Add class..., choose From type library. Be sure not to use #import).
  21. IAcadApplication m_IApp;
  22.         IAcadDocument         m_IDoc;
  23.         IAcadModelSpace  m_IMSpace;
  24.        
  25.         IAcadMenuGroups         m_IMenuGrps;
  26.         IAcadMenuGroup                m_IMenuGrp;
  27.         IAcadPopupMenus         m_IPopupMenus;
  28.         IAcadPopupMenu                m_IPopupMenu;
  29.         IAcadPopupMenuItem        m_IPopupMenuItem;
  30. In the dialog's cpp file, add the following (2) handlers:
  31. //
  32. // This function starts Acad and initialize the appropriate
  33. // interface objects
  34. //
  35. void CClientDlg::OnStartAcad()
  36. {
  37.         HRESULT hr = NOERROR;
  38.         CLSID clsid;
  39.         LPUNKNOWN pUnk = NULL;
  40.         LPDISPATCH pDisp = NULL;

  41.         BeginWaitCursor();
  42.         CoInitialize(NULL);
  43.         hr = ::CLSIDFromProgID(L"AutoCAD.Application", &clsid);

  44.         if (SUCCEEDED(hr))
  45.         {
  46.                 if(::GetActiveObject(clsid, NULL, &pUnk) == S_OK)
  47.                 {
  48.                         VERIFY(pUnk->QueryInterface(IID_IDispatch, (LPVOID*)
  49. &pDisp) == S_OK);
  50.                         m_IApp.AttachDispatch(pDisp);
  51.                         pUnk->Release();
  52.                 }
  53.                 else
  54.                         VERIFY(m_IApp.CreateDispatch(clsid) == TRUE);
  55.                
  56.                 m_IApp.SetVisible(TRUE);

  57.                 pDisp = m_IApp.GetActiveDocument();
  58.                 m_IDoc.AttachDispatch(pDisp);
  59.                 pDisp = m_IDoc.GetModelSpace();
  60.                 m_IMSpace.AttachDispatch(pDisp);

  61.         }
  62.         else
  63.                 AfxMessageBox("Acad.Application is not registered!");

  64.         // remember the you need to call CoUninitialize(); somewhere
  65.         // I would do it in the destructor of the dialog
  66.         EndWaitCursor();
  67. }
  68. //
  69. // This function adds a popup menu to the exist row of popup menus
  70. // displayed in the menu bar.
  71. //
  72. // Note: The popup menus and menu items that we are adding
  73. // through Automation, are in memory only. They are not
  74. // saved in any menu files, no persistent in another word.
  75. //
  76. void CClientDlg::OnAddMenuButton()
  77. {
  78.         // get all the menu groups
  79.         LPDISPATCH pDisp = m_IApp.GetMenuGroups();
  80.         m_IMenuGrps.AttachDispatch(pDisp);

  81.         // get to the menu group that we're interested
  82.         VARIANT var;
  83.         var.vt = VT_I4;
  84.         var.lVal = 0;
  85.         pDisp = m_IMenuGrps.Item(var);
  86.         m_IMenuGrp.AttachDispatch(pDisp);

  87.         // get the popup menus in the menu group
  88.         pDisp = m_IMenuGrp.GetMenus();
  89.         m_IPopupMenus.AttachDispatch(pDisp);

  90.         long cnt = m_IPopupMenus.GetCount();
  91.         VARIANT  vtIndex;
  92.         vtIndex.vt = VT_I4;
  93.         vtIndex.lVal = cnt + 1;

  94.         // append a popup menu to the popup menus
  95.         const char myPopupMenuName[] = "TestPopupMenu";
  96.         pDisp = m_IPopupMenus.Add(myPopupMenuName);
  97.         m_IPopupMenu.AttachDispatch(pDisp);
  98.         m_IPopupMenus.InsertMenuInMenuBar(myPopupMenuName, vtIndex);

  99.         // append a menu item to the popup menu we added
  100.         // notice the last parameter of AddMenuItem is for
  101.         // a command
  102.         vtIndex.lVal = 0;
  103.         pDisp = m_IPopupMenu.AddMenuItem(vtIndex, "TestItem", "Regen ");
  104.         m_IPopupMenuItem.AttachDispatch(pDisp);
  105. }
  106. Removing menu bar and items are just as easy. You can call
  107. RemoveMenuFromMenuBar() to remove a popup menu, for example.[/FONT]
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-15 15:14 , Processed in 0.325685 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表