Thanks for that. I got it working.
I have, however, run into another problem.
I'm trying to dynamically allocate an array, and I was initially allocating the memory when a button was clicked and then freeing it on the WM_CLOSE message.
However, when I run the program(In debug mode, using VS 2008) and then close the dialog window, it gives me an error about the handle pointer being uninitialized, despite the fact I allocate memory for it, after which it gives me access violation errors where some debug, heap-checking function tries to read the memory and can't.
I've also noticed that the at the point where the memory gets freed(before it's passed) the pointer contains 0xcccccccc, instead of the address it was assigned from malloc which I can see if I break after malloc.
Here's the code(of the Dialogproc)
Code:
BOOL CALLBACK DlgProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
SomeHandle *rfidHandle;
switch(Message)
{
case WM_INITDIALOG:
{
int ret;
if((ret = ReadSerialFile(hWnd)) == ERROR_OCCURRED)
{
MessageBox(hWnd, SERIAL_FILE_NOT_FOUND, "File not found!", MB_OK|MB_ICONWARNING);
break;
}
return TRUE;
}
case WM_CLOSE:
{
free(rfidHandle);
rfidHandle = NULL;
EndDialog(hWnd, 0);
break;
}
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDC_REREADSERIALS:
{
int ret;
SendDlgItemMessage(hWnd, IDC_SERIALS, LB_RESETCONTENT, 0, 0);
if((ret = ReadSerialFile(hWnd)) == ERROR_OCCURRED)
MessageBox(hWnd, SERIAL_FILE_NOT_FOUND, "Not Found!", MB_OK|MB_ICONWARNING);
break;
}
case IDC_SERIALS:
{
switch(HIWORD(wParam))
{
case LBN_SELCHANGE:
{
unsigned int serialNumber = 0, selPos = 0;
selPos = SendDlgItemMessage(hWnd, IDC_SERIALS, LB_GETCURSEL, 0, 0);
serialNumber = SendDlgItemMessage(hWnd, IDC_SERIALS, LB_GETITEMDATA, (WPARAM)selPos, 0);
SetDlgItemInt(hWnd, IDC_SERIALEDIT, serialNumber, 0);
break;
}
default:
break;
}
break;
}
case IDC_ATTACH:
{
int noListBoxEntries = SendDlgItemMessage(hWnd, IDC_SERIALS, LB_GETCOUNT, 0, 0);
rfidHandle = malloc(noListBoxEntries * sizeof(SomeHandle));
break;
}
default:
return FALSE;
}
break;
}
default:
return FALSE;
}
return TRUE;
}