CreateThread with char array
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: CreateThread with char array

  1. #1
    Join Date
    Dec 2007
    Location
    France
    Posts
    220

    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 online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,272

    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
    220

    Re: CreateThread with char array

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

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

    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
    220

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center