|
Hadn't tried GetBuffer(), but tested it out and that crashed it too.
Strangly, setting up a local char * and passing it in works just fine too, it's just passing anything associated with the CString object.
|
|
|
|
|
How about following?
TCHAR tempString[...];
strcpy(tempString, tmp.Getbuffer());
CreateEx(, , tempString, ....
|
|
|
|
|
transoft wrote: TCHAR tempString[...]; strcpy(tempString, tmp.Getbuffer());CreateEx(, , tempString, ....
Nope, doesn't work either. What I can't understand is why this code existed in previous builds and now causes a problem, why it works in Vista, and why the Debug Configuration in XP also works. The whole executable is around 5000 lines of code plus a driver to a hardware card so the project isn't huge, but not tiny either. So I suppose it could be some strange interaction with memory somewhere or something with the stack.
|
|
|
|
|
There must be some reason.
Are you sure that "CreateEx" crashed your software? Like "strcpy" will also crash program because of temp string has not enough buffer.
Could you post your code here?
|
|
|
|
|
transoft wrote: e you sure that "CreateEx" crashed your software? Like "strcpy" will also crash program because of temp string has not enough buffer.
Could you post your code here?
No, I'm not positive that CreateEx is THE cause, all I know is that the
code crashes before the function ever returns. I had narrowed this down by putting Message Boxes throughout the code and the last one that successfully displayed was immediately before the CreateEx() call.
Here's the code that crashed:
void DialogEditBoxObject_Class::init(CWnd *pParent, CString ctrlText, UINT resourceId)
{
CString tmp;
tmp.Format("%d", nLimit); //nLimit is a class member
//pMyRects are allocated in the constructor and do exist here
CreateEx(WS_EX_CLIENTEDGE, _T("EDIT"), tmp, WS_CHILD | WS_TABSTOP | WS_VISIBLE, *pMyRects[0], pParent, resourceId);
CRect clientRect;
GetClientRect(clientRect);
pMyFont->CreateFont(clientRect.Height(),0,0,0,FONT_HEIGHT(700),0,0,0,
ANSI_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH|FF_DONTCARE,
"arial");
SetFont(pMyFont); //pMyFont was allocated in the constructor
}
|
|
|
|
|
Often when the debug version works and the release crashes and you're dealing with pointers, you might have an uninitialized pointer. The debug heap zeros data blocks before it returns them and the release version doesn't. The pointer value itself is nonNULL but contains garbage so when something dereferences it, the program crashes. If the function accepts NULL as a valid pointer, it obviously checks and doesn't try to dereference the pointer. Since it worked before, you may just have gotten lucky and the garbage in the pointer pointed to something that could be interpreted as a valid string.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Tim Craig wrote: Often when the debug version works and the release crashes and you're dealing with pointers, you might have an uninitialized pointer. The debug heap zeros data blocks before it returns them and the release version doesn't. The pointer value itself is nonNULL but contains garbage so when something dereferences it, the program crashes. If the function accepts NULL as a valid pointer, it obviously checks and doesn't try to dereference the pointer. Since it worked before, you may just have gotten lucky and the garbage in the pointer pointed to something that could be interpreted as a valid string.
Thanks, that's useful to know. I was imagining that it could be a memory problem somewhere. The code I inherited when I took this project over was awful; even the debug version was letting me know about numerous memory leaks. I wrapped most of the code in classes and cleaned up new/delete calls all over but it is possible there is a more subtle problem going on that the debugger isn't letting me know about.
|
|
|
|
|
I'm a french new MFC programmer, and at run-time (compiling is OK), I got a message from MSVC++. This message is a Debug Error(Value of ESP was not properly saved...Problem of convention function calling). It's seems I located the call function which generate this exception. Following a piece of my source code. I think it's a function declaration problem. Thank's if someone could help me.
class CRepository
{
{
struct Server {
struct AutomationModules {
int nDataValid;
char szFilename[20];
char szDrawrow1[50];
char szDrawrow2[50];
char szDateModifier[10];
};
char szServerName[20];
AutomationModules files [MAX_FILES];
int nValid;
};
public:
CString RepositoryName;
bool bModify;
Server server[MAX_SERVERS];
CRepository() {}
virtual ~CRepository() {}
.....
public:
void InverseServer(CRepository::Server *Svr1,CRepository::Server *Svr2);
...
};
CRepository *pRepository = new CRepository;
...
extern CRepository *pRepository
...
pCrepository->InverseServer(&server[j],&server[j+1]);
...
|
|
|
|
|
AntoineBab wrote: ...I got a message from MSVC++. This message is a Debug Error(Value of ESP was not properly saved...Problem of convention function calling).
Which statement is generating the error?
AntoineBab wrote: pCrepository->InverseServer(&server[j],&server[j+1]);
What is the value of pCrepository at this point?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Hi
How can I change the color of a Tab Control? I manged to change the color of a static text and dialog. I need to change the color of the Button control and Tab control from the default gray to a color matching my dialog. How to do this? Please help
Thanks in advance
Deepak
|
|
|
|
|
|
hi,
i have a C++ program which can open cmd using createprocess() function but i want to give command to cmd.means when i run my program it will open cmd and if i want to show the directory i ahve to write in cmd dir but i want that i write dir in my program and it will automatically execute in cmd.can i do this?
|
|
|
|
|
Do you have troubles adding "cmd " to the actual command typed in your application?
You may also use the system CTR function, for instance
void main()
{
system("dir");
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
no no actually i use there scanf function and if i use system() commmand and type command cd c:\ then it will not goes to c: drive.I simply want to write a program which can give command to cmd and show me the output in my C++ running window.means whatever cmd shows it will be shown on my screen
|
|
|
|
|
Are you talking about console input/output redirection?
|
|
|
|
|
|
See here and here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
|
There are several articles about here [^] at Code Project.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
ravi 12 wrote: ...when i run my program it will open cmd and if i want to show the directory i ahve to write in cmd dir...
Why don't you use the FindFirstFile() and FindNextFile() pair?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
I don't know how you guys decipher this gibberish. It looks like Liquid Nitrogen to me...
|
|
|
|
|
|
In a C++ MFC application I have a Main dialog and several child dialogs. Now one of these child dialogs I used the Tabbed Dialog (CTabDialog - which had a main dialog and a dialog for each TAB). This worked greatand it has loads of code associated with the many controls on these tabs.
Now I would like to clone this dialog x2.
What is the best way to try and do this?
I am worried about the IDD/IDC etc in the resource.h file.
I can do global exchange for many items in the code.
Has anyone done this before or suggest the scheme to do this.
Many thanks,
Graham
grahamfff
|
|
|
|
|
Why do you need to clone it ? Can't you simply reuse it ?
Do you need different functionalities ? If yes, can't you simply make two classes inheriting from the same base class ?
|
|
|
|
|
The program controlled a hardware item, using a database and shared library. Now would like to control three items of hardware; which can be done OK. But need three instances of the GUI to control each h/w item.
If was starting the scratch then could design a class for this scheme, but too late now.
For ease and speed, clone the GUI and global change the code behind it.
Graham.
grahamfff
|
|
|
|