|
DavidCrow wrote: Actually, it should only fire if the address pointed to by pInt was not contained entirely within the program’s memory space.
Yes, that's what the API does. This doesn't contradict my statement. The OP wanted to know how to tell if memory "was allocated by the application and can be used without problem". AfxIsValidAddress was put forward as a solution and the OP accepted it claiming that it worked. I pointed out that if this API could be used to perform this function then the ASSERT in the code below should fire as AfxIsValidAddress should return FALSE given that it is surely not safe to use a pointer after it has been deleted:
int *pInt = new int;
delete pInt;
ASSERT( AfxIsValidAddress(pInt, sizeof(int)) );
This is not the case. If you try this code AfxIsValidAddress returns TRUE and thus the ASSERT will not fire. Why? Because the address pointed to by pInt was entirely contained in the process’s address space. It's cached by the heap (the small block heap in this case) for recycling. So the problem is that just because an address is physically mapped into the process's address space doesn't mean it's safe to use.
In general these APIs can only be used to tell if memory can't be safely used but not to tell if it is safe to use.
Steve
|
|
|
|
|
Best programs always handle the pointers validity by checking NULL or not. for this you should cautious about allocation and de-allocation
SaRath.
"Do Next Thing..."
My Blog | Understanding State Pattern in C++
|
|
|
|
|
hatemtalbi wrote: does someone know how to check if a pointer is valid (was allocated by the application and can be used without problem) or no?
When you ask that question something is wrong in your code. You should never have to check if a pointer is 'valid'.
|
|
|
|
|
I agree 100%. You get a five for making so much sense.
Steve
|
|
|
|
|
Hi,
i need to know a way to read the motherboard sensors (temp, speed...) using C++. Just like MBM.
Grateful!
Honae
Edit/Delete Message
|
|
|
|
|
Have you checked out the various WMI classes?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I wanna do that withou WMI.
|
|
|
|
|
Why, especially when that's the most logical solution?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Because i wanna do something with the less requirements. Wmi does not work in win 95/98/ME. For that is necessary to install the resource.
|
|
|
|
|
honae wrote: Because i wanna do something with the less requirements.
Which means what exactly? What requirements?
honae wrote: Wmi does not work in win 95/98/ME.
Sure it does.
honae wrote: For that is necessary to install the resource.
What resource?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
WMI is not integrated in win95/98/ME like is in winxp for example. It is necessary to install WMI resource on this case. I don't want this. I wanna to do some application in the lower level using C++. Do you know the software called MBM (motherboard monitor)? I wanna do something like that, but more simple.
I could use the MBM, but it would be a requirement also. I want that my application makes everything, understands?
|
|
|
|
|
honae wrote: WMI is not integrated in...ME
Actually, it is. For Windows 95 OSR 2, Windows 98 or Windows NT v4.0, a WMI installation package can be downloaded from Microsoft.
honae wrote: I want that my application makes everything, understands?
I understand, but I do not know of a solution that meets that requirement.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi,
Is there a way to append text to a rich edit box without using SetSel/ReplaceSel? The problem is that the text is highlightable, and if the user is highlighting text, then receives a chat message, which runs in a separate thread, sometimes the mouse dragging will set the selection to within the chat history and replace the highlighted history instead of appending to the end of the editbox.
Thanks!
Kelly Ryan
|
|
|
|
|
In that case you just have to ensure that all accesses to your rich edit box all happen on your main (GUI) thread. When you get data on your seperate thread, post a user defined message to your gui thread and have the handler of that message do the appending (remember to save and restore the current user selection).
|
|
|
|
|
Oh yeah.. I was thinking I'd still run into shared memory problems if I set up an event queue but if I just post a windows message I won't have to worry about memory locking or anything. Great, thanks!
Kelly Ryan
|
|
|
|
|
i load menu using this code
CMenu* menu2=AfxGetMainWnd()->GetMenu();
CMenu* submenu = menu2->GetSubMenu(0);
submenu->AppendMenu(MF_STRING, MF_BYPOSITION,m_SongName );
how can i add click event to this menus
-- modified at 9:46 Monday 26th June, 2006
|
|
|
|
|
Add handler for ON_COMMAND_RANGE depends on the ID receiving inside the function, you could handle it.
don't forget to specify the menu ID within the range
Sample from MSDN
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_COMMAND_RANGE(ID_FILE_MENUITEM1, ID_FILE_MENUITEM3, OnFileMenuItems)
END_MESSAGE_MAP()
void CMainFrame::OnFileMenuItems(UINT nID)
{
CMenu* mmenu = GetMenu();
CMenu* submenu = mmenu->GetSubMenu(0);
submenu->CheckMenuRadioItem(ID_FILE_MENUITEM1, ID_FILE_MENUITEM3,
nID, MF_BYCOMMAND);
}
SaRath.
"Do Next Thing..."
My Blog | Understanding State Pattern in C++
|
|
|
|
|
Hello
sir i'm getting assertion error in my program.
actually this error comes in winocc.
here
ASSERT(::IsWindow(m_hWnd));
My Code is:-
void
CTESTsipXtapiDlg::handleOffering(SIPX_CALL hCall)
{
SetDlgItemText(IDC_STATIC_NEW_CALL,"New Incoming Call");
}
just i want to display this msg in any text box or in label control of Dialog.
My application is a Dialog Based Application.
thanks
|
|
|
|
|
It seems as if you call SetDlgItemText() before the window/control is created.
AFAIK, the earliest time you can (programmaticly) set text to a window is in OnInitDialog().
|
|
|
|
|
hello
i cann't do it..
becoz when a call comes to my PC i have to show the caller id in it.
yes i'm feeling the same becoz when i trace it then i found that hWnd value is NULL.
plz tell me how to recify this error.
thanx
|
|
|
|
|
The simple solution would be to just do a null-check on the m_hWnd handle. If it is null, skip the set call. A more thorough solution might be to figure out why you are trying to set a window's text prior to creation to begin with. I've seen many people deal with communication-type code where they initialize the communications port (serial, ethernet, etc) in the application's InitInstance method and wonder why they have problems (a better solution in many cases is to do that initialization from the OnInitDialog/OnInitialUpdate method in the dialog or view class).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
You can test ::IsWindow(m_hWnd) yourself. If ::IsWindow(m_hWnd) returns FALSE, then you can buffer the message(s). (Or write them to a file).
Then, in the OnInitDialog, you can update the window with the buffered messages.
But it seems a bit peculiar to me that the app exists and is running, but the window doesn't exist (yet) ...
|
|
|
|
|
hello
yes this is exactly i'm not getting if appication is running but the window does not exist at all.and hwnd=NULL.
My Application is a Dialog Based Application.
i cannot do as u said becoz in my application when Any one will call to My PC then when i will set the Caller id.
plz help me how to reinitialize the hwnd.
byee
|
|
|
|
|
Have a look at the response from Zac Howland. It should give you the solution to your problem.
|
|
|
|
|
kakan wrote: AFAIK, the earliest time you can (programmaticly) set text to a window is in OnInitDialog().
Make sure the base implementation (of OnInitDialog() ) has been called first. That's when the controls get created.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|