Solved

evc++ /EHa option cause error LNK2019

Posted on 2011-09-29
14
594 Views
Last Modified: 2012-06-27
Hi,

i,m trying to use /EHa option in evc++ to use a TRY CATCH block catching also asyncrounouns errors (like index out of bound etc...)

the problem is that while linking it gives me this error:

DiagTool.obj : error LNK2019: unresolved external symbol ___CxxLongjmpUnwind@4 referenced in function "public: virtual int __thiscall CDiagToolApp::InitInstance(void)" (?InitInstance@CDiagToolApp@@UAEHXZ)

Project otpions are:

/nologo /W3 /Zi /Od /I "..\jpeglib\\" /D "DEBUG" /D "_i386_" /D UNDER_CE=$(CEVersion) /D _WIN32_WCE=$(CEVersion) /D "$(CePlatform)" /D "UNICODE" /D "_UNICODE" /D "_X86_" /D "x86" /D "_WIN32_WCE_CEPC" /D "_AFXDLL" /FR"X86Dbg/" /Fo"X86Dbg/" /Fd"X86Dbg/" /Gs8192 /GF /c /EHa

and the piece of code is this one:

      
TRY
	{
		int intArray[5] = { 16, 2, 77, 40, 12071 }; 
		int mtp;

		for(int i=-1;i<50;i++)
		{
			intArray[i]=i;
			mtp=intArray[i];
		}
		
	}
	CATCH( CException, e )
    {
		AfxMessageBox(_T("Problem here"));
	}
	END_CATCH

Open in new window

0
Comment
Question by:rileo8
  • 7
  • 5
14 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Are you just adding the compoiler option manually? Try to set that is VS (from the docs):

------------------------------------>8-----------------------------------

To set this compiler option in the Visual Studio development environment
Open the project's Property Pages dialog box. For details, see How to: Open Project Property Pages.

Click the C/C++ folder.

Click the Code Generation property page.

Modify the Enable C++ Exceptions property.

------------------------------------>8-----------------------------------
0
 

Author Comment

by:rileo8
Comment Utility
Hi,

i'm usinf EVC++ 4.0 so the only way to add it is by hand..

from the help:

 Project Options -> Type /EH in the text box, adding the desired exception-handling arguments.
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Hmm, could you give it a try to set that in the project options?
0
 

Author Comment

by:rileo8
Comment Utility
I already set it, project oprions are:

/nologo /W3 /Zi /Od /I "..\jpeglib\\" /D "DEBUG" /D "_i386_" /D UNDER_CE=$(CEVersion) /D _WIN32_WCE=$(CEVersion) /D "$(CePlatform)" /D "UNICODE" /D "_UNICODE" /D "_X86_" /D "x86" /D "_WIN32_WCE_CEPC" /D "_AFXDLL" /FR"X86Dbg/" /Fo"X86Dbg/" /Fd"X86Dbg/" /Gs8192 /GF /c /EHa

so you can see /EHa at the end of the string

The problem is that wihout it it catch only c++ exception while with it it should catch also win32 exception....but it gives that error...
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Honestly, I wouldn't try to catch SEH exceptions with a C++ exception handler, these are simply two different things. Rather try to
LONG
WINAPI
MyExceptionHandler(LPEXCEPTION_POINTERS pe) {

    AfxMessageBox(_T("Problem here"));

    return EXCEPTION_EXECUTE_HANDLER;
}

//...

SetUnhandledExceptionFilter(MyExceptionHandler);

TRY
	{
		int intArray[5] = { 16, 2, 77, 40, 12071 }; 
		int mtp;

		for(int i=-1;i<50;i++)
		{
			intArray[i]=i;
			mtp=intArray[i];
		}
		
	}
	CATCH( CException, e )
    {
		AfxMessageBox(_T("Problem here"));
	}
	END_CATCH

Open in new window

0
 

Author Comment

by:rileo8
Comment Utility
I did like this:


LONG WINAPI OurCrashHandler(EXCEPTION_POINTERS * /*ExceptionInfo*/)
{
    AfxMessageBox(_T("TAKEN"));

    return 0;
}

BOOL CDiagToolApp::InitInstance()
{

      SetUnhandledExceptionFilter(OurCrashHandler);

...

but it gives me compile error:

 error C2065: 'SetUnhandledExceptionFilter' : undeclared identifier
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
Comment Utility
Ooops, sorry, my fault - "Windows CE: Unsupported.". But, since you are mainly after SEH exceptions, does the following work for you?
//...
        __try
	{
		int intArray[5] = { 16, 2, 77, 40, 12071 }; 
		int mtp;

		for(int i=-1;i<50;i++)
		{
			intArray[i]=i;
			mtp=intArray[i];
		}
		
	}
	__except(1)
        {
		AfxMessageBox(_T("Problem here"));
	}

Open in new window

0
 

Author Comment

by:rileo8
Comment Utility
Now the code is like this:


      __try
    {
            regman->ReadString(_T("Language"));
      }
      __except(1)
    {
        AfxMessageBox(_T("Problem here"));
    }


and i don't have /EHa in the project settings

regman is a null pointer so rise an exception and it seems to work correctly.
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
That's what is is supposed to do ;o)
0
 

Author Comment

by:rileo8
Comment Utility
I've requested that this question be closed as follows:

Accepted answer: 0 points for rileo8's comment http:/Q_27361360.html#36815462

for the following reason:

Solved the issue
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Um, since your comment you suggested for closing this Q is basically what I wrote earlier - why are you not just closing this question?
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
http://www.experts-exchange.com/Programming/Languages/CPP/Q_27361360.html?cid=1572#a36815385 already lines out what now should be the solution now, thus the objection.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now