Take the 2-minute tour ×

I have a struct that I'm passing through CreateThread

packetargs *args;

But when I receive it in my Thread function, it crashes the application(Because the information is wrong):

    packetargs *pargs = (packetargs *)args;

How am I supposed to pass the struct as a pointer and then create it again in the thread function?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

You forgot to allocate any memory for your struct:

packetargs *args = new packetargs;

(Of course, you'll need to delete it at some point.)

share|improve this answer
oh wow, thanks. I'm pretty rusty. –  Nowayz Jun 27 '11 at 23:52
The structs still seem to contain different information after it's passed. I have no idea why –  Nowayz Jun 27 '11 at 23:58
It might also be possible just to create the args struct as an automatic variable. Obviously make sure it lives long enough for the new thread to use it, safest is to ensure it lives until after you join that thread. –  Steve Jessop Jun 27 '11 at 23:58
Something is going wrong on this line packetargs *pargs = (packetargs *)args; –  Nowayz Jun 28 '11 at 0:23
@Nowayz: You'll need to edit your question to include your actual code (cut down to the minimum possible). –  Oli Charlesworth Jun 28 '11 at 0:28
add comment

Your Answer


