-
September 19th, 2010, 10:12 AM
#16
Re: How to catch error happening AFTER the code / application
Hi all, thanks for replying
@itsmeandnobodyelse
I tried using HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED); as well as HRESULT hr = CoInitializeEx(0, COINIT_APARTMENTTHREADED);.
Unfortunately, both failed.
@ADSOFT
I tried removing that but it errors. Just initializing the PxeAuthClass using errors.
Code:
IPxeAuthClassPtr pxecls;
hr = pxecls.CreateInstance(CLSID_PxeAuthClass);
Might you have some suggestions how to 'silence' this error so that if I run the .exe program, it will not crash?
Thank you!
-
September 19th, 2010, 10:44 AM
#17
Re: How to catch error happening AFTER the code / application
Originally Posted by LeanA
Hi all, thanks for replying
@itsmeandnobodyelse
I tried using HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED); as well as HRESULT hr = CoInitializeEx(0, COINIT_APARTMENTTHREADED);.
Unfortunately, both failed.
@ADSOFT
I tried removing that but it errors. Just initializing the PxeAuthClass using errors.
Code:
IPxeAuthClassPtr pxecls;
hr = pxecls.CreateInstance(CLSID_PxeAuthClass);
Might you have some suggestions how to 'silence' this error so that if I run the .exe program, it will not crash?
Thank you!
It's been a while since I've done COM stuff. Maybe even if you initialize a COM object you have to delete the object before the program ends. Others that are doing COM stuff might be able to jump in.
If it were me I would do two things.
1) Look for example on how to use IPxeAuthClassPtr. I did a search, there IS some stuff out there.
2) Brush up on programing with COM objects. Once you know that you should be able to determine if the COM object is working properly. The problem with sample COM code is that they assume you know how to use COM components. There is alot of stuff out there on using COM objects (initializing, terminating, etc).
Rate this post if it helped you.
-
September 21st, 2010, 06:21 AM
#18
Re: How to catch error happening AFTER the code / application
Hi again, thanks for replying
Ok, I will do that also thank you.
I just found out something weird.
In my C++ code, if I compile and run the code using "CTRL + F5", the error does not occur! The .exe produced also works and does not error.
However, in C#, compiling and running using "CTRL + F5" still errors.
Can anyone enlighten as to why this happens? I think that CTRL + F5 means that "without debugger", but I am wondering why it does not work with C#.
PS. Also, 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++)? Basically, 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.
Thank you!
Last edited by LeanA; September 21st, 2010 at 06:23 AM.
-
September 21st, 2010, 07:20 AM
#19
Re: How to catch error happening AFTER the code / application
Well, typical COM-aware code goes like this:
Code:
// headers and similar stuff
int _tmain(bla-bla)
{
HRESULT hrInit = ::CoInitialize(NULL);
if (SUCCEEDED(hrInit))
{
// here you go with smart pointers to COM objects and objects creation
. . .
// and usually no explicit Release required to those
}
if (SUCCEEDED(hrInit))
::CoUnintialize();
return 0;
}
Please note, there's no smart pointers in _tmain root scope, there you only init/deinit COM.
Best regards,
Igor
-
September 23rd, 2010, 08:24 AM
#20
Re: How to catch error happening AFTER the code / application
Hi Igor, thanks for replying;
I would just like to clarify if you mean by "COM-aware" is managed code?
So in C#, the CoInitialize and CoUinitialize is defined in a similar manner like the one you posted?
Also, is it possible to disable the automatic calling of the above and just manually call CoInitialize and CoUnitialize in C#?
Thank you!
-
September 23rd, 2010, 09:10 AM
#21
Re: How to catch error happening AFTER the code / application
No, it's all about regular C++ code. And sorry, I do very little of C# programming and none of managed C++.
Best regards,
Igor
-
September 23rd, 2010, 10:58 AM
#22
Re: How to catch error happening AFTER the code / application
Originally Posted by Igor Vartanov
No, it's all about regular C++ code. And sorry, I do very little of C# programming and none of managed C++.
I used to code in C# and had to drop it because C# doesn't offer challenging coding techniques and it uses only a subset of windows internals with a large number of functionalities, which is why things becomes easier with C#. The most beautiful integrated part it plays is to be with active pages
Well I saw D, now see F# in my VS10 install disc
-
September 24th, 2010, 02:04 AM
#23
Re: How to catch error happening AFTER the code / application
Originally Posted by HochiminhCity
I used to code in C# and had to drop it because C# doesn't offer challenging coding techniques and it uses only a subset of windows internals with a large number of functionalities, which is why things becomes easier with C#.
So you prefer to code in an environment that's more challenging?
-
September 24th, 2010, 02:16 AM
#24
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
#25
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, 08:59 AM
#26
Re: How to catch error happening AFTER the code / application
Originally Posted by LeanA
Hi again, thanks for replying
Ok, I will do that also thank you.
I just found out something weird.
In my C++ code, if I compile and run the code using "CTRL + F5", the error does not occur! The .exe produced also works and does not error.
However, in C#, compiling and running using "CTRL + F5" still errors.
Can anyone enlighten as to why this happens? I think that CTRL + F5 means that "without debugger", but I am wondering why it does not work with C#.
PS. Also, 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++)? Basically, 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.
Thank you!
Hi all,
I just clarified this. If I use
Code:
CoInitialize(NULL);
and press CTRL + F5, it still errors (0xC0000005).
However! If I use
Code:
CoInitializeEx(0, COINIT_MULTITHREADED);
and press CTRL + F5, it does not error!
Just pressing F5 either way (CoInitialize and CoInitializeEx) will result in an error.
I'm wondering why this is happening. Anyone has an idea?
Thank you!
-
September 26th, 2010, 09:01 AM
#27
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!
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
|