| View previous topic :: View next topic |
| Author |
Message |
pkedpker Master Cheater
Reputation: 1
Joined: 11 Oct 2006 Posts: 412
|
Posted: Wed Aug 20, 2008 1:46 am Post subject: How do I form structure dymaically? |
|
|
I got this atm.. but i get a ton of compiler errors
| Code: |
struct Packet{
char d6; //D6
short Size; //XX XX
char Keys[7];
char ServerKeys[1];
char data[2000];
};
|
| Code: |
Packet packet;
packet.d6 = 0xD6;
packet.Size = 0x1e;
packet.Keys = "\x0b\x00\x00\x00\x00\x00\x07\x00";
packet.ServerKeys = serverKeys;
packet.data = "\x00\x00\x0b\x00\x07";
strncat(packet.data, DBId, 4);
strncat(packet.data, "\x00\x63\x00\x00\x7d\x00\x00\x6b", 8);
SendPacket(&packet);
|
atm im doing the only way i know how.. and its not looking pretty
| Code: |
char* packet = new char[0x1e];
packet[0] = 0xd6;
packet[1] = 0x1e;
packet[2] = 0x00;
packet[3] = 0x0b;
|
Well help me out u smart peepz lol.
_________________
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Wed Aug 20, 2008 2:36 am Post subject: |
|
|
You forgot to set access point to your structure:
try now
| Code: | struct _Packet{
char d6; //D6
short Size; //XX XX
char Keys[7];
char ServerKeys[1];
char data[2000];
}Packet; |
|
|
| Back to top |
|
 |
pkedpker Master Cheater
Reputation: 1
Joined: 11 Oct 2006 Posts: 412
|
Posted: Wed Aug 20, 2008 2:44 am Post subject: |
|
|
Na its not that lol I remember that what u just wrote from a typedef tutorial but naw im talking about
errors like char[9] is not char[7] etc.. stupid errors
seems i can't even use strncat on it..
in the end I want to take the packet structure and pass it as a address hopefully it should look like a stream of a real packet..
_________________
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Wed Aug 20, 2008 3:29 am Post subject: |
|
|
| pkedpker wrote: | | errors like char[9] is not char[7] etc.. stupid errors | Dynamically also allocate the length too? I mean | Code: | struct Packet{
..
char *Keys;
..
}
unsigned char src[] = "\x00\x01";
Packet p;
p.Keys = new char [ sizeof(src) ];
::memcpy( p.Keys, Src, sizeof( src ) );
delete [] p.Keys;
or something |
| pkedpker wrote: | | seems i can't even use strncat on it.. | ::memcpy / ::memcpy_s.
|
|
| Back to top |
|
 |
pkedpker Master Cheater
Reputation: 1
Joined: 11 Oct 2006 Posts: 412
|
Posted: Thu Aug 21, 2008 12:37 am Post subject: |
|
|
thanks memcpy_s doesn't exist
but memcpy is powerful o_O man thats all i need really memcpy..
i could use any offest I want..
packet[4] = blahblah
memcpy(packet+5, whatIwantToCopy, sizeOf(WhatIwantToCopy;
all good.. thanks
rep++
_________________
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Aug 21, 2008 1:27 am Post subject: |
|
|
| pkedpker wrote: | thanks memcpy_s doesn't exist
but memcpy is powerful o_O man thats all i need really memcpy..
i could use any offest I want..
packet[4] = blahblah
memcpy(packet+5, whatIwantToCopy, sizeOf(WhatIwantToCopy;
all good.. thanks
rep++ |
memcpy_s does indeed exist.
|
|
| Back to top |
|
 |
nog_lorp Grandmaster Cheater
Reputation: 0
Joined: 26 Feb 2006 Posts: 743
|
Posted: Thu Aug 21, 2008 1:58 am Post subject: |
|
|
So the question was how do I dynamically allocate a string, not actually related to structs.
_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Thu Aug 21, 2008 3:09 pm Post subject: |
|
|
| Code: | | TCHAR* tszString = new TCHAR[ SizeNeeded ]; |
_________________
- Retired. |
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Thu Aug 21, 2008 3:18 pm Post subject: |
|
|
If you new something, will it get deleted after the function ends? I know you can use mallocs created from a function call, but what about news?
_________________
|
|
| Back to top |
|
 |
pkedpker Master Cheater
Reputation: 1
Joined: 11 Oct 2006 Posts: 412
|
Posted: Thu Aug 21, 2008 3:42 pm Post subject: |
|
|
I t hink any pointer u create from a packet has to be added into a pointerBuffer and clear when it reaches 100 pointers or so.. thats how i got it right now... so i dont know!
| nog_lorp wrote: | | So the question was how do I dynamically allocate a string, not actually related to structs. |
dud this has everything related to structs and allocation..
_________________
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Thu Aug 21, 2008 3:44 pm Post subject: |
|
|
| HalfPrime wrote: | | If you new something, will it get deleted after the function ends? I know you can use mallocs created from a function call, but what about news? |
No. The memory that holds the buffer is still valid after the function ends. You need to use delete to remove it after you are done with it.
_________________
- Retired. |
|
| Back to top |
|
 |
|