|
There are a limited number of device contexts available at any one time. Every time this executes, you are locking one of these DCs with GetDC() but not releasing it with ReleaseDC() . Eventually, there will be no DCs available, and GetDC() will return NULL . Since you're not doing any error checking, you'll get a NULL-pointer exception while trying to call GetPixel() .
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Two questions:
One, can interface methods have default parameters? i.e.
HRESULT MyMethod ([in] int size = 0) Two, can a class that implements and interface have a constructor with paramaters?
Thanks!
- Aaron
|
|
|
|
|
hi
One - Yes, An interface method can have parameters with default values provided the parameter shud be optional too. The parameter settings while creating the function defenition in IDL is as fllows:
[in] short i, [in] short j, [in, out, optional, defaultvalue(117)] short* k, [out, retval] short* l
and the c++ function signature will be:
STDMETHODIMP MyClass::Test(short i, short j, short *k, short *l)
Two - A class that implimets an interface can have constructor with parameters. But no way to use that . If you use CoCreateInstance to create the client then we can't use the c++ class name directly and so cunstructor parameter also. Only way where we can use the c++ class name to create the com class is CComObject<MyClass> . But even this CComObject does not accept constructor initializers.
rgds...mil10
|
|
|
|
|
In a support library I'm developing which is serving as the foundation of an application I'm working on, I've provided a whole bunch of augmented debug functionality. For example, if I hit an assert, the replacement assert implementation logs this sort of thing to a file and to OutputDebugString:
---- ASSERT LOG OPENED ----
Version 0.7.4.1
assertion failure 5/12/04, 16:49:42.353738
File: btlocalclient.cpp
Line: 1086
Expression: Unrecognized command in BTLocalClient_t::AsynchMessageReceived
Call stack: 0x00417B93 (BTLocalClient_t::AsynchMessageReceived +0x542, btlocalclient.cpp line 1086)
0x004F15D1 (AsynchMessageTrigger_t::Triggered +0x60, asynchmessagetrigger.cpp line 93)
0x004F6E88 (EventServer_t::ThreadFunction +0x387, eventserver.cpp line 284)
0x0042F8BF (BTServer_t::ThreadFunction +0x2E, btserver.cpp line 93)
0x004F6A01 (EventServer_t::ThreadFunctionEntryPoint +0x70, eventserver.cpp line 174)
0x1020BFD2 (UNKNOWN)
0x7C57B382 (UNKNOWN)
I'm providing that detail so no one asks "why are you replacing assert" - the utility should be clear and MS should have done a better job of providing this sort of info.
Anyway... One part of this support library is an EventServer object running in a thread, servicing EventTrigger objects by WaitForMultipleObjects - EventTriggers have an associated triggler HANDLE of one kind or another - could be an event, could be a TCP/IP socket, could be a device handle doing asynchronous I/O, that sort of thing. The server thread is servicing a remote client server and device objects controlling Bluetooth ASICs. An EventServer running at critical priority is a necessary part of the application I'm working on. Anyway every once in a while during the development process I introduce a bug where the code gets stuck in a loop. At critical priority, that brings my system to its knees and depending on how bad it is, I can't get over to Visual Studio to hit the pause button on the debugger. So I just added a feature to the event server where, optionally, another thread watches it and if the event server stops punching a watchdog (to borrow a metaphor from hardware engineering) then the watcher thread suspends the event server and pops up a dialog indicating that the event server stalled, abort retry ignore, all that.
I caught the case where the event server has hit an assert and is therefore legitimately not punching the watchdog...assert puts the watchdog to sleep. But what if I set a breakpoint? Once I start stepping through code, the watcher thread fires almost immediately.
What I wanted to do was catch EXCEPTION_BREAKPOINT and put the watchdog to sleep in that situation. I already have a __try exception handler so that address exceptions for example get turned into asserts and log the info shown up above, the call stack and everything. I augmented it as follows:
int
ExceptionFilter( unsigned int code, struct _EXCEPTION_POINTERS *ep )
{
g_exception_context = ep->ContextRecord;
if(code == EXCEPTION_ACCESS_VIOLATION)
release_error("Access violation");
else if(code == EXCEPTION_INT_DIVIDE_BY_ZERO)
release_error("Integer divide by zero");
else if(code == EXCEPTION_PRIV_INSTRUCTION)
release_error("Privileged instruction");
else if(code == EXCEPTION_ILLEGAL_INSTRUCTION)
release_error("Illegal instruction");
else if(code == EXCEPTION_NONCONTINUABLE_EXCEPTION)
release_error("Noncontinuable exception");
else if(code == EXCEPTION_GUARD_PAGE)
release_error("Guard page violation");
ADD else if(code == EXCEPTION_BREAKPOINT)
ADD {
ADD debug_printf("Why isn't this working???\n");
ADD EventServer_t::PauseCurrentThreadStallWatcher();
ADD }
g_exception_context = NULL;
return EXCEPTION_CONTINUE_SEARCH;
}
But it didn't work...EXCEPTION_BREAKPOINT isn't raised, or at least isn't able to be caught using __try.
Does anyone know what EXCEPTION_BREAKPOINT is for, will it work for what I'm trying to do if I do something a bit different?
Alternatively, does anyone know of a way that the watcher thread can determine whether the debugger has been active recently, like having just set a breakpoint and released the debuggee to do a "step out of function"? IsDebuggerPresent() isn't good enough because that returns TRUE whenever I'm in the debugger, that says nothing as to whether I'm stepping through code.
Thanks,
Brian
|
|
|
|
|
Breakpoint exceptions are not raised when the debugger is single-stepping. Try checking for EXCEPTION_SINGLE_STEP instead. If that doesn't work, I'm as stumped as you are...
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Just a quick question...is it possible to use these two libraries in VC6 or do you have to have VS.NET in order to use them. Thanks.
- Aaron
|
|
|
|
|
|
|
Greetings,
I'm trying to display simple debug messages from the constructor and destructor of a class (we'll call it MyClass.) I have a simple CDialog based project and if I declare a member object of MyClass in the main dialog class definition, I expect to see the "MyClass::MyClass()" message box when starting the app and the "MyClass::~MyClass()" when closing the app. The destructor message is never displayed. I've used ::MessageBox() and AfxMessageBox() and I've tried NULL and ::GetDesktopWindow() as the hWnd param to ::MessageBox.
Of course, if I just locally create and destroy the object in a function body (such as a button click event), then I see both messages.
Can anyone clue me in as to why this is happening? Does it have something to do with the fact that the main dialog has already been destroyed when the member MyClass object's destructor is called?
Thanks,
Justin
|
|
|
|
|
If this is an MFC app, make sure you don't have the line
m_pMainWnd = &dlg
in CYouWinApp::InitInstance.
|
|
|
|
|
Thanks. That was the problem. Does that work because the main dialog isn't really the main window, so if you set m_pMainWnd to the dialog, when you kill the dialog, the app prematurely teminates? (I read the MSDN docs, but I'm not totally clear on it yet.)
Thanks,
Justin
|
|
|
|
|
Er well it works because of the way DoModal works. Each (UI) thread has a message pump as im sure u know, and in MFC, that pump is usually started by returing true from InitInstance. When you call DoModal on a dialog - you want that call to block until the dialog is closed - and you also want to continue to pump messages while waiting. MFC does that by running another message pump within DoModal, that runs until EndDialog is called and then passes control back out to the "outer" pump. That all apples if your not using a dialog for you "main" window.
When the message pump in DoModal comes across a WM_QUIT message, it handles it differently. Its the outer pump that must process this quit message, so it reposts another WM_QUIT message and then exits it's loop. If you have m_pMainWnd set to anything other than NULL, then the WM_QUIT message is reposted.
Once a thread has received WM_QUIT, calling GetMessage/PeekMessage will do nothing. Internally, a MessageBox also pumps and process messages - so if you have a non-null m_pMainWnd, your message box will start it's own message pump, and will get the WM_QUIT message which was reposted - and exit.
If you set m_pMainWnd to NULL, the WM_QUIT message is esentially swollowd by the message pump in DoModal - even though the DoModal loop exits, the WM_QUIT doesn't get reposted, and hence the message box doesn't pick it up. The app is then exited via returing false at the end of InitInstance.
|
|
|
|
|
Hi-
I have some source code (samples) that will be distributed with an API. I'd like the samples to be in source control of course, but I'm not sure the proper way to remove source control for distribution. (So customers don't get a message like: "This project appears to be under source control, but ...")
Can this process be easily automated with an installer such as Nullsoft's NSIS? It should be clear, but I don't want to remove source control entirely, just for the distributed code.
|
|
|
|
|
Hello, i hope you can help me,
Ik need a program for instance a .exe file that when it runs it holds the image of my entire screen, meanwhile a other program is changing information and it had to fade into the current screen total time +/- 1 sec and then the program closes again. Is this possible? if yes please tell me how i can make this. I am not a verry good programer in c++ or maybee you can help me with it.
Thanks Johan
|
|
|
|
|
If you're using W98 or above, there is an AlphaBlend function that you can use to make your image fade.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Hi
I made a class that it's header does not include any other files..
however, when i used MAX_PATH (defined in windef.h ) it compiled well.
how that comes ? shouldn't i include windef.h or a file that includes it to use MAX_PATH ?
(others classes include stdafx.h but this one doesn't)
also how can I make such a (global #define ) ?
|
|
|
|
|
A header file isn't actually compiled, it's just #included.
When you #include your header it's effectively added into the source code of whatever file you included it in. So if you #include some other file with a #define it it before you #include your header file then your header will get the benefit of that #define making it look like the #define was some kind of "global".
For example, consider these files:
yourheader.h
#define MAX_PATH 256
myheader.h
typedef struct {
int FileID;
char FileName[MAX_PATH];
}FILE
mycode.cpp
#include "yourheader.h"
#include "myheader.h"
FILE myfile;
In this case yourcode.cpp will effectively look like this:
#define MAX_PATH 256
typedef struct {
int FileID
char FileName[MAX_PATH]
}FILE
FILE myfile;
So the fact that you didn't #define MAX_PATH in yourheader doesn't actually make any difference.
By the way, the order of the #includes effects this so if you changed yourcode.cpp to be
#include "myheader.h"
#include "yourheader.h"
FILE myfile;
you'd get a compile error because you'd use MAX_PATH before it's been #defined.
Hope that helps.
|
|
|
|
|
...I know how #include works .. but the problem here is that (as i mentioned in the post) I did NOT include windef.h
but MAX_PATH still can be used !!
|
|
|
|
|
So you didn't #include windef.h (or any other header file which #includes it such as windows.h) anywhere else in your project?
|
|
|
|
|
it's included in other classes..
but not in this specific class or in any headers included in this class
|
|
|
|
|
There is no such thing. You've included this file without knowing it, probably it's listed as an include in the project settings. If you don't include it, it's not included. Simple as that.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
We can create functions that return values like :
<br />
CString my_function()<br />
{<br />
CString my_string="whatever";<br />
return my_string;<br />
}<br />
BUT I NEED A FUNCTION THAT MAY BE ABLE TO RETURN A CStringArray OBJECT OR SOMETHING SIMILAR WITH SOME DATA !! I mean, something like this:
<br />
CStringArray my_function()<br />
{<br />
CStringArray my_array;<br />
my_array.Add("VALUE1");<br />
my_array.Add("VALUE2");<br />
return my_array;<br />
}<br />
THANKX !!!!
|
|
|
|
|
If an object has a copy constructor you can do it. It might even be optimized to not be a performance nightmare.
For anything but a trivial return value, I prefer passing a reference to the object to be "returned."
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Could you show me an example please ??
I'm really thanked...
|
|
|
|
|
void my_function(CStringArray& my_array)
{
my_array.Add("VALUE1");
my_array.Add("VALUE2");
}
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|