|
Yeah, I've tried it also now and it worked... strange!
Rickard Andersson8
Here is my card, contact me later!
UIN: 50302279
E-Mail: nikado@pc.nu
Interests: C++, ADO, SQL, Winsock, 0s and 1s
|
|
|
|
|
You don't appear to be null-terminating buffert . Just before the MessageBox() call, do a *p1 = 0 . AFAIK, your initialiser only sets the first location of the array to 0 - all the rest are left uninitialised.
Also, make sure that your buffert array is not being overrun - your code as written is a big security hole. What if somebody managed to send 22 characters without a space? If you're lucky it would crash. If not, who knows what data might get corrupted...
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Ryan Binns wrote:
AFAIK, your initialiser only sets the first location of the array to 0 - all the rest are left uninitialised.
AFAIK the ={0}; does the same as zeromem() does - only that it is more pleasant to the eye.
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
Fair enough. I'll remember that
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Thank you very much!
I've updated the code, here is the updated version:
void HotIceParser(const char* command, const int len, PHIPD phipd)
{
char* buffert = NULL;
char* p1 = NULL;
const char* p2 = NULL;
#ifdef DEBUG_MODE
assert(phipd != NULL);
assert(len < MAX_BUFFERT+1);
assert(len != 0);
#endif
buffert = (char*)malloc(len);
ZeroMemory(buffert, len);
p1 = &buffert[0];
p2 = &command[0];
while((*p2 != ' ') && (*p2 != '\0'))
*p1++ = *p2++;
if(strcmp(buffert, HIC_LUC) == 0)
{
phipd->type = LUC;
p1 = &buffert[0];
p2++;
while((*p2 != ' ') && (*p2 != '\0'))
*p1++ = *p2++;
*p1 = '\0';
strcpy(phipd->luc.pszIP, buffert);
}
free(buffert);
}
Is there anything that you think is done wrong or so?
One thing I don't really understand is:
while((*p2 != ' ') && (*p2 != '\0'))
*p1++ = *p2++;
Is command contains this: "luc 192.168.244.151 4000 50 mypass".
Then it only run the loop 3 times because it is supposed to find 'luc'. If I remove "&& (*p2 != '\0')" it will loop many times, I don't know how many but many! With "&& (*p2 != '\0')" I will understand it as it would keep iterate until '\0' is also found... but it doesn't. I did wrote the code by myself but I don't really understand it correctly!
Rickard Andersson8
Here is my card, contact me later!
UIN: 50302279
E-Mail: nikado@pc.nu
Interests: C++, ADO, SQL, Winsock, 0s and 1s
|
|
|
|
|
I have been programming in C and C++ for a little while now, but I want to start learning the MFC stuff. I have been looking through the MSDN library, but I could not seem to find much information on where to start in the learning process. I have manipulated a few Visual C++ apps to do what I need them to do, but I'm not sure what some of the code did. So here is my list of simple questions:
1. What are the most helpfull resources to use?
2. Did I miss a section of the MSDN library that is helpful in this area?
3. When I start a new Win32 Project, how much of the automatic code do I need to understand?
4. What other basic tips can you provide for someone in my situation?
by the way,
I'm using Visual Studio .net
|
|
|
|
|
Jon H wrote:
1. What are the most helpfull resources to use?
To a certain extent learning MFC is a bit of trial and error. The way I learnt was by starting with dialog based apps.
Play around with the toolbox and adding controls. Then start to add controls to your app. Finally make sure you understand how to add variables to represent the controls with various ID's.
Jon H wrote:
2. Did I miss a section of the MSDN library that is helpful in this area?
Possibly what you missed is that MFC is huge. It's made up of so many classes which represent so many different types of controls
Jon H wrote:
3. When I start a new Win32 Project, how much of the automatic code do I need to understand?
Very little to start with. Try to avoid modifying message maps unless you have to. Stick, at least at the start, to just worrying about your handlers for buttons / whatever. Don't worry much about the code the AppWizards generate for you, most of it's just framework stuff. If you need to modify it you can get more help on MSDN. Look for the todo: in the code for place's where you can start to add code if you feel the urge to experiment.
Don't make the mistake of trying to cram your whole app into the generated MFC classes. Write your app, then use MFC as a frontend, using whatever goodies you want like CString along the way.
Jon H wrote:
4. What other basic tips can you provide for someone in my situation?
Be aware of linking. Sometimes I think this is the most underdone of all C++ topics. Make sure that you're linking to the correct standard library. Be aware of unicode compliance. Use string tables if you start thinking about developing a bigger product
|
|
|
|
|
hi
I get a linker error (WinMain@16 or something like that) when I try to build my app with unicode.
I've defined the _UNICODE macro in the config-settings. Are there any other steps necessary to successfully build a unicode app ?
different question:
I have, for example, 2 string tables (1x german, 1x english) or dialog templates... (german is default)
Now the question -> What steps are necessary to make a build with the english
resources ?
thanks
widi
vc6 sp5, mfc, winxp
|
|
|
|
|
MSDN->Contents->books->Developing International Software for Windows 95 and Windows NT. The new edition was released by microsoft press earlier this year.
There is also an article on internationalization at codeproject (and some otehr articles).
:(Sorry, I can not remember what other steps are required after defining _UNICODE.
Trust in the code Luke. Yea right!
|
|
|
|
|
Hi,
i have some IO and memory initialize code within an object
constructor. i wish to have an null object if there is io operation
fail in the constructor. ie:
CXXXManager *cm = new CXXXManager();
if(cm == NULL){// something had failed}
how the constructor with the above ability can be implemented?
thank you.
regards
yccheok
|
|
|
|
|
yccheok wrote:
i wish to have an null object if there is io operation fail in the constructor.
Constructors will never return NULL.
If you want to represent an error in a constructor you have a number of choices.
1/ Set an internal flag in your class to show that the IO Operation failed, and check that flag before you continue. The standard iostream library does this.
2/ Throw an exception
try
{
CXXXManager *cm = new CXXXManager();
}
catch(IOEx& ex)
{
}
Solution 2 is the preferred solution, at least in my mind, because errors always have to be dealt with.
Note: that this is different to a failure with the allocation of memory, in which some non-standard compilers (eg/ MSVC6) will return NULL. The accepted behavior for memory allocation failure is now to throw std::bad_alloc
|
|
|
|
|
it might be better to call a separate method rather than doing the code in the constructor - it's a bit easier, although exceptions are a good idea, as pointed out above...
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Hi All,
I got a problem in debugging the server of an existing client-server application in my project.I tried to Run the client in debug mode than run the server.and then go to vc++ build ->Start Debug ->Attach to process.But i didn't see any processes listed their so that i can attach it to the client source code.I don't know what is wrong?I am not getting any clue for last 2-3 work-days.
Please help.
|
|
|
|
|
Does anybody know the format of the Visual C++ Intellisense database file, i.e. the ncb file?
|
|
|
|
|
my activex Ctrl creates a frame and view under the object base on COleControl.when i test it by asp, i find that it can only run at IE6.But test by other tools like Delphi,it has no problerm.
my ctrl has a public function named LoadMap().
i followed the error message and found that the frame is not created while the function LoadMap() has been called.
i can provide the source code,please mail to ffjn@yeah.net
fjn
|
|
|
|
|
Hi everybody,
Can you tell me how to get the index of the current hot item(under the mouse) of the CListCtrl. I used the member function "GetHotItem", but it always return -1, why
Thanks!
HuChJ
|
|
|
|
|
|
Hi guys,
Last friday I posted a question about a strange exception that was thrown (when I called a messageBox in the OnNewDocument)! With the help of some guys here (thanks to RaGe, Neville Franks, FranzKlein and basementman ), I finally solved the problem !
In fact, when I call MessageBox in the OnNewDocument function, the Framework make a call to the GetMessageString(UINT nID, CString& rMessage) function (from CMainFrame). In my case, this function was overloaded to support multiple languages for help text for the toolbar buttons (text in the status bar). I was then calling a funtion from a class that hasn't been instancied (the class for language texts).
void CMainFrame::GetMessageString(UINT nID, CString& rMessage) const
{
if (ID_SAVE <= nID <= ID_SELECTTV)
{
rMessage.Format(localtext->nr(nID));
}
else
CFrameWnd::GetMessageString(nID,rMessage);
}
The function was called with an nID equal to 57345 wich isn(t corresponding to any of my buttons (range from 20 to 33). So the error was in the line:
if (ID_SAVE <= nID <= ID_SELECTTV)
wich has to be replaced by:
if ( (ID_SAVE <= nID) && (nID <= ID_SELECTTV) )
otherwise, I call localtext->nr(nID); and this class hasn't been instancied for now !!
So again, a big big thanks to all the guys who help me to solve this problem that was wrecking my mind !
|
|
|
|
|
Glad to hear you have finally found out ... very tricky, this one bug
~RaGE();
|
|
|
|
|
Great to hear you found it. Thanks for letting us know. Now you can take it easy for the rest of the week.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Dear All,
I am developing an application (using VC++ Version 6 for Windows 2000/XP/NT) in which I want to retrieve the list of all the "File type extenstons" present in my system.
I suppose that there must be some API for retrieving this list.
To see the list go to:--
Start=>Settings=>Control Panel=>Folder Options.
Then select File Type to get list all file type extenstions
Thanks in advance.
Rohit Dhamija
|
|
|
|
|
This is stored in the registry under HKEY_CLASSES_ROOT.
So Open this key using registry functions (RegOpenKey ) and then you can enumerate the subkeys with RegEnumKey . In these, look for the ones starting with a point '.' and there you have your file extensions. In the key are stored the associated application, usually in shell\command\open.
For example, under HKEY_CLASSES_ROOT\.txt is stored Text Files .
And under HKEY_CLASSES_ROOT\.txt\Text Files [edit] Sorry, it is HKEY_CLASSES_ROOT\Text Files [/edit] is stored Shell\Command\Open\"Notepad %1"
~RaGE();
|
|
|
|
|
Hi Rage,
Thanks a lot. That was very useful.
Rohit
|
|
|
|
|
Hi,
Have anyone ever played D&D games? I want to write a
program(in console mode) that will give you a random
number, so I write the Die class. But I have tons of
errors even I have debugged it so many times.(still
tons of) I hope some of you would help me out here.
There are 18 errors, 1 warning
This is how I did that:
I use VS.Net, Visual C++ => Win32 Project => console
application => empty project.
I divided it into three files, the driver, the implementation
and the header. Here is the code:
<br />
<br />
#include "Die.h"<br />
#include < iostream ><br />
using namespace std;<br />
<br />
void main()<br />
{<br />
Die d1, d2;<br />
Die d3(10), d4(100);<br />
<br />
cout << "d1\td2\td3\td4" << endl;<br />
<br />
for (int i=0; i<10; ++i)<br />
{<br />
d1.roll();<br />
d2.roll();<br />
d3.roll();<br />
d4.roll();<br />
<br />
cout << d1.getValue() << '\t';<br />
cout << d2.getValue() << '\t';<br />
cout << d3.getValue() << '\t';<br />
cout << d4.getValue() << '\t';<br />
}<br />
}<br />
<br />
<br />
#include <cstdlib><br />
#include <ctime><br />
#include "Die.h"<br />
<br />
Die::Die()
{<br />
nSides = DEFSIDES;<br />
value = 1;<br />
}<br />
<br />
Die::Die(int sides)<br />
{<br />
nSides = sides;<br />
value =1;<br />
srand (unsigned (time null)));<br />
<br />
}<br />
<br />
void Die::roll()
{<br />
value = (srand()%nSides)+1);<br />
}<br />
<br />
<br />
#ifndef DIE_h<br />
#define DIE_h<br />
<br />
const int DEFSIDES = 6;<br />
<br />
class Die<br />
{<br />
public:<br />
Die();<br />
Die(int);<br />
<br />
void roll();<br />
<br />
int getValue() const ( return value; )<br />
<br />
Private:<br />
int nSides;<br />
int value;<br />
<br />
};<br />
<br />
#endif<br />
<br />
|
|
|
|
|