本文介绍了有没有办法在COM中的另一个exe中访问寄存器对象的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 创建ATL COM DLL 启动Visual Studio .NET 启动新项目 选择Visual C ++项目 选择ATL项目 点击确定 为项目命名ATLDemo 点击确定 默认选项是动态链接库(DLL),点击下一步 选择支持MFC,点击完成 添加ATL COM控制 右键单击项目名称 转到添加选项 选择添加类... 选择ATL COM控制 根据要求选择选项,点击完成 在ATL Contol中添加方法 右键单击Class View中指定的接口类 转到添加 选择添加方法 输入方法名称 选中t下的in复选框他参数属性部分 为参数类型选择BSTR 将参数命名为bsName 点击添加 点击完成 在运行对象表中注册COM对象的代码 STDMETHODIMP CPPName :: FunctionName (BSTR bsName) { ConInitialize(NULL); CComPtr< IBindCtx>中国人民银行; CComPtr< IRunningObjectTable> PROT; CComPtr< IMoniker> spMoniker; CComPtr< IUnknown>仙水; CComPtr< IEnumMoniker> IMonikerEnum; DWORD dWCookie; CreateBindCtx( 0 ,& pbc); pbc-> GetRunningObjectTable(& pROT); CreateItemMoniker(NULL,bsName,& spMoniker); QueryInterface(IID_IUNKNOWN,( void **)& spUnk); pROT->注册(ROTFLAGS_REGISTRATIONKEEPSALIVE,spUnk,spMoniker,& dWCookie); CoUnInitialize(); } 在其他COM对象中使用注册COM对象 STDMETHODIMP CPPName :: FunctionName (BSTR bsName) { ConInitialize(NULL); CComPtr< IBindCtx>中国人民银行; CComPtr< IRunningObjectTable> PROT; CComPtr< IMoniker> spMoniker; CComPtr< IUnknown>仙水; CComPtr< IEnumMoniker> IMonikerEnum; DWORD dWCookie; CreateBindCtx( 0 ,& pbc); pbc-> GetRunningObjectTable(& pROT); < Loop for Moniker,检查名称提供> hr = pROT-> GetObject(pMon,& pInterface); < IF获取Moniker的名字> == bsName> hr = pInterface-> QueryInterface(IID_IAttach,( void **)pAttach); <结束IF> < Loop End> } pAttach对象可以访问已注册的对象。 由此pAttach可以访问对象的方法。 问题: 我正在使用One Exe注册的对象。 在另一个exe中我使用另一个对象给出已经注册的名称。 现在我的任务是从第一个exe时点击左键然后第二个exe exe应该得到消息。 有没有办法在另一个exe中访问寄存器对象的事件?? 解决方案 简单的答案是否定的。但是一个程序可以发送一条消息说我点击了我的按钮并将其发送到特定进程或广播它以获取任何内容 起点此处 [ ^ ] 但是,如果您遇到代码的特定问题你发布了,然后在鲍里斯的文章 结尾处有一个评论部分Create the ATL COM DLL Start Visual Studio .NET Start a "New Project" Select "Visual C++ Projects" Select "ATL Project" Click "OK" Name the project "ATLDemo" Click "OK" As the default option is "Dynamic-link library (DLL)", Click "Next Select Support MFC, click "Finish" Add ATL COM Control Right-click on the project name Go to the "Add" option Select "Add Class…" Select "ATL COM Control" Select Options as per Requirement, Click "Finish" Add Method in ATL Contol Right-click on the interface class named in Class View Go to "Add" Select "Add Method" Enter method name Check the "in" checkbox under the "Parameter attributes" section Select BSTR for the parameter type Name the parameter "bsName" Click "Add" Click "Finish" Code to Register COM Object in Running Object TableSTDMETHODIMP CPPName::FunctionName(BSTR bsName){ ConInitialize(NULL); CComPtr<IBindCtx> pbc; CComPtr<IRunningObjectTable> pROT; CComPtr<IMoniker> spMoniker; CComPtr<IUnknown> spUnk; CComPtr<IEnumMoniker> IMonikerEnum; DWORD dWCookie; CreateBindCtx(0,&pbc); pbc->GetRunningObjectTable(&pROT); CreateItemMoniker(NULL,bsName,&spMoniker); QueryInterface(IID_IUNKNOWN, (void**)&spUnk); pROT->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, spUnk, spMoniker, &dWCookie); CoUnInitialize();} Use Register COM Object in other COM ObjectSTDMETHODIMP CPPName::FunctionName(BSTR bsName){ ConInitialize(NULL); CComPtr<IBindCtx> pbc; CComPtr<IRunningObjectTable> pROT; CComPtr<IMoniker> spMoniker; CComPtr<IUnknown> spUnk; CComPtr<IEnumMoniker> IMonikerEnum; DWORD dWCookie; CreateBindCtx(0,&pbc); pbc->GetRunningObjectTable(&pROT); <Loop For Moniker, Checking Name Provided> hr = pROT->GetObject(pMon, &pInterface); <IF Get Name of Moniker> == bsName> hr = pInterface->QueryInterface(IID_IAttach, (void **)pAttach); <End IF> <Loop End>}"pAttach" object having access to object that is Registered.By this "pAttach" having access to methods of object.Problem:I am having One Exe with Object that is registed.In another exe I am using another object giving name that is already registered.Now my task is from first exe when i m clicking left button then second exe should get message.Is there any way to access register object's event in another exe?? 解决方案 The simple answer is No. But a program can transmit a message to say "my button was clicked" and either send it to a specific process or broadcast it for anything to pick upStarting point here[^]However, if you are having specific problems with the code you posted, then there is a Comments section at the end of Boris' article 这篇关于有没有办法在COM中的另一个exe中访问寄存器对象的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 09:41