|
-
December 19th, 2008, 02:33 AM
#2
Re: CreateThread LPVOID Struct Char * Issue
That's normal.
Code:
MyStruct.IP = IPModded;
IP is a pointer to char. The above line says: "let IP point to the address of buffer IPModded". Then you create a new thread and probably return from that function. But then, IPModded, which is a local variable gets out of scope, and IP will point to garbage memory. So, you're lucky that 10% of the time you have it working.
To solve it, you must allocate memory for IP, and copy the content of IPModded to IP. Actually, you don't need IPModded at all.
Change
Code:
char IPModded[16]; //Max Len of Ip is 15 + Null
strcpy(IPModded, ParamIP);
IPModded[ParamLenOfIP] = '\0'; // Cut Of Crap from End Of String
ConnectionInformation MyStruct;
MyStruct.IP = IPModded;
to
Code:
ConnectionInformation MyStruct;
MyStruct.IP = new char[ParamLenOfIP + 1];
strcpy(MyStruct.IP, ParamIP);
MyStruct.IP[ParamLenOfIP] = '\0'; // Cut Of Crap from End Of String
But you have to make sure, when MyStruct is no longer needed, that you release the memory allocated for IP.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|