|
Hi
I have a class named CClipSaver and I want to create an array of this class. I do this as follows:
CClipSaver* Clips[10];
.
.
.
Clips[i]=new CClipSaver;
Clips[i]->Save();
.
.
.
But it crashes!
Note:
When I do not use array (i.e.
CClipSaver * Clip;<br />
Clip=new ClipSaver();<br />
Clip.Save();
) everything works fine.
How should I declare and use the array?
|
|
|
|
|
What is the value of i when it "crashes"? (whatever "crashes" means)
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
Remember that when using arrays
array[10]
the tenth value is
array[9]
the value array[10] is out of the definition and may cause writting out of memory...
|
|
|
|
|
MohammadAmiry wrote: Clip=new ClipSaver();
Clip.Save();
everything works fine
Hope its a typo Error
Do your Duty and Don't expect the Result Rate this Post, if I helped You
|
|
|
|
|
i am a master student and i need genetic algorithms examples codes in borland C++ for my homework
this homework deadline :12th april
thanks for your help
|
|
|
|
|
kewl , have fun with that!
If you post a specific question you may get a specific answer.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
oz-gur wrote: i am a master student
No, you're not.
/ravi
|
|
|
|
|
if you dont know my question answer you dont sent me yours opinion please
|
|
|
|
|
If you're surprised by my response, see item (2) in this[^] post.
/ravi
|
|
|
|
|
hi i have spawned a an executable using shellexecuteEx as
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "textcopy.exe";
ShExecInfo.lpParameters = str;
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_HIDE;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
i wish to check whether "textcopy.exe" is still running....
i want to do sth like
if(process_is_running)
//do something..display some message
else
//continue
but I dont know how to check whether textcopy is still running.
Msdn says it can be done with the help of "ShexecInfo.hprocess"..i dont know how?.Please post some code example.Thnk you..
|
|
|
|
|
See GetExitCodeProcess()
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
Something like...
if (WAIT_OBJECT_0 != ::WaitForSingleObject(ShExecInfo.hProcess, 0))
//do something..display some message (process is still running)
else
//continue (process is terminated)
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
thnx man..it worked al rite..kudos!
|
|
|
|
|
I'm trying to write a quick util to do the following...
1. scan through all subdirectories of a specifiable root dir.
2. calculate the file sizes of all files encountered
3. delete 0-byte files
4. delete empty directories
The key here, is that i'd like to do this in as much ANSI c/c++ as possible, and definitely without using MFC. The reason being, I do not have visual studio at the moment, so the program must compile on dev-c++ or code::blocks IDE.
if anyone can point me to a reference for this it would be appreciated, thanks!
|
|
|
|
|
Can you use Windows APIs?
If so, check out FindFirstFile, FindNextFile, FindClose for directory traversal.
The C runtime has equivelant functions but they aren't ANSI compatible.
Mark
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
yea, i plan on doing a "include <windows.h>"
ok, ill check these functions out, thanks!
|
|
|
|
|
I'll keep this brief. My app has a member variable of type CStringList called m_channelList. I wish to add new CStrings via a dialogue box. This is how I've been trying to do it:
CWinApp* AFXAPI AfxGetApp();
AFXAPI->m_channelList.AddTail ( szNewChannelName );
But my compiler doesn't like it. I get the following error:
error C2143: syntax error : missing ';' before '__stdcall'
Is there a better way? Or at least an explaination why this error is occuring?
|
|
|
|
|
AFXAPI is defined by MFC as follows
#ifndef AFXAPI
#define AFXAPI __stdcall
#endif
hence it is an unlucky name for your variable. Use instead
CWinApp* myApp AfxGetApp();
myApp->m_channelList.AddTail ( szNewChannelName );
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.
|
|
|
|
|
Well, it never fails that I would do something like that. Thanks.
I have another problem now though. When I use
CWinApp* myApp = AfxGetApp();
I get 'm_channelList' : is not a member of 'CWinApp' (which it obviously isn't), but if I use
CMyApp* myApp = AfxGetApp();
I get cannot convert from 'class CWinApp *' to 'class CMyApp *'.
|
|
|
|
|
Since your App it's actually a CMyApp (I guess you have, somewhere in you project, the following line: class CMyApp : public CWinApp ), you can safely use the following cast :
CMyApp * myApp = (CMyApp*)AfxGetApp();
and the compiler will not complain anymore.
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.
|
|
|
|
|
That worked perfectly, thanks! (And yes, my app class really is called CMyApp. LOL)
|
|
|
|
|
What I find is useful when I store info in MyApp is to add:
to MyApp.h
CMyApp* GetMyApp();
and for some common functions or global settings (if req'd)
void CommonAppFunction(something);
and to MyApp.cpp
CMyApp* GetMyApp()
{
return &theApp;
}
void CommonAppFunction(something)
{
return theApp.CommonAppFunction(something);
}
This enables you to write in any file that includes MyApp.h
GetMyApp()->DoSomething();
or
CommonAppFunction(something);
and saves all the casting etc.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
You need to declare a CWinApp* variable, what you have there is a function prototype.
CWinApp* pApp = AfxGetApp();
|
|
|
|
|
Yeah, I picked up that little mistake when the compiler started throwing unexpected tokens at me LOL!
|
|
|
|
|
can anyone explain how to use tcp in C++ I've looked at a million sites and a million tutorials and every single one doesn't work.
|
|
|
|