Click here to Skip to main content
15,891,688 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm new to managed C++, dealing now with a C++/CLI project which involved function calling from native DLL for results to be displayed via WinForm.

An expected exception is encountered when calling function from native DLL due to missing equipment for the project.

However, instead of being caught right on the function call. The program step out of the line of code & an AccessViolationException is caught where the WinForm runs:

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
	// Enabling Windows XP visual effects before any controls are created
	Application::EnableVisualStyles();
	Application::SetCompatibleTextRenderingDefault(false); 

	try{
	// Create the main window and run it
	Application::Run(gcnew Form1());
	}
	catch(System::AccessViolationException^ expMsg)
	{
		MessageBox::Show(expMsg->ToString());
	}
	return 0;
}

with Exception of:

'System.AccessViolationException' occurred in Unknown Module.


What I have tried:

While searching through the web, it seems like Winform projects by default skip the crt initialization, which obviously has an impact on any static objects. Is that the reason why the scenario happened?
Posted

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