#include <windows.h>
#include <stdio.h>


struct in {
  int a;
  int b;
};

struct out {
  int c;
  int d;
};

DWORD WINAPI ThreadController (void *arg)
{
  struct in *indata;
  struct out *outdata;

   indata = (struct in *)arg;
   printf("indata is %d and %d\n", indata->a, indata->b);
   
   outdata = (struct out *)malloc(sizeof(struct out));
   outdata->c = indata->a*2;
   outdata->d = indata->b*2;
   ExitThread((DWORD)outdata);
   return (0); /* we never get here */
}

int main()
{
  int i;
  struct in *a;
  struct out *b;
  DWORD retval;
  HANDLE thehandles[3];
  DWORD ThreadId;

  for (i=0;i<3;i++) {
    a = (struct in *) malloc (sizeof (struct in));
    a->a = i+1;
    a->b = i+100;
    thehandles[i]=CreateThread(NULL,0,ThreadController,a,0,&ThreadId);
  }
  for (i=0;i<3;i++) {
    WaitForSingleObject(thehandles[i],INFINITE);
	GetExitCodeThread(thehandles[i],&retval);
	b = (struct out *)retval;
    printf("Thread %d returned %d and %d\n",i,b->c, b->d);
  }
  return 0;
}
 
    
