CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    CreateThread with char array

    How to pass a char* as an argument to CreateThread?

    Code:
    #include <windows.h>
    #include <iostream>
    using namespace std;
    
    char * buf1 = "Hello World!";
    
    DWORD WINAPI runThread(LPVOID arg)
    {
        char * buf2 = reinterpret_cast<char*>(arg);
        cout << buf2 << "\n";
    
        return 0;
    }
    
    int main()
    {
        CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)runThread, (LPVOID)buf1, 0, 0);
        return 0;
    }

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: CreateThread with char array

    Quote Originally Posted by MasterDucky View Post
    How to pass a char* as an argument to CreateThread?
    Is it a question or a tip?
    Victor Nijegorodov

  3. #3
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Re: CreateThread with char array

    lol a question of course, seeing that the code doesnt work.

  4. #4
    Join Date
    Nov 2003
    Posts
    1,902

    Re: CreateThread with char array

    Your process, and its threads, die when main() returns. Get the thread handle and wait on it before returning from main().

    gg

  5. #5
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Re: CreateThread with char array

    Of course... thank you Codeplug!

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