tags:

views:

40

answers:

1

Hi i have explained the scenario in one of my earlier questions in the link, http://stackoverflow.com/questions/4008156/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();

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

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) Later I entered this code part in comutil.h

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

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

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

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

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());

}**

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

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

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

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

#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());
}

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.

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