Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Help!!!

Author
Message
CAJUN57
16
Years of Service
User Offline
Joined: 29th May 2008
Location:
Posted: 13th Jun 2008 03:25
For some reason i get an access violation every time i recive a meesage on the server heres the code??



Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 13th Jun 2008 05:42
All you have is a raw pointer that's uninitialized. Try changing

char *bufferout;

to

char bufferout [50];

Or do

char *bufferout = new char [50];

Before the program finishes or before you exit that function you'll need to do

delete []bufferout;

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
CAJUN57
16
Years of Service
User Offline
Joined: 29th May 2008
Location:
Posted: 13th Jun 2008 19:30
thanks it works with

char* buffer = new char [50]

what's the 50 stand for???

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 13th Jun 2008 19:49 Edited at: 13th Jun 2008 19:49
The 50 means you're reserving room for 50 characters. If you're expected string is longer than that you may need to increase the number.

char buffer [##];

reserves ## number of characters in an array. When you pass the name of the array to your NetGetString function it's actually passing the address of the first character of the array. The function then uses that address to sequentially place the string into the array. Reserving the space ahead of time is necessary and you need to provide sufficient space to accept the largest possible string.

On the other hand

char *buffer = new char [##];

declares a pointer named buffer. A pointer is a variable that stores an address but needs to be initialized by setting it equal to the address of an existing array or by using the new key word to have the system reserve space on the heap and assigning the address returned by that call to the pointer. The pointer can then be used to pass the address to another function. You do, however, need to use the pointer to delete the reserved space before you exit the scope where the pointer is declared and avoid reassigning the pointer before deleting the reserved space.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office

Login to post a reply

Server time is: 2024-11-20 13:17:17
Your offset time is: 2024-11-20 13:17:17