I have been trying in vain to pass an array to a thread
and have that thread loop through it.

Here is code of a simple thread passing an int to it.

#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>

DWORD ThreadProc (LPVOID lpdwThreadParam );

int threadnumber = 1;

using namespace std;
int main( int argc, char **argv)
{ 
    CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&ThreadProc, (LPVOID) &threadnumber, 0, NULL);
    Sleep(5000);
    return 0;
}


DWORD ThreadProc (LPVOID lpdwThreadParam ) 
{
    printf ("Thread #: %d\n", *((int*)lpdwThreadParam));

    for (int n = 1; n < 6; n++) {

        std::cout << n << std::endl;
    }

    return 0;
}

But how can I have threadnumber as an array, and loop through that array
in the ThreadProc routine?

I have tried a number of ways, but it's just a mess, always fails.
Any help is warmly welcomed.

Had to re-cast passed pointer to int.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.