Re: runtime error when setting pointer to interface to NULL
* Daniel:
I am getting an error when I try to run the following code when I set the
variable to NULL?
#import "..\Orchestra\Orchestra\Debug\Orchestra.dll"
using namespace OrchestraLib;
DWORD WINAPI ThreadFunction(LPVOID lpvParameter);
int _tmain(int argc, _TCHAR* argv[])
Just in passing, using the Microsoft's braindead "T" functionality is an almost
sure way to screw up. Have you tried compiling your code as both Unicode and
ANSI? My guess is that one of those will not compile, and then "T" is just
misleading and a source of complexity and trouble; don't use it.
{
::CoInitializeEx(NULL,COINIT_APARTMENTTHREADED);
IClarinetPtr spIClarinet;
spIClarinet.CreateInstance(__uuidof(Clarinet));
spIClarinet->Sound(1000, 1000);
spIClarinet->Release();
You're messing up the reference count.
The smart pointer has no idea and no way to know that you're calling Release on
the referenced object.
spIClarinet = NULL;
The error happens in comip.h at the point below:
Not surprising, but be happy that it's detected in some way.
This code is invoking Undefined Behavior where there's no guarantee that such
things will be detected.
Cheers, & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?