|
mir5465 wrote: ...active control that have a dialog. Do you mean that you have an ActiveX control that is on a dialog?
mir5465 wrote: but i cann't to move it as mfc controls Meaning what exactly?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
int *pi;
{
int i = 3;
pi = &i;
}
std::cout << *pi << std::endl;
I figure that the *pi value in std:cout can not be trusted since i goes out of scope and the address of i can be used for other stuff. Is that correct?
Thank
|
|
|
|
|
Yep, that's right. It's also why you should never return references to local variables - what they're based on disappears at the end of the block they're declared in.
Cheers,
Ash
|
|
|
|
|
It depends on stack usage.
If you return a local var thats now out of scope to a func that eats the stack it will get munged. If not, it is still there, but its is risky of course.
Actually we found a windows bug that did just this. It returned a local var. This was OK till we hooked the func, and thus increased its tack usage.
In your case i is out of scope at code level, but is still on the stack since you havent returned from your func yet (your code is actually compiled with i on the stack just after pi).
--edit--
I see no one has responded. I guess an understanding of assembler (ie, the way code actually compiles) is totally foreign territory to todays 3G coders.
==============================
Nothing to say.
modified 19-Apr-12 2:43am.
|
|
|
|
|
Erudite_Eric wrote: It depends on stack usage.
AFAIK it doesn't so much depend on stack, but on the runtime libraries used: if they choose to invalidate a memory address as soon as it goes out of scope, then code like this will crash with an access violation. It may depend on compiler settings, but I've never seen code like that actually work on Windows XP or 7.
Then again I never deliberately tried
|
|
|
|
|
No, it isnt to do with libraries, but the very way local variables are allocated, ie, on the stack. This is only unwound, upwards dont forget, when the func the variables are declared in returns. Thats when the memory can be reused, by calling another func that declares its own variables.
So if you look at assembler you will see stuff like ebp+4 being set to a value. This is a local variable. At the end you see a ret 4. This returns from the func and winds the stack back by the same number as the size of the local variables declared.
==============================
Nothing to say.
|
|
|
|
|
hello guys... I have this dialogbox whose name I am trying to get. I have added a new dialogbox to the project using Add->Resource , so this gets an ID automatically, in the resource.h file. But when I use MAKEINTRESOURCE macro by providing resource id to get its name, it does not return it. It gives an assertion. What can be wrong here? thnx for any input.
This world is going to explode due to international politics, SOON.
modified 18-Apr-12 1:11am.
|
|
|
|
|
overloaded Name wrote: It gives an assertion.
Which is?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
plz refer to my answer below
This world is going to explode due to international politics, SOON.
|
|
|
|
|
MAKEINTRESOURCE does not get the name, it merely casts the integer value to a pointer. However, that is neither here nor there, the important question is what assertion you get and which line of code does it occur on.
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
|
|
|
|
|
Assertion Shown: Debug Assertion Failed
Context of the program: actually I am adding CPropertyPage s to CPropertySheet . Now when I pass the property page's IDD to CPropertyPage's constructor, there this macro can not cast this integer value to LPCTSTR (the resource type). Here is what the constructor looks like
CString1Dlg::CString1Dlg(CWnd* pParent ): CPropertyPage(CString1Dlg::IDD)
{
}
Now the point where it shows this assertion, looks like this.
CPropertyPage::CPropertyPage(UINT nIDTemplate, UINT nIDCaption, DWORD dwSize)
{
ASSERT(nIDTemplate != 0);
AllocPSP(dwSize);
CommonConstruct(MAKEINTRESOURCE(nIDTemplate), nIDCaption);
}
I debugged the application and know that nIDTemplate contains the ResourceId . Now MAKEINTRESOURCE here, does not convert this ID to corresponding resource type. Thats why I asked this question. During debuggin I came to know that MAKEINTRESOURCE is not working but in the first place, the assertion is shown in afxwin1.inl - line 24 , where code looks like this.
_AFXWIN_INLINE HINSTANCE AFXAPI AfxGetResourceHandle()
{
ASSERT(afxCurrentResourceHandle != NULL);
return afxCurrentResourceHandle;
}
I hope I was able to clear the picture.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
overloaded Name wrote: Context of the program: actually I am adding CPropertyPage s to CPropertySheet .
Which you should probably be doing in the sheet's constructor. Something like:
CMySheet::CMySheet(CWnd* pParentWnd , UINT iSelectPage )
:CPropertySheet(IDS_CAPTION_FRUITS, pParentWnd, iSelectPage)
{
AddPage(&m_page1);
AddPage(&m_page2);
AddPage(&m_page3);
AddPage(&m_page4);
}
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
DavidCrow wrote: Which you should probably be doing in the sheet's constructor
Yes. I have done that too. But eventually, the assertion is shown using that method too.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
Then something else is fundamentally wrong. Other than calling AddPage() in the sheet's constructor, and creating a dialog template for each page, that's all there is to it. Since you are not getting a compiler/linker error, we can assume there is a CPropertyPage -derived object in the sheet's .h file for each page you want added.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
class CString1Dlg : public CPropertyPage
{
public:
CString1Dlg(CWnd* pParent = NULL);
enum { IDD = IDD_STRING1_DLG };
Comparison of this code with previous one can be done here.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
Are you working with a DLL or EXE?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
EXE . This is solved now. As I said in earlier posts, Resource was missing. I was instantiating my CPropertySheet class in the wrong place. I was doing so in the constructor of my APP file like this.
CxyzApp::CxyzApp()
{
MySheet sheet = new MySheet(_T("My Sheet"));
}
But this was wrong. Controls are not loaded until InitInstance() is called. I should have instantiated my sheet class in the InitInstance() of APP like this
BOOL CxyzApp::InitInstance()
{
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
MySheet = new CEmplSheet(_T("My Sheet"));
if(MySheet != NULL)
m_pMainWnd = MySheet;
}
Thank you for you time.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
overloaded Name wrote: I should have instantiated my sheet class in the InitInstance() of APP like this
Or you could have waited to construct the sheet object until it was actually called for. For example:
void CxyzApp::SomeFunction( void )
{
CEmplSheet sheet(_T("My Sheet"));
sheet.DoModal();
}
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
overloaded Name wrote: Now MAKEINTRESOURCE here, does not convert this ID to corresponding resource type.
It's not supposed to convert it to anything, it merely casts its type to the appropriate LPSTR so that the receiving function's definition is satisfied. The key issue is whether the value is correct and identifies a valid dialog template.
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
|
|
|
|
|
I've got an SDI application created with VS2008. After some of the submenu item captions, I've added the tab escape sequence (\t) followed by the accelerator key I want (e.g., F2, F5). Visual Studio menu editor shows this correctly. The accelerator key table has also been updated. When I run the program, the submenu options work fine, but the accelerator keys do not show up in the submenu. Any obvious reason for this?
[edit]
It has something to do with a plain SDI app vs. one with a style and/or menu bar. I created another SDI app but opted for the standard style and the classic menu. My F5 accelerator key showed at run time.
[/edit]
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
modified 18-Apr-12 12:20pm.
|
|
|
|
|
|
jkirkerx wrote: I didn't quite understand the question, you mean the F5 key is not doing it's thing, or F5 is not showing up in the SubMenu after the value?
The latter.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
I'm not at your skill level, but I would create a new project as a test, and add the \t F5, and see if you get the same result.
|
|
|
|
|
jkirkerx wrote: ...I would create a new project as a test, and add the \t F5, and see if you get the same result. Same result. I created a new SDI project, ran it without any mods, and I see the stock set of accelerator keys in the submenus. So I created a menu and added a few submenu items, each with an accelerator key. For simplicity, I deleted IDR_MAINFRAME , and renamed my menu to IDR_MAINFRAME . Running the app now shows my menu and submenus but does not show the accelerator keys.
I took it one step further and rather than create a new menu to replace a stock one, I simply made a change to the IDR_MAINFRAME menu. For the Save option, I changed Ctrl+S to F2. While F2 shows up in the menu editor next to Save, when I run the app, Ctrl+S still shows up next to Save in the File menu. I also added F3 to one of the Office themes in the View menu. It does not show up at all. I've looked at the project's .rc file in Notepad and there's no sign of Ctrl+S. I've cleaned the project so it rebuilt everything.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
modified 17-Apr-12 15:51pm.
|
|
|
|
|
I created a Win32 non empty test project in VS2008 and it worked fine. I hand edited the rc file, and added \t Alt-F5 to Exit in the File Column.
I doubt if this is of any help, but this is my rc file content from the test project. Perhaps there's something in there you don't have. I'm sure it's the \t that's terminating the menu item value, just not sure why.
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
#ifndef APSTUDIO_INVOKED
#include "targetver.h"
#endif
#define APSTUDIO_HIDDEN_SYMBOLS
#include "windows.h"
#undef APSTUDIO_HIDDEN_SYMBOLS
#undef APSTUDIO_READONLY_SYMBOLS
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE 9, 1
#pragma code_page(1252)
IDI_MENUTESTDELETE ICON "MenuTestDelete.ico"
IDI_SMALL ICON "small.ico"
IDC_MENUTESTDELETE MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "E&xit\t Alt-F5", IDM_EXIT
END
POPUP "&Help"
BEGIN
MENUITEM "&About ...", IDM_ABOUT
END
END
IDC_MENUTESTDELETE ACCELERATORS
BEGIN
"?", IDM_ABOUT, ASCII, ALT
"/", IDM_ABOUT, ASCII, ALT
END
IDD_ABOUTBOX DIALOGEX 0, 0, 170, 62
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About MenuTestDelete"
FONT 8, "MS Shell Dlg"
BEGIN
ICON IDR_MAINFRAME,IDC_STATIC,14,14,21,20
LTEXT "MenuTestDelete, Version 1.0",IDC_STATIC,42,14,114,8,SS_NOPREFIX
LTEXT "Copyright (C) 2012",IDC_STATIC,42,26,114,8
DEFPUSHBUTTON "OK",IDOK,113,41,50,14,WS_GROUP
END
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_ABOUTBOX, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 163
TOPMARGIN, 7
BOTTOMMARGIN, 55
END
END
#endif // APSTUDIO_INVOKED
#ifdef APSTUDIO_INVOKED
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#ifndef APSTUDIO_INVOKED\r\n"
"#include ""targetver.h""\r\n"
"#endif\r\n"
"#define APSTUDIO_HIDDEN_SYMBOLS\r\n"
"#include ""windows.h""\r\n"
"#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
STRINGTABLE
BEGIN
IDC_MENUTESTDELETE "MENUTESTDELETE"
IDS_APP_TITLE "MenuTestDelete"
END
#endif
#ifndef APSTUDIO_INVOKED
#endif // not APSTUDIO_INVOKED
|
|
|
|
|