Name: Windows 2008-07-09 6:04
ohai, i has teh problems passing the function through newthread(). The .exe runs, but gives me that stupid "bsdvskd.exe has encountered a problem and needs to close" any help would be great.
CODE:
#include <stdio.h>
#include <windows.h>
#define MAX_THREADS 4
enum {
THREAD_A,
THREAD_B,
THREAD_C,
THREAD_D
};
typedef struct
{
char name[50];
int id;
HANDLE handle;
int active;
} _THREAD, *THREAD;
int newthread(char *namex, int tid, LPTHREAD_START_ROUTINE (*thread)(LPVOID param), LPVOID param, THREAD t[MAX_THREADS])
{
int i;
DWORD dummy;
for(i = 0; i < MAX_THREADS; i++)
{
if(t[i]->active != 1)
{
strncpy(t[i]->name,namex,49);
t[i]->id = tid;
if(t[i]->handle = CreateThread(NULL, 0, thread, param, 0, &dummy))
{
t[i]->active = 1;
return i;
}
else return 666;
}
}
}
DWORD WINAPI print(LPVOID param)
{
int i;
for(i=0;i<11;i++)
printf("%d hats\n",i);
return 0;
}
int main()
{
THREAD threads[MAX_THREADS] = { 0 };
int x = newthread("Print", THREAD_A, print, NULL, threads);
if(x == 666) printf("error");
else printf("Name: %s, Id: %d, Active: %d",threads[x]->name,x,threads[x]->active);
return getch();
}
CODE:
#include <stdio.h>
#include <windows.h>
#define MAX_THREADS 4
enum {
THREAD_A,
THREAD_B,
THREAD_C,
THREAD_D
};
typedef struct
{
char name[50];
int id;
HANDLE handle;
int active;
} _THREAD, *THREAD;
int newthread(char *namex, int tid, LPTHREAD_START_ROUTINE (*thread)(LPVOID param), LPVOID param, THREAD t[MAX_THREADS])
{
int i;
DWORD dummy;
for(i = 0; i < MAX_THREADS; i++)
{
if(t[i]->active != 1)
{
strncpy(t[i]->name,namex,49);
t[i]->id = tid;
if(t[i]->handle = CreateThread(NULL, 0, thread, param, 0, &dummy))
{
t[i]->active = 1;
return i;
}
else return 666;
}
}
}
DWORD WINAPI print(LPVOID param)
{
int i;
for(i=0;i<11;i++)
printf("%d hats\n",i);
return 0;
}
int main()
{
THREAD threads[MAX_THREADS] = { 0 };
int x = newthread("Print", THREAD_A, print, NULL, threads);
if(x == 666) printf("error");
else printf("Name: %s, Id: %d, Active: %d",threads[x]->name,x,threads[x]->active);
return getch();
}