-
September 13th, 2010, 10:26 AM
#1
How to catch error happening AFTER the code / application
Hi all!
I am using a DLL which I am not sure if has some issues. The problem is that it always causes my application to crash right AFTER the code / application.
However, I can properly use all its function while inside the code.
What I want to do is to probably make the error 'silent' or seemingly not happening. The problem is, I can't put this on try-catch because it happens AFTER the code.
Has anyone any idea what I need to do?
Thank you!
-
September 13th, 2010, 10:47 AM
#2
Re: How to catch error happening AFTER the code / application
What do you mean cause the application to crash after the application?
Have you tried the debugger?
-
September 13th, 2010, 11:34 AM
#3
Re: How to catch error happening AFTER the code / application
Originally Posted by LeanA
Hi all!
I am using a DLL which I am not sure if has some issues.
What is the name of this DLL? Have you contacted the persons responsible for creating the DLL?
The problem is that it always causes my application to crash right AFTER the code / application.
Maybe it is your application that is faulty or doing something illegal, and not the DLL.
However, I can properly use all its function while inside the code.
As any experienced C++ programmer would tell you, just because it crashes at some point doesn't mean that is where the problem started.
Again, you could have been using the code incorrectly, and then the crash occurs due to your improper usage.
What I want to do is to probably make the error 'silent' or seemingly not happening. The problem is, I can't put this on try-catch because it happens AFTER the code.
You should be determining exactly why the code crashes, and not create band-aid "solutions" that do not really fix the problem.
Regards,
Paul McKenzie
-
September 13th, 2010, 09:55 PM
#4
Re: How to catch error happening AFTER the code / application
Hi all,
The dll I am using is from Microsoft. I already reported it to the Microsoft connect.
I am about 80% sure that the dll is what is wrong. I tried using it in 2 languages: C# and C++. Both languages error in exactly the SAME way.
I am also sure that I am using the DLL properly in C++, because I have used a similar DLL that requires the same code. This DLL however, is for a different function.
I would like to know if there is a way to make the error in the end 'silent'?
Thanks
-
September 14th, 2010, 03:07 AM
#5
Re: How to catch error happening AFTER the code / application
And, if it is not a big secret, - which one from hundreds or thousands of MS DLLs do you mean?
And again: you haven't provided enough info yet about how and where it crashed
Victor Nijegorodov
-
September 14th, 2010, 03:12 AM
#6
Re: How to catch error happening AFTER the code / application
Hi all:
Here is the code in order to provide more information:
Code:
#include "stdafx.h"
#include "ATLComTime.h"
#import "TSCore.dll" named_guids
#import "tsmediaapi.dll" named_guids
using namespace TsMediaLib;
int _tmain(int argc, _TCHAR* argv[])
{
::CoInitialize(NULL);
IPxeAuthClassPtr pxecls;
pxecls.CreateInstance(CLSID_PxeAuthClass);
VARIANT varDate;
VariantInit(&varDate);
COleDateTime mytime(1996,1,1,0,0,0);
varDate = _variant_t(mytime, VT_DATE);
_bstr_t name = "ab40c4ab-7e74-4740-9a09-e999e876edaa";
_variant_t out;
out = pxecls->CreateIdentity(name,name,name,&varDate,&varDate);
VariantClear(&varDate);
pxecls.Release();
::CoUninitialize();
cout << “END” << endl;
}
It reaches the "END" and then crashes with error:
TSMediaInterop.vshost.exe: Managed' has exited with code -1073741819 (0xc0000005).
Here is also a link to the DLL we are using (TsMediaApi.dll): http://msdn.microsoft.com/en-us/library/cc142946.aspx
Thank you!
Last edited by LeanA; September 19th, 2010 at 10:14 AM.
Reason: used code tags
-
September 14th, 2010, 03:30 AM
#7
Re: How to catch error happening AFTER the code / application
error code 0xc0000005 (access violation) is pointer error. when it occurs after unloading the dll it means that releasing of resources crashes what can happen if you didn't call a necessary initialisation routine or function.
You can do the following:
- add a return statement to your _tmain function (what is bad habit if it is missing)
- set a breakpoint to that return statement
- change your debug - exceptions - win32 settings so that the debugger stops
immediately before the access violation (0xc0000005) exception was thrown
The default is that it first tries to find a handler (in your case there is none) and that is why you don't get a break where the wrong pointer actualy was used.
-
September 14th, 2010, 09:58 AM
#8
Re: How to catch error happening AFTER the code / application
Hi itsmeandnobodyelse, thanks for replying.
I just tried what you suggested (add a return as well as the debug). The same error still occurs.
I was able to stop at the return breakpoint and managed to continue from that point. Right after that, when the code finishes, it crashes. The error said by Visual studio is still the same:
First-chance exception at 0x67e9bed0 in TSMediaC++.exe: 0xC0000005: Access violation reading location 0x0229feb0.
I really think that the DLL is what is wrong here, as I also tried it with C# but using a "Void" return type. May I ask if there is a way to make the error 'silent' or something?
Thank you!
Last edited by LeanA; September 14th, 2010 at 10:02 AM.
Reason: add info
-
September 24th, 2010, 02:16 AM
#9
Re: How to catch error happening AFTER the code / application
Try this - use smart pointers and scope them so they go out of scope before ::CoUnitialized is called.
Code:
#include "stdafx.h"
#include "ATLComTime.h"
#import "TSCore.dll" named_guids
#import "tsmediaapi.dll" named_guids
using namespace TsMediaLib;
int _tmain(int argc, _TCHAR* argv[])
{
::CoInitialize(NULL);
IPxeAuthClassPtr pxecls;
pxecls.CreateInstance(CLSID_PxeAuthClass);
// VARIANT varDate;
// VariantInit(&varDate);
COleDateTime mytime(1996,1,1,0,0,0);
// varDate =
_variant_t vDate(mytime, VT_DATE);
_bstr_t name( _T("ab40c4ab-7e74-4740-9a09-e999e876edaa") );
_variant_t out;
out = pxecls->CreateIdentity( name, name, name, &vDate, &vDate );
// VariantClear(&varDate);
//pxecls.Release();
} // end of scoping block
::CoUninitialize();
cout << “END” << endl;
}
-
September 24th, 2010, 10:57 AM
#10
Re: How to catch error happening AFTER the code / application
Hi All thanks for replying,
@Igor
Okay, thank you for your help.
@Arjay
I will try that and get back to you. Thank you for this!
Also, can anyone enlighten me as to why it does not error / crash when I compile using CTRL + F5 instead of just F5?
And since it does not error, is it possible to call the get a variable from C++ code I did and just input it to a C# code so that the error does not display (because the error does not happen in C++)?
Something like the C++ code is the one to instantiate the COM Class I need and perform the necessary methods, while the C# code just gets something from the C++ code.
Thanks!
-
September 26th, 2010, 09:01 AM
#11
Re: How to catch error happening AFTER the code / application
Originally Posted by Arjay
Try this - use smart pointers and scope them so they go out of scope before ::CoUnitialized is called.
Code:
#include "stdafx.h"
#include "ATLComTime.h"
#import "TSCore.dll" named_guids
#import "tsmediaapi.dll" named_guids
using namespace TsMediaLib;
int _tmain(int argc, _TCHAR* argv[])
{
::CoInitialize(NULL);
IPxeAuthClassPtr pxecls;
pxecls.CreateInstance(CLSID_PxeAuthClass);
// VARIANT varDate;
// VariantInit(&varDate);
COleDateTime mytime(1996,1,1,0,0,0);
// varDate =
_variant_t vDate(mytime, VT_DATE);
_bstr_t name( _T("ab40c4ab-7e74-4740-9a09-e999e876edaa") );
_variant_t out;
out = pxecls->CreateIdentity( name, name, name, &vDate, &vDate );
// VariantClear(&varDate);
//pxecls.Release();
} // end of scoping block
::CoUninitialize();
cout << “END” << endl;
}
Hi Arjay, thanks for this.
I just tested it and it errors the same (0xC0000005). However, based from my post above, I tried changing the CoInitialize to CoInitializeEx(0, Multithreaded) and CTRL + F5. It does not error!
Any idea why this happens?
Also, I like your code; cleaner than mine but seems to perform the same thing.
Thanks!
-
September 14th, 2010, 11:54 AM
#12
Re: How to catch error happening AFTER the code / application
Originally Posted by LeanA
Hi all,
The dll I am using is from Microsoft. I already reported it to the Microsoft connect.
I am about 80% sure that the dll is what is wrong. I tried using it in 2 languages: C# and C++. Both languages error in exactly the SAME way.
If you use the same code, of course you will get the same error.
I am also sure that I am using the DLL properly in C++
First, when posting code, use code tags. The code you posted is unformatted, and is double spaced, making it very hard to read.
Second, whatever you posted contains only a few lines. If a very simple program like that can break a DLL created by Microsoft, then hundreds, probably thousands of programmers would have noticed and reported it. Therefore, the problem is more than likely your code, not the DLL.
Regards,
Paul McKenzie
-
September 15th, 2010, 10:01 AM
#13
Re: How to catch error happening AFTER the code / application
Hello all thanks for replying,
Will try the 'cleaning' functions and get back to you.
Actually, I have seen some threads similar to the error I am experiencing with the same DLL. Microsoft said they will escalate it but no replies yet.
I have also reported it to Microsoft connect, but no replies yet also.
Thank you
-
September 15th, 2010, 10:30 AM
#14
Re: How to catch error happening AFTER the code / application
Hi all, thanks for replying
@itsmeandnobodyelse
I tried commenting out the ones you mentioned, however, the error still occurs.
I added 0xC0000005 to the Exception in Debug->Exception. Since I added the 0xC0000005 Exception to Debug->Exception, I start to Break at "CoUninitialize" instead of the end of the program.
If the CoUnitilize is available, the Debugger breakpoints there. However, if the CoUnitialize is commented out, First-Chance exception occurs instead on this code block, specifically in __crtExitProcess(code):
Code:
#endif /* CRTDLL */
}
#endif /* _DEBUG */
}
/* return to OS or to caller */
__FINALLY
if (retcaller)
_unlockexit(); /* unlock the exit code path */
__END_TRY_FINALLY
if (retcaller)
return;
_C_Exit_Done = TRUE;
_unlockexit(); /* unlock the exit code path */
__crtExitProcess(code);
}
The file that it errors to is called "crt0dat.c".
I tried adding try-catch but it does not catch the error. I think this is because the error happens outside the code, going out of the try-catch.
Actually, even if I don't use its function "CreateIdentity", just initializing PxeAuthClass makes the error. This is both for C++ and C#.
Thank you
PS. Sorry for not using CodeBlocks / Quotes. For some reason, the option does not appear when I reply.
Last edited by LeanA; September 19th, 2010 at 10:15 AM.
Reason: used code tags
-
September 15th, 2010, 01:06 PM
#15
Re: How to catch error happening AFTER the code / application
According to the docs
A thread must call CoUninitialize once for each successful call it has made to CoInitializeEx
CoUninitialize only may be called for a call to CoInitializeEx.
So, I would try to call CoInitializeEx and explicitly pass the needed threading model.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|