|
Sort of, tha last m_pMyCtl = NULL is redundant (or the first one, if you prefer )
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Well, I tried checkd if my pointer was NOT NULL. and then delete myptr and then myptr = NULL but the compiler said something with memory problems... bla bla... damn I can't remember the debug error...
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
You probably forgot to initialize myptr to NULL in the first place. Read Nish's answer below for a better explanation about the scheme to follow.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Rickard Andersson wrote:
delete m_pMyCtl;
m_pMyCtl = NULL;
m_pMyCtl = NULL;
This is what Joaquín meant :-
pVar=NULL;
...
...
...
pVar = new blah blah;
...
...
...
delete pVar;
pVar=NULL;
Now from whereever in your code you can do a :-
if(pVar) to know if it is allocated or deleted.
Nish
Bow wow wow,
Yippee yo yippee yay,
My miniputt high,
Is now 30 yay.
|
|
|
|
|
"If there is insufficient memory for the allocation request, by default operator new returns NULL" - MSDN
Nish
Bow wow wow,
Yippee yo yippee yay,
My miniputt high,
Is now 30 yay.
|
|
|
|
|
This does is not true when using MFC. In MFC use exceptions to detect out of memory situations:
int *ptr1 = 0;
try
{
ptr1 = new int[10];
}
catch (CMemoryException *ex)
{
delete [] ptr1;
}
(2b || !2b)
|
|
|
|
|
Nor is it true with VC7 (that is unless you force it to use the VC6 new.)
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Good to know!
(2b || !2b)
|
|
|
|
|
I have to keep a few extra bytes in a data file when it is being created. But when the file is finished, these bytes have to be thrown away. I cannot have another copy of the file since it may be huge, and I have to put those bytes in the file for it may be moved away or deleted. That means I have to shorten the file.
I'd be very thankful for any good idea about truncating a file.
Tiny Flying Elephant
I love flying...
|
|
|
|
|
|
Setfilesize may do the same work!
Please pardon my weak English!
|
|
|
|
|
I have a hook dLL that I'd like to send a message back to the calling app.
Something like......
keyboard hook detects that F2 is pressed
dLL sends message to app
app shows dialog
main code in dLL as follows
///////////////////////////////////////////////////////////
#define WM_APPSTARTED WM_USER + 100
#pragma data_seg(".shared")
HWND g_mainWnd = NULL; //the server window handle
HHOOK g_hShellHook = NULL;
HHOOK g_hKeyboard = NULL;
#pragma data_seg()
#pragma comment(linker, "section:.shared,rws")
SYSDLL_API BOOL _Startup(HWND hwnd)
{
g_hKeyboard = NULL;
g_mainWnd = hwnd; // g_mainWnd is the main window handle
g_hKeyboard = SetWindowsHookEx(WH_KEYBOARD, MyProc, g_hInstance, 0);
if(g_hKeyboard == NULL)
MessageBox(HWND_DESKTOP, "hook fail", "BLAH", MB_OK);
if(g_mainWnd != NULL)
return FALSE; // already hooked!
g_hShellHook = SetWindowsHookEx(WH_SHELL, MyShellProc,g_hInstance, 0);
if(g_hShellHook != NULL)
{
g_mainWnd = hwnd;
return TRUE;
}
return FALSE;
}
SYSDLL_API LRESULT CALLBACK MyShellProc(int ncode, WPARAM wparam, LPARAM lparam)
{
if(ncode < 0 )
return CallNextHookEx(g_hShellHook, ncode, wparam, lparam);
if(ncode == HSHELL_WINDOWCREATED)
{
HWND hfoundApp;
hfoundApp = FindWindow(NULL, TEXT("my_window" ) );
if(hfoundApp)
{
PostMessage(hfoundApp, WM_APPSTARTED, lparam, wparam);
}
}
this is where I'd like the dLL to send a message to the callin app
but the message never gets to the app
thanks for your time
|
|
|
|
|
Hi,
I am a beginner in MFC and I am working on the tab controls. However, I don't really know how it works. Can anyone demonstrate to me how to use it?
thank you
|
|
|
|
|
(In VC6.0,using MFC)
I created a list control(by CListCtrl).Here,i met a little problem
:i input a string,then i told the list control to search in its items whether there's a item contains it.If
there's one does contains,how can i highlight this item and scroll the window automaticly to make the item appear on my screen?
God blessing me...
|
|
|
|
|
Try this:
int viFoundThisItem = 4;
m_ctrlMyList.SetItemState(viFoundThisItem, LVIS_SELECTED, LVIS_SELECTED);
m_ctrlMyList.EnsureVisible(viFoundThisItem, FALSE);
Hope this helps.
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
I don't want keep on asking so many questions, so is here has something like faq which has already collect most question asked here and answer. that would be great.
|
|
|
|
|
The FAQ link is just above this post, on the right hand side, in the orange bar.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|
|
http://www.codeproject.com/useritems/cppforumfaq.asp
Copy/paste that into Start-Run
Nish
Bow wow wow,
Yippee yo yippee yay,
My miniputt high,
Is now 30 yay.
|
|
|
|
|
there are some misunderstand, the faq on the top is talk about how to deal with this message board. i just want a faq that collect the question&answers on this message board about vc programming.
|
|
|
|
|
Gosh! Scroll down man...
It is titled " Mike Dunn's C++ FAQ ".
You seriously dont think that he'd name it that if it was a FAQ about the Lounge.
Nish
Bow wow wow,
Yippee yo yippee yay,
My miniputt high,
Is now 30 yay.
|
|
|
|
|
Hi,
I want to teach myself COM, I'm an experience Visual C++/MFC progammer, can anyone recommend a book?
Thanks,
Stuart
|
|
|
|
|
Well there are two approaches:
COM is a model or a paradigm, and the developers that I have met that have read and understand the theory, go alot farther, and are able to do alot more with COM. Therefore I would recommend Don Box's book on Essential COM for theory.
You are notreally going to absorb it until you practice it. I do not have any books that explain COM in MFC, except Jeff Prosise's Programming Windows with MFC, however, it only glosses over the topics.
If you are interested in ATL, which I think is a cleaner way of programming with COM since that is what it was conceived to do, then I would recommend Brett Rector's and Chris Sells' ATL Internals.
With these two books and all of the examples in MSDN, I have had no problem learning anything that I wanted to do in COM.
|
|
|
|
|
Hi guys
when i execute this code
void main ()
{
float x=3/2;
cout<
|
|
|
|
|
Mohe wrote:
float x=3/2;
A computer is only smart enough to operate on two items at a time. If you break your statement in question down into its simplest parts, 3 is an integer, and 2 is an integer. When the compiler performs an operation on these two numbers, it does integer division which results in 1.
In order to fix this, make one or both of the parameters floats like this:
float x=3.0 / 2;
float x=3 / 2.0;
float x=3.0 / 2.0;
Then you will get the result that you expect.
|
|
|
|
|
How can I modify an environment variable such that the changes are made to the registry, so that they are propagated to others when system restarts or some new application starts? The SetEnvironmentVariable API updates the environment for the current process only.
Thanks,
Krishnan
|
|
|
|