无法从一个VC ++应用程序调用COM DLL的功能是什么? [英] Not able to CALL the functions of COM DLL from a VC++ application?

查看:353
本文介绍了无法从一个VC ++应用程序调用COM DLL的功能是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的链接,<一个较早的一个问题解释的情况下href="http://stackoverflow.com/questions/4008156/how-to-call-functions-of-a-com-dll-in-vc-from-a-vc-exe-application/">How调用COM DLL(在VC ++),从一个VC .EXE应用程序的功能?的,也是回答帮我在很大的程度。 。我调用应用程序是构建完美。但我遇到的问题,当我调试调用应用程序。在函数调用语句, 如果 XYZ是在Debug目录的.tlh文件中的智能指针类的命名空间, CX是类在我的COM类的名称并IX是公开的接口由类CX比,

Hi i have explained the scenario in one of my earlier questions in the link, How to call functions of a COM DLL (In VC++) from a VC++ .EXE application? and also the answer helped me to a great extent. . My calling application is building perfectly. But I am encountering problem, when I am debugging the calling application. In the function call statement, If XYZ is the namespace of the smart pointer class in the .tlh file of Debug directory, Cx is the name of the class in my COM Class and Ix is the interface exposed by the class Cx than,

XYZ :: IxPtr OBJ;
    obj.CreateInstance(__ uuidof(XYZ :: CX));
    obj-> FUNC();

 当我把一个断点在函数调用语句,并步入它(使用F11),我会通过以下-----------------

XYZ::IxPtr obj;
obj.CreateInstance(__uuidof(XYZ::Cx));
obj->func();

When I am putting a breakpoint in the function call statement and STEPPING INTO it (using F11), I am going through following -----------------

1)在线_variant_t :: _ variant_t(常量VARIANT&安培; varSrc) {     :: VariantInit(本);     _com_util :: CheckError(:: VariantCopy(这一点,const_cast会(安培; varSrc))); }
comutil.h 头文件
2)如果我继续步进在使用F11,后来我进,
       命名空间_com_util {     内嵌无效CheckError(HRESULT小时)掷(...)     {         如果(失败(小时)){             _com_issue_error(小时);         }     } }    如果上述code stmnt,在同一个comutil.h头文件和控制didnt输入

1) inline _variant_t::_variant_t(const VARIANT& varSrc) { ::VariantInit(this); _com_util::CheckError(::VariantCopy(this, const_cast(&varSrc))); }
in the comutil.h header file
2) If I keep on Stepping In using F11, later I entered,
namespace _com_util { inline void CheckError(HRESULT hr) throw(...) { if (FAILED(hr)) { _com_issue_error(hr); } } } in the same comutil.h header file and control didnt enter if stmnt of above code.

3)后来我在comutil.h进入这个code部分

3) Later I entered this code part in comutil.h

在线_variant_t :: _ variant_t(常量VARIANT&安培; varSrc) {     :: VariantInit(本);     _com_util :: CheckError(:: VariantCopy(这一点,const_cast会(安培; varSrc))); }

inline _variant_t::_variant_t(const VARIANT& varSrc) { ::VariantInit(this); _com_util::CheckError(::VariantCopy(this, const_cast(&varSrc))); }

4)控制回来给调用语句obj-> FUNC();

4) Control came back to the calling statement obj->func();

5)再次pressing F11,控制进入下code,在 comip.h头文件

5) again on pressing F11, control entered the following code , in "comip.h" header file.

接口*运算符 - >()const的     {         如果(m_pInterface == NULL){             _com_issue_error(E_POINTER);         }         返回m_pInterface;     }

Interface* operator->() const { if (m_pInterface == NULL) { _com_issue_error(E_POINTER); } return m_pInterface; }

下面控制进入IF语句,我得到一个弹出窗口说:没有源$ C ​​$ C可用于当前位置,并要求SHOW拆卸。  好心帮我在执行从EXE应用程序的函数调用。

Here control is entering IF statement and I am getting a pop up window saying "THERE IS NO SOURCE CODE AVAILABLE FOR THE CURRENT LOCATION" AND ASKING SHOW DISASSEMBLY. kindly help me in executing the function call from EXE application.

如果我把一个尝试捕捉的函数调用

If I put a try catch for the function call

try {
    obj->func();
} 
catch (_com_error e) {  
   printf("Error: %s\n", (LPCSTR)e.Description()); 
   printf("Error: %s\n", (LPCSTR)e.ErrorMessage());  
}

我得到的输出空和我这2 printfs输出。

I get the output "NULL" and "I" for these 2 printfs.

我不知道什么是功能没有得到所谓的原因...

I dont know what is the reason the functions are not getting called...

我显示D信号源$ C ​​$我叫MFC应用程序下进行。

I am showing d source code of my calling MFC application.

我会贴在这里调用应用程序的我的源$ C ​​$ C。嘿,如果ü可以让我知道,如果我缺少什么。

I will paste my source code of calling application here. plz if u can let me know if I am missing anything.

#include "stdafx.h"  
#include "Calling.h"  
#include "comutil.h"  
#include <objbase.h>  

#ifdef _DEBUG  
#define new DEBUG_NEW  
#endif  

// The one and only application object 
CWinApp theApp;  
using namespace std;   

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])  
{  
    int nRetCode = 0;  

    // initialize MFC and print and error on failure  
    if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))  
    {  
        // TODO: change error code to suit your needs  
        _tprintf(_T("Fatal Error: MFC initialization failed\n"));   
        nRetCode = 1;  
    }  
    else  
    {  
        // TODO: code your application's behavior here.  
        try  
        {  
            XYZLib::IxPtr obj;  
            obj.CreateInstance(_uuidof(XYZLib::x));  
            objt->setUser(uid);  
        }  
        catch (_com_error e) {  
            printf("Error: %ls\n", (wchar_t*)e.ErrorMessage());  
            printf("Error: %ls\n", (wchar_t*)e.Description());  
        }
    }
}

这是我的calling.cpp文件的code段。 我注册使用regsvr32命令DLL。 我在stdafx.h中的文件和编译stdafx.cpp进口.DLL。 我的COM DLL是比调用应用程序完全不同的目录。我刚才导入的.dll文件在我调用应用程序。我应该做的DEF文件或.IDL或我的COM DLL的.LIB文件中的任何。或者我应该不需要做任何设置,请让我知道。

This is the code snippet of my calling.cpp file. I registered the DLL using regsvr32 command. I have imported .DLL in my stdafx.h file and compiled stdafx.cpp. My COM DLL is in a totally different directory than the calling application. I have just imported its .DLL file in my calling application. Should I do anything with .DEF file or .IDL or .LIB file of my COM DLL. Or should I need to do any settings kindly let me know.

由于这是一个MFC应用程序,我没有使用CoInitialize的()USES_CONVERSION等...

Since this is a MFC application, I didnt use CoInitialize() USES_CONVERSION etc....

推荐答案

试着寻找<一href="https://encrypted.google.com/search?hl=en&source=hp&biw=1366&bih=612&q=%22Automation+helper+function%22&aq=f&aqi=&oq=&gs_rfai="相对=nofollow>自动化辅助函数

考虑到这些例子,可以帮助:
如何填充EXCEPINFO在IDispatch实现
如何使用Visual C ++来访问DocumentProperties使用自动化
如何实现的Visual C ++ COM对象返回记录

Try looking for Automation helper function

Consider these examples that can help :
How to Fill EXCEPINFO in IDispatch Implementation
How To Use Visual C++ to Access DocumentProperties with Automation
How To Implement Visual C++ COM Objects Returning Recordsets

这篇关于无法从一个VC ++应用程序调用COM DLL的功能是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆