Thread: Pass parameter to a thread

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    216
    When I remove the [], I get this error in my DownloadUpdates function. (which I call in the CheckForUpdate function ~ which is the new thread)

    Code:
    `void*' is not a pointer-to-object type
    Function which is called in CheckForUpdate (the thread function)
    Code:
    void DownloadUpdates(void *file)
    {
         int j;
         
         for(j = 0; j < num_files; j++)
         {
               SendMessage(hwndpb, PBM_SETPOS, 0, 0);
               //DownloadFile(file[j].name, file[j].outName); for reg struct
               DownloadFile((*file)[j].name, (*file)[j].outName); // error on this line
         }
    }
    I need to be able to cycle through the contents of the file structure (however many items there will be) and execute on the appropriate ones.

  2. #2
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    When you use a void pointer the compiler no longer knows what the original type of the variable was. You can't just expect the compiler to know that your 'file' variable is actually some sort of structure when you've made it a void variable.

    This is why we cast the void pointer to whatever it is supposed to be, so that it can be properly accessed:

    Code:
    int DoSomething( void *var1 )
    {
            int *var1cast = (int*)var1;
            
            return *var1cast + 1;
    }
    
    int main( void )
    {
            int num;
    
            num = 10;
    
            printf( "%d\n", DoSomething( (void*)&num ) );
    
            return 0;
    }
    Some of this may be wrong. It's been a while since I've even used void pointers and it's not like I ever used them very much. Note that this code only demonstrates the syntactic usage of void pointers. It does not actually show a situation in which void pointers would be used.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 11-27-2011, 07:40 PM
  2. Replies: 9
    Last Post: 10-19-2009, 04:46 PM
  3. How pass NULL for a parameter in a function?
    By 6tr6tr in forum C++ Programming
    Replies: 2
    Last Post: 04-02-2008, 01:29 PM
  4. how would i pass on a vector pointer parameter
    By bugmenot in forum C++ Programming
    Replies: 5
    Last Post: 12-16-2005, 02:51 AM
  5. Parameter pass
    By Gades in forum C Programming
    Replies: 28
    Last Post: 11-20-2001, 02:08 PM

Tags for this Thread