|
Yup. You're all right. There is this site www.cppgames.com where one can submit a game (whether full version / beta test). Once submitted, it will be saved within the sites database and members may download the game and do as they please. You may either submit the source code or the executable file. In my case, I just need to submit the executable file since my program is a beta version. So, right now I'm just looking for another SUITABLE for the said purpose. Thanks for all your feedback. I'll try out the websites that you recommended and see what's going on there.
|
|
|
|
|
than codeproject is not right place for you as article must accompany with the source code otherwise article will get deleted!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
You can not update the game here in the website, but you can use megaupload or something like and post the link in the collaboration and testing forum[^]. Users will download and test it, and you can get the feedbacks there too.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Hi all,
I have a byte stream, consisting of two parts. First 4 bytes gives an int value. Rest of the part give just a name. I want to read them separately.
I've tried something like this.
<br />
UINT vBuffer[4];<br />
::memcpy(vBuffer,InMsg.GetDataBuffer(),sizeof(vBuffer));<br />
used memcpy to copy the first 4 bytes to my buffer. Now I have two question. How read the vBuffer and find the value? How to read the rest?
I appreciate your help all the time...
Eranga
|
|
|
|
|
you say the first 4 bytes give an int value, but you don't read 4 bytes, you read 4 UINTs (that means, 16 bytes on a 32 bits system, and 32 bytes on a 64 bits system).
moreover, you're writing into an undefined buffer.
why don't you just do this:
<font color="green">
<font color="blue">unsigned long</font> nSize = 0;
<font color="green">
::memcpy(&nSize, InMsg.GetDataBuffer(), <font color="blue">sizeof</font>(nSize));
then you don't have much complicated task to read the size...
modified on Thursday, December 06, 2007 5:24:09 AM
|
|
|
|
|
Ok, I got the point where I'm going wrong.
I have a question on your code. in memcpy first argument should be the new buffer to copy from the existing buffer. But here nSize is not a buffer at all. Can you clear me on it.
I appreciate your help all the time...
Eranga
|
|
|
|
|
oh god, you're right. i updated my previous answer so that the 4 bytes are written at the memory used by the nSize variable
|
|
|
|
|
How about my second question. I know that after reading the initial 4 bytes of the stream, stream points to the next byte start position. Since the length of the rest vary how can I read as u said. It's string, just a name like "ball, house, etc...."
I appreciate your help all the time...
Eranga
|
|
|
|
|
what about using strncpy() and pass it the integer formerly extracted ?
<font color="green">
nSize = 0;
<font color="green">
::memcpy(&nSize, InMsg.GetDataBuffer(), <font color="blue">sizeof</font>(nSize));
char* pszBuffer = new char[nSize + 1]; <font color="green">
::strncpy(pszBuffer, <font color="green"></font>, nSize);
pszBuffer[nSize] = <font color="gray">'\0'</font>;
std::string strData = pszBuffer;
delete[] pszBuffer;
modified on Thursday, December 06, 2007 5:15:54 AM
|
|
|
|
|
Yep, initially I thought about this. But failed to do it. Because my destination is a string, that is my requirement. But my destination is in a buffer, a byte stream. I want to read it after finding the int value.
toxcct wrote: pass it the integer formerly extracted ?
I'm not clear this.
I appreciate your help all the time...
Eranga
|
|
|
|
|
i don't understand your problem... why can't you use strncpy() ?
you say you want to read it after getting the int value, but isn't it what i'm doing there ?
|
|
|
|
|
No, No.
You take me wrong way. There is no connection between int value and the string. Let me explain it again.
Stream has two parts. First part give an int value. It gives the first 4 bytes of the stream. That is ok.
Second part has a string, few characters. I want to read it as well and find the word there has.
No connection with int value(nSize according to your code) and the string.
Is it clear...
I appreciate your help all the time...
Eranga
|
|
|
|
|
ok, so, the int is not the size of the remaining string. then just extract the string without taking care of nSize. can't you ?
|
|
|
|
|
toxcct wrote: ok, so, the int is not the size of the remaining string.
Yes, that is correct.
toxcct wrote: then just extract the string without taking care of nSize. can't you ?
That's where I'm stuck with. Can give me a help.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: Can give me a help
yes, i can; that's what i'm trying to do. but i need more infos.
1) so, to begin, what have you tried so far to extract the string ?
2) is the string of a constant length ?
3) can you know its length by any method ?
|
|
|
|
|
toxcct wrote: 1) so, to begin, what have you tried so far to extract the string ?
Lots of things I've tried,
<br />
char* varBuffer = new char[(InMsg.GetDataLength() - 4)];<br />
string var_name(&InMsg[3], (InMsg.GetDataLength()-4));<br />
It is better to provide more details. InMsg is in BYTE* to a byte steam. GetDataLength() and GetDataBuffer() are two member functions to get the message and the length. Here in this case my message is included both int value and the string.
toxcct wrote: 2) is the string of a constant length ?
No, string is not in fixed length. Actually contain some small words.
toxcct wrote:
3) can you know its length by any method ?
Yes, string length is less than 4 bytes. (InMsg.GetDataLength()-4)
I appreciate your help all the time...
Eranga
|
|
|
|
|
is the string is nul-terminated ?
also, what is the type of InMsg ???
modified on Thursday, December 06, 2007 8:08:09 AM
|
|
|
|
|
toxcct wrote: is the string is nul-terminated ?
Yes.
toxcct wrote: what is the type of InMsg ???
The type is BYTE*
I appreciate your help all the time...
Eranga
|
|
|
|
|
std::string second_part( (char*)(InMsg+sizof( first_part), InMsg.GetDataLength() - 4))
This calls the constructor of std::string with the address of the first char of the string (InMsg is of type BYTE* ? So you need to cast it to char* ) and the length of the remaining buffer.
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
Yes, I don't have cast it.
jhwurmbach wrote: (InMsg+sizof( first_part)
I've not clear this part. Why did you add the first part length.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Ok here are the details.
First thing is,
toxcct wrote: char* pszBuffer = new char[nSize + 1];
I'm not clear why you set the size of buffer to nSize, I mean that int values don't give the number of bytes of the rest of the stream or the string.
I got the following error on this line.
toxcct wrote: ::strncpy(pszBuffer, InMsg.GetDataBuffer(), nSize);
error C2664: 'strncpy' : cannot convert parameter 2 from 'BYTE *' to 'const char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: toxcct wrote:
::strncpy(pszBuffer, InMsg.GetDataBuffer(), nSize);
error C2664: 'strncpy' : cannot convert parameter 2 from 'BYTE *' to 'const char *'
You can esplicitely cast the pointer. But you must provide a meaningful value of nSize .
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.
|
|
|
|
|
CPallini wrote: You can esplicitely cast the pointer.
Can you little more explain this.
Please read my last post. There is no connection between int value and the string.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: I know that after reading the initial 4 bytes of the stream, stream points to the next byte start position.
memcpy() does not move any pointers around, other than the ones it uses internally. After it finishes, InMsg is in the same state as before.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
toxcct wrote: 34 bytes on a 64 bits system
Two bytes wide!
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.
|
|
|
|