CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1

    Angry CreateThread LPVOID Struct Char * Issue

    Alright Im new and this is my first post ive always read CodeGuru but just now got stuck with an issue that pretty much conserns me so i found myself here and Im glad to join.

    Ill try to make that as strate forward as possable

    I got a DLL I made VIA STDCall a Function call Test it takes 3 Params (INT, Char*, Long)

    The first is a Port Number, the 2nd is a String that will hold "127.0.0.1", and the Length of the string passed of "127.0.0.1" which will change Via Application passing the Args

    Now im calling this function from VB6 using FromUnicode option to format "127.0.0.1" then formatting it further once it Hits the C++ Dll Function Thats fine...

    Now it takes that String and put it into a Structure that looks like this
    Code:
    typedef struct {
    unsigned int Port;
    char * IP;
    } ConnectionInformation;
    I then use
    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;
    	MyStruct.Port = ParamPort;
    	MessageBox(0,LPCSTR(MyStruct.IP),LPCSTR("before it goes through"),0);
    	CreateThread(NULL, 0, InitSocketTest, reinterpret_cast<LPVOID>(&MyStruct), 0, 0);
    now another function resides in the same dll that CreateThread calls.. now the issue is that right when the function is called I use this
    Code:
    DWORD WINAPI InitSocketTest(LPVOID lp)
    
    {
    	//ConnectionInformation * MyInformation = (ConnectionInformation *)lp;
    	ConnectionInformation * MyInformation = reinterpret_cast<ConnectionInformation *>(lp);
    	unsigned int nPort=MyInformation->Port; //65535
    	MessageBox(0,LPCSTR(MyInformation->IP),LPCSTR("Information"),0);
    }
    and somewhere in between The CreateThread and Messagebox it Messes up beucase about 10&#37; of the time it shows 127.0.0.1 in the messagebox and the other it Crashes or displays Junk evenly... Any Ideas im sure its something reall simple that I dont see,

    Now once I get the Char Pointer issue handled I am just passing it like this to a Socket Stucture
    Is this the correct way to use it?
    Code:
     
    if ((RemoteSin.sin_addr.S_un.S_addr = inet_addr(MyInformation->IP)) == INADDR_NONE)
    Thankyou!
    Last edited by AgentSmithers; December 18th, 2008 at 10:37 PM.

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
  •  





Click Here to Expand Forum to Full Width

Featured