|
Why should it not be null? That's what you set it at. Passing the address of the pointer can make it modify it but just passing the pointer itself won't modify it. Let me explain.
See the code and the two functions below. Since you are not giving the address of the pointer to the first one, the pointer is not changing from null, it is only valid inside of your function.
char *sz = NULL;
func1(sz);
//sz is still null here.
func2(&sz);
//ok now sz is changed.
func1(char *sz)
{
sz = new char[1024];
strcpy(sz, "blah");
}
func2(char **sz)
{
*sz = new char[1024];
strcpy(*sz, "blah");
}
This is probably what you want your code to do:
CApproach approach; //notice, not a pointer.
GetNextApproach(&approach);
-- Rocky Dean Pulley
|
|
|
|
|
Ok, I think I am understanding now.
This is valid because the function is changing the contents of where the pointer I am passing in points to, not the actual value of the pointer itself.
char g_code[APP_AIRPORT_CODE_SIZE + 1];
GetCode(g_code);
GetCode(char* code)
{
strcpy(code, "Code");
}
However this does not work as I expected because I am trying to change the actual value of the pointer g_code:
char* g_code;
GetCode(g_code)
{
g_code = GetPointerToArraysomeOtherPlace();
}
Please let me know if I am still in la la land.
Thank you for your answers.
Kevin Shaffer
kshaff03@msn.com
|
|
|
|
|
rocky_pulley wrote:
This is probably what you want your code to do:
CApproach approach; //notice, not a pointer.
GetNextApproach(&approach);
Yes, except I don't want to make a copy, I just want to reference an object that is already created.
I also want to know, if I did the following, this would create a memory leak, right?
CApproach approach;
GetNextApproach(&approach);
GetNextApproach(CApproach* approach)
{
approach = GetAddressOfApproachSomePlaceElse();
}
Kevin Shaffer
kshaff03@msn.com
|
|
|
|
|
it's not a copy, he passing approach by reference.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
If, GetAddressOfApproachSomePlaceElse() calls new, then yes, this would be a memory leak. If in your function you want to change what object a pointer points to (not the object itself, but what object it points to), then one technique is to pass it a pointer to a pointer.
CApproach* pApproach = NULL;
GetNextApproach(&pApproach)
void GetNextApproach(CApproach** ppApproach)
{
*ppApproach = GetAddressOfApproachSomePlaceElse();
}
If you simply pass it a pointer, then it makes a copy of the pointer (not a copy of the object, but a copy of the pointer to the object). Any changes you make to the pointer (not the object, but the pointer to the object) will not be kept when the function returns, they are thrown away with the copy of the pointer.
Hope this helps,
Tim
|
|
|
|
|
The correct approach would be:
CApproach* approach = GetNextApproach();
The other responses solve the problem ( not passing by reference ), but they ignore the fact that you're passing null in, all you want is for the value to be returned.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
I want to include the Outlook2Ctrl in a program, but I also want to split the right side area ( which is the remaining part ) horizontally into two panes.
I used a class derived from CSplitterWnd (by Daniel Zuppinger) and it's on this site. But I couldn't do it.
I tried to split, first vertically [CView || NULL]
then using the NULL pane I splitted the right vertically. But couldn't include the Outlook2Ctrl in the CView place.
Please help me...even by a hint...even not using the upper-mentioned splitter class.
Thanks
|
|
|
|
|
It sounds like you need to create your own class that inherits directly from CView, then add the Outlook2Ctrl control to that window. When the window is resized, call MoveWindow on the outlook control to make it the same size as the view.
-- Rocky Dean Pulley
|
|
|
|
|
The author of the Outlook2Ctrl had written "the outbar docks normally on the left side of the main frame", and in his demo, he included the Control in the MainFrame directly. So I am not sure, probably this control was meant to use some properties of the CFrameWnd class.
I didn't sail into the class itself (Outlook2Ctrl) yet, because of the lack of time. And I thought that probably someone has done what I am looking for now.
Anyway, thanks "Rocky Dean Pulley" for taking the time to reply to me. Probably I should do what you've said but with modifying COutlook2Ctrl itself also( or only).
If there is any further suggestions from anyone here, I would really appreciate it.
////////////After sometime//////////////
when I read what I have written above I noticed that I had some of the answer(it docks on the left side). So I remembered that I first tried to include the control and split the remaining to two parts horizontally....it didn't work at that time for a reason not related to it directly, I fixed that thing and continued working and trying other approaches forgetting the fact that it wasn't the real reason.
So I fooled myself at that point. Sorry for bothering.
|
|
|
|
|
Hi,
I have a requirement to hide the existing taskbar and place my own taskbar there. How can i do it? The existing taskbar's class is "Shell_TrayWnd", which is not available in mfc. Should i use "Toolbars" or "rebars". I would be of great help if someone could provide me code samples. Is there anyway by which i can change the existing taskbar apperance, like changing the font, color, font size, etc...
regards,
Jayashree
|
|
|
|
|
You may want to look for some articles on replacing explorer as the shell. Is this really what you want to do? If you want to replace the task bar you will probably want to replace the shell itself as well.
-- Rocky Dean Pulley
|
|
|
|
|
hi,
Thanks for your reply. Actually i don't want to replace explorer. I just want to restrict the user from using the normal taskbar. I can hide the existing taskbar by getting the windowhandle. Now i want to replce it with my own taskbar with restricted features. I need this because i my app runs on a TV which is of a less resolution. So i have to increase the font size, colors or may be use bitmaps. If it is possible to alter the appearance of the existing taskbar too, then i want to try that also.
regards,
Jayashree
|
|
|
|
|
The available MSDN documentation is quite clear on the proper methods for setting up a TCP/IP printer connection using the TCPMON Xcv Commands, and I have had reasonable success in this area.
I came up dry when I started looking for information on specifying the IP Port (rather than the "Printer Port") that will be used to send data to a given TCP/IP printer. Certain TCP/IP printers (like HP JetDirect) expose multiple IP ports and one IP address.
Advanced Google searches have returned thousands of false hits on other uses of the word "port" that I am not interested in. Combining the word "port" with the names of printer-setup APIs does not provide any more clarity. Perhaps I need to use another language in which the same word is not used to describe these completely unrelated objects.
|
|
|
|
|
I would like my SDI/CFormView application to be either minimized or maximized but not zoomed. That much I have done.
But how can I get rid of the 'X' on the menu bar that closes the application?
cs.style = WS_VISIBLE | WS_SYSMENU | WS_MINIMIZEBOX ;
|
|
|
|
|
I am not sure you can get rid of it if you have a minimize box. What I do in an app is gray out the box and handle the OnQueryEndSession() message.
BOOL CCommonApp::DisableClose(BOOL bDisable)<br />
{<br />
BOOL retVal = (m_pMainWnd != NULL);<br />
if ( retVal ) {<br />
CMenu* pMenu = m_pMainWnd->GetSystemMenu(FALSE);<br />
if ( pMenu ) {<br />
CMainFrame* pMainFrame = DYNAMIC_DOWNCAST(CMainFrame,m_pMainWnd);<br />
<br />
pMenu->EnableMenuItem(SC_CLOSE,MF_BYCOMMAND | bDisable ? MF_GRAYED : MF_ENABLED); <br />
<br />
}<br />
}<br />
return retVal;<br />
}
John
|
|
|
|
|
Simply get rid of WS_SYSMENU.
|
|
|
|
|
How does one create a resource dll containing only bitmaps? Is it just a normal DLL with only bitmaps in it?
My brain is a bit fuzzy at the moment.
I am the handsome one in the crowd.
|
|
|
|
|
yes, just create a normal win32 DLL, then add a resource file to it. Now add all the bitmaps you want, just like you would with an application.
-- Rocky Dean Pulley
|
|
|
|
|
Thanks.
Winter and what the cold does to the brain!!!!
I am the handsome one in the crowd.
|
|
|
|
|
You might also wish to alter your build settings such that debug information isn't linked in, and there is no entry point generated (/NOENTRY linker option). May as well make it as light as possible...
Shog9
I'm not the Jack of Diamonds... I'm not the six of spades.
I don't know what you thought; I'm not your astronaut...
|
|
|
|
|
Hey guys
My app has a mem leak which results from ExitInstance() not being called when I terminate the program.
I have traced into MFC and descovered that in the THRDCORE.cpp file, the following code is causing ExitInstance() to NOT be called.
==============================================================
// phase2: pump messages while available
do
{
// pump message, but quit on WM_QUIT
if (!PumpMessage())
return ExitInstance();
==============================================================
Does anybody know what some of causes of pumpMessage() to return true??
Thanks George
George W
Software Developer
www.zsystems.ca
|
|
|
|
|
If your message pump processes a WM_QUIT, then the GetMessage returns false.
Per MSDN ---
"What Is WM_QUIT?
Normal message-processing loops in an application's WinMain routine usually exit when the GetMessage function returns a FALSE value. Internally, if GetMessage is about to return a WM_QUIT message, it returns FALSE instead of TRUE even though the message returned in the MSG structure (a WM_QUIT message) is valid. The only time GetMessage will ever return a FALSE value is when it is returning a WM_QUIT message. Conversely, PeekMessage returns WM_QUIT messages as it would any other message. Applications that use PeekMessage in their main message-processing loop must explicitly look for the WM_QUIT message.
The PostQuitMessage function does not actually post a WM_QUIT message to the application's task queue. Instead, it sets a flag that is tested inside GetMessage and PeekMessage. WM_QUIT is returned when GetMessage or PeekMessage detects that this flag is set and no other messages or events are pending for the application."
|
|
|
|
|
That is pure GOLD!
Thank you....I have been struggling with this problem for a while.
I knew exactly where to look as soon as I read that.
Problem fixed!
Thanks again
IGeorgeI
George W
Software Developer
www.zsystems.ca
|
|
|
|
|
I tried build Setup project in Visual Studio
Everything works ok, but I am not able to find
how to do some features.
I need to Setup ask user for system reboot after install
...it should be there, but where?
And I am not sure if it is there but i need Uninstall part
delete whole folder
(program during its lifetime create files and after uninstal
these files are not deleted)
Does anyone know how to solve this?
Thank you
viliam
|
|
|
|
|
Hi,
I have a really annoying problem. When I build my application (which is quite large), the build succeeds and I press F5 to start debugging it, Visual Studio .NET 2003 always gives me this MessageBox:
These project configuration(s) are out of date:
ApplicationName - Debug Win32
Would you like to build them?
If I select Yes, the resources are rebuilt but nothing else. There are multiple resource files in this project BTW. Has this happened to anyone and are there any solutions?
Best regards,
Daniel
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|