views:

27

answers:

0

Hello,

I have native C++ DLL code to call from C++/CLI functions. It's not working properly. I am copying those areas of code here which causing problems.

Note: I made native C++ stub and called that native dll's functions and it worked fine as per context.

Native C++ DLL:

void ExecutorFactory::GetTESService(string a_strFileToProcess,ISubjectExecutor**            a_pSubjectExecutor)
 {
SubjectTypes oSubjectType;
DetermineSubjectType(a_strFileToProcess,&oSubjectType);

ICOMExecutor *pCOMExecutor = NULL;
IWin32Executor *pWin32executor = NULL;
ISubjectExecutor *pSubjectExecutor = NULL;

if(oSubjectType == SubjectTypes::COM)
{
    pCOMExecutor =  COMExecutor::getInstance();
    if(pCOMExecutor!=NULL && pCOMExecutor)
    {
        pSubjectExecutor = (ISubjectExecutor*)pCOMExecutor;

    }//end of else
}
else if(oSubjectType == SubjectTypes::WIN_32)
{
    pWin32executor =  Win32Executor::getInstance();
    if(pWin32executor!=NULL && pWin32executor)
    {
        pSubjectExecutor = (ISubjectExecutor*)pWin32executor;
    }//end of else
}
*a_pSubjectExecutor = pSubjectExecutor;
  }

  EXECUTORFACTORY_EXPORTS_API ExecutorFactory* ExecutorFactory::getInstance()
  {
 static ExecutorFactory oExecutorFactory;
 return &oExecutorFactory;
  }

I called its function from native C++ stub which was its client.It worked fine for every call like

    ExecutorFactory *pExecutorFactory = ExecutorFactory::getInstance();
    pExecutorFactory->GetTESService(strPath,&pSubjectExecutor);

here pExecutorFactory pointer was fine and After calling GetTESService "pSubjectExecutor" was pointing to some object created inside GetTESService.

But when I called the same piece of code(statted above) getInstance and GetTESService() from some MANAGED C++/CLI code it has some unpredictable behaviors.

getInstance worked fine here. it returned valid pointer, but GetTESService() which is taking address of SubjectExecutor pointer(pSubjectExecutor) , it returned it with "undefined value"..

Managed C++/CLI assembly linked properly native C++ DLL. but when it loaded its symbols i watched in Modules window : "The module did not load at default loaded address" and it marked with red sign. More over I am unable to debug as break point not hit inside native C++ code of above DLL when calling from managed code.

Regards Usman