|
char *buffer = (char *) malloc(size);
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
The size of the array has to be known at compile time, so it can't be a variable. You need to use malloc or calloc instead.
--Mike--
Ericahist [updated Oct 26] | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber
There is a saying in statistics that a million monkeys pounding on typewriters would eventually create a work of Shakespeare. Thanks to the Internet, we now know that this is not true.
|
|
|
|
|
Thanks!
Kevin Shaffer
kshaff03@msn.com
|
|
|
|
|
<small>kshaff03 wrote:</small>
void parse(const int size)
{
char buffer[size];
...
} I think it valid in C99, not in C++.
Maxwell Chen
|
|
|
|
|
The problem is in your code
kshaff03 wrote:
void parse(const int size)
{
char buffer[size];
...
}
The problem lies in the way you've declared the array.
since char buffer[] is a static array meaning the compiler needs to know at compile time so it knows how much memory to allocate.
You're using a variable to size it. Where you should a constant or literal.
e.g.
#define MAX 100<br />
const unsigned int size = 50;<br />
<br />
inr main(void)<br />
{<br />
char foo[MAX];<br />
char bar[size];<br />
int fred[20];<br />
}
these 3 are all legal
your example should be coded as follows
void parse(const unsigned int &size)
{
char *buffer = new char[size];
...
delete[] buffer;
}
I'll send you an e-mail shortly
|
|
|
|
|
Hi,
I am trying to built an MFC application with an MDI Frame (CWinApp). Beside this, I have implemented a DLL in which I need to open an MFC based Dialog. Within the EXE, I just need to call DoModal and it works fine but here, the function that creates the dialog is in the DLL that is called by the main application.
It crashes in the function int CWnd::RunModalLoop(DWORD dwFlags) with an unhandled exception.
// pump message, but quit on WM_QUIT
if (!AfxGetThread()->PumpMessage())
{
AfxPostQuitMessage(0);
return -1;
}
By the way, I put Debugmultithreaded Dll in the settings of the application and the DLL.
What did I made wrong, please ????
MFC Beginer
|
|
|
|
|
I have two questions pertaining to serialization.
- I have nested classes but want save each class into seperate files how do go about doing this
and
- If want to able to open files in range of different extensions e.g *.csv, *.prn and *.txt. How is this achieved?
Again many thanks
Alton
|
|
|
|
|
1. Using MFC serialisation mechanisms, you don't. The assumption is made that a single file will contain the entire document. Indeed, use is made of a 'class dictionary' within an MFC archive file, unless you redo the serialisation from scratch.
2. There's a KB article (141921) which covers this nicely.
Steve S
|
|
|
|
|
I know to code it to return an object of ostream &, istream & or the classes that derived from them.
But how do you do it to return a reference to a CArchive?
Alton
|
|
|
|
|
If you're overloading the << and >> operators, chances are that you also have a CArchive& parameter. Simply return that.
Usually you'll have something like
<br />
friend CArchive& operator<<( CArchive& ar, myObj obj);<br />
friend CArchive& operator>>( CArchive& ar, myObj& obj);<br />
inside your class declaration for myObj .
So when you implement
<br />
CArchive& operator<<( CArchive& ar, myObj obj)<br />
{<br />
...<br />
return ar;<br />
}<br />
and similarly for the operator>> function.
Steve S
|
|
|
|
|
Steve S wrote:
friend CArchive& operator<<( CArchive& ar, myObj obj);
friend CArchive& operator>>( CArchive& ar, myObj& obj);
return ar;
I've those that inside a generic underived class but the compiler complains i.e. what the hell am I talking about.
do I:
- place the functions in the appropiate C++ and header files
- subclass them from CObject (which I don't want to do)
- or find the correct syntax (which is)
Alton
There's no problem, only solutions
John Lennon
|
|
|
|
|
Your C++ class must be derived from CObject to be serialisable anyway (see DECLARE_SERIAL, IMPLEMENT_SERIAL).
You would put those definitions in your 'base' class's header file, with the implementation, which is normally to call obj.Serialize(CArchive&ar), which you then implement.
You can then use these objects in your document's serialize method, using the operators, or alternatively, call the object's serialize method directly.
Does that help any?
Steve S
|
|
|
|
|
Does any one know how rows & columns can be added or remove on MSDataGrid control programatically. without using the CRecordset class. (there must be a way)
Many thanks
Alton
|
|
|
|
|
How to use UniCode in VC++ (CEdit control) or win32.
|
|
|
|
|
I don't understand the question. But for a project to support Unicode without any other changes, you need to turn that feature on. You'll then need to make sure all your char s are TCHAR s and your strings have the _T() macro around them. (If you are using pure Unicode, you can use wchar_t and the L prefix for strings.)
If you just want to make a single Win32 call using the Unicode function, use a Unicode string, if needed, and tack a 'W' on the end.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
I am trying to open an htlm file to a specific bookmark without any success. I am tyring to use the ShellExecute command as follows:
ShellExecute(0, "open", "c:\test.html#Bookmark1", NULL, NULL, SW_SHOWNORMAL);
The result is that the program opens test.html in explorer, but does not got to Bookmark1. Is there any way to do this?
And while I'm on the subject, is there any way to do the same thing with PDF files (open a PDF file to a specific location?)
Thanks,
John
|
|
|
|
|
I'm automating our product build process. I have a native Win32 application that does some UI setup and updates version resources, and then it runs the build script. The build script is a .wsf (Windows Script File) that I want to run using CScript, the console script host.
My problem is this: If I call CreateProcess with CScript.Exe as the file to execute, the process starts, creates a console window, and exits immediately:
STARTUPINFO startup_info = { 0 };
char startup_title[128];
strcpy(startup_title,"Distribution build");
startup_info.cb = sizeof(startup_info);
startup_info.lpTitle = startup_title;
PROCESS_INFORMATION process_info = { 0 };
CreateProcess("CSCRIPT.EXE",
"//nologo DistributionBuild.wsf",
NULL,NULL,FALSE,
"C:\SC400.Build",
&startup_info,
&process_info); However, if I start CScript.Exe via the command interpreter, it runs correctly:
CreateProcess("CMD.EXE",
"CScript //nologo DistributionBuild.wsf",
NULL,NULL,FALSE,
"C:\SC400.Build",
&startup_info,
&process_info); Anyone have any ideas why this might be the case?
Software Zen: delete this;
|
|
|
|
|
You seem to be missing two parameters to CreateProcess() . I'm guessing that DWORD dwCreationFlags and LPVOID lpEnvironment are the ones.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Thanks for your help, and sorry for the missing stuff. I'm using dwCreationFlags = 0 and lpEnvironment = NULL . I just reread the help for CreateProcess and realized I probably should use dwCreationFlags = CREATE_NEW_CONSOLE . Leaving the environment set to NULL should cause the new process to receive a copy of the existing one.
Software Zen: delete this;
|
|
|
|
|
What about the double backslash in the lpCurrentDirectory parameter? Does GetLastError() return a non-zero value in your first example of CreateProcess() ?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
The current directory included the proper backslashes (the code I posted originally is paraphrased). The process does start (CreateProcess doesn't return an error), but it doesn't run the script.
Mike Dunn gave me the key (see the posts below). Thanks for your help .
Software Zen: delete this;
|
|
|
|
|
|
That makes it work .
Hmmm. Looking at my original code, when I was specifying "C:\Windows\System32\CScript.Exe" as the application parameter, and "//nologo DistributionBuild.wsf" as the command line, I realize I wasn't repeating the program name in the command line, e.g. "C:\Windows\System32\CScript.Exe //nologo DistributionBuild.wsf". Perhaps that was what was causing the problem. Thanks for your help.
Software Zen: delete this;
|
|
|
|
|
Hi, I need help.
I have enabled asynchronous listening on tcp and udp port.
When I receive TCP request, averything is ok, i read source IP adress
(FD_ACCEPT) and data (FD_READ).
But when UDP broadcast message comes, i cannot read IP adress, because
there is no FD_ACCEPT event. I can only read udp data.
How can i get source ip of UDP datagram?
Thanx for help.
|
|
|
|
|
I've already made it,
simply call recvfrom() instead of recv().
Thanks anyway.
O.
|
|
|
|