I am trying to create a multithreaded program using the windows API. Here is what I have so far:
Code:
//Definitions//////////////////////////////////////////////////////////////////////////////
//Define this to allow multithreading
#define _MT
///////////////////////////////////////////////////////////////////////////////////////////
//Include files////////////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <stdio.h>
#include <commctrl.h>
#include "resource.h"
#include "diologs.h"
///////////////////////////////////////////////////////////////////////////////////////////
//Global variables/////////////////////////////////////////////////////////////////////////
//All puropose counter variable
int i;
//Thread handles
HANDLE mainDialogProc_Handle; //Main diolog
//Thread IDs
LPDWORD mainDialogProc_ID; //Main diolog
///////////////////////////////////////////////////////////////////////////////////////////
//Main function. Serves as entry point for other application threads///////////////////////
bool main(void)
{
printf("%d\n",GetLastError());
mainDialogProc_Handle = CreateThread(
(LPSECURITY_ATTRIBUTES) NULL, //Security attributes for thread. Default is fine here
(DWORD) 0, //Initial thread stack size. Again, default is fine
(LPTHREAD_START_ROUTINE) &DialogThread, //Pointer to thread function
(LPVOID) NULL, //Argument for new thread. Not implemented here
(DWORD) NULL, //Creation flags. None neccesary here
(LPDWORD) mainDialogProc_ID); //Pointer to receive thread ID
printf("%d\n",GetLastError());
if(!mainDialogProc_Handle)
{
printf("Error: Could not create DialogThread\n");
}
return FALSE;
}
///////////////////////////////////////////////////////////////////////////////////////////
Also, here is my code for the function in diologs.h that the thread should be going into (although I'm sure none of this is actually getting executed.)
Code:
DWORD WINAPI DialogThread(LPVOID lParam)
{
DialogBoxParam(
GetModuleHandle(NULL),
MAKEINTRESOURCE(IDD_DLG_MAIN),
NULL,
(DLGPROC)MainDialogProc,
0);
return FALSE;
}
This code does absolutely nothing execpt display my two printf functions calls. The weird thing about this mess is that I'm getting a Class does not exist error on my first call to the GetLastError function before my code even makes any calls to the Windows API. After the call to the CreateThread function though, no error occurs, and I actually get a handle to my thread, but it just never excecutes. Can anyone explain why this code won't work, and also why I'm getting that error if the two things aren't related.