Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Below code works fine in VS2010 . But it is not working in VS2017. Below the code snippet .

void ResultRule::ExecuteFireRule()
	HINSTANCE         hModule;
	CSiRuleReturn *pRuleRet = NULL;


	hModule = LoadLibrary("siJCLJOb.dll");
	pFunc = (FIRERULE) GetProcAddress(hModule, "FireRule");

	if (pFunc != NULL)
		try {
			pRuleRet = pFunc(inputList);
		catch (CException *)

		if (pRuleRet->GetReturnCode() > retVal.GetReturnCode())
		if (pRuleRet->GetReturnObject())
		delete pRuleRet;		
		CString msg;
		msg.Format("The result rule defined on line %d of %s referenced result module [%s], which has no exported FireRules function.", m_fileLineNumber, m_ruleFile, m_moduleName);
		CSiException *pEx = new CSiException("CSiResultRule::FireRule", msg);
		throw pEx;

Calling Above code:
//Calling above ExecuteFireRule(), which will dynamically load firerule function of siJCLJOb.dll.

CSiRuleReturn ruleRet = iRulesProcessor::GetInstance()->FireRequestRule("JCLCARD", NULL, "");
CString *pJobTemplate = (CString*)ruleRet.GetReturnObject(); // gives me the correct values after executing FireRule function of siJCLJob.dll

CLauncherApp* Obj = (CLauncherApp*)AfxGetApp(); // after dynmic execution , it corrupts the memory /main thread . it show me the object siJCLJob.dll, when i place my cursor to Obj

What I have tried:

We are facing same issue in all MFC dynamic loaded objects. We have tried to compile the code by adding
... but getting runtime error
Exception thrown: read access violation.
this was 0x3E8.
Updated 7-Sep-20 7:48am
Rick York 10-Jul-20 11:11am    
My guess is you have a version mismatch problem with MFC DLLs. Try rebuilding the DLLs. If you can't do that then you probably need to stay with VS2010.
Member 13261094 13-Jul-20 1:44am    
All MFC and DLL are compiled using VS2017 in debug mode.
KarstenK 10-Jul-20 12:10pm    
Rick is right, it best to build all dll with the same VS version. Another way is to make a static build.
Shao Voon Wong 11-Jul-20 5:46am    
Check whether hModule and pFunc is NULL. Check siJCLJOb.dll is in the executable path. If they are correct, then it could be the VC runtime for siJCLJOb.dll is not found/installed. Try installing VS2010 runtime.
Member 13261094 13-Jul-20 1:45am    
I have debugged the code and It's loading the siJCLJOB.dll and pFunc is not null. After execution of siJCLJOB.dll function, it corrupts the main memory/thread.

1 solution

When you use
hModule = LoadLibrary("siJCLJOb.dll");

pFunc = (FIRERULE) GetProcAddress(hModule, "FireRule");

There is the option that LoadLibrary will fail, and if it does, the next line will cause an Access Violation.

Change it to:

hModule = LoadLibrary("siJCLJOb.dll");

if(hModule) pFunc = (FIRERULE) GetProcAddress(hModule, "FireRule");
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900