DLL is not loading properly using LoadLibrary in VS 2019

  • Thread starter Thread starter AroDeep
  • Start date Start date
A

AroDeep

Guest
Below is the code of DLL (Compiled in VS2019 v142, SDK 10,Debug mode) compiled successfully. Loading this DLL(below code) using LoadLibrary()in MFC program(Compiled in VS2019 v142 , Sdk 10,Debug Mode). Both code works fine in VS2010. But not working in VS2019.

#include "stdafx.h"
#include "SiTempJCL.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

BEGIN_MESSAGE_MAP(SiJCLTemplateDfltApp, CWinApp)

END_MESSAGE_MAP()

SiJCLTemplateDfltApp::SiJCLTemplateDfltApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}


SiJCLTemplateDfltApp theApp;

extern "C" __declspec( dllexport )

CSResult* FireRule(CObList& list)
{
AFX_MAINTAIN_STATE2 *pState = new AFX_MAINTAIN_STATE2(AfxGetStaticModuleState());
try
{

CString *sJobTemplate;
CString sDBUseCode="M";
if((sDBUseCode == "M") || (sDBUseCode == "P")) {
sJobTemplate = new CString("JOBM");
}
else {
sJobTemplate = new CString("JOBC");
}

// Return JCL job template id
CSResult *ruleRet = new CSResult();
ruleRet->SetReturnObject((CObject *) sJobTemplate);

delete pState;
return ruleRet;
}
catch (...)
{
delete pState;
throw;
}
}


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//MFC code calling above DLL

HINSTANCE hModule;
hModule = LoadLibrary("SiJCLTemplate.dll");

SiLauncherApp* pSiBatchLauncherApp1 = (SiLauncherApp*)AfxGetApp();

I have checked hModule is not null, loading dll and calling firerule function.
but i think it is not loading properly. as when i check pSiBatchLauncherApp1 object after loadlibrary, it shows me

{SiJCLTemplateDfltApp.dll!SiJCLTemplateDfltApp theApp<NULL>};

Assuming , there is some issue in SiJCLTemplateDfltApp.dll that way it is not loading properly.

Please guide.

Continue reading...
 
Back
Top