Dear Colleagues,
I'm attempting to use a dialog box to select the filename of an AVI file that I want to use in OpenCV. The OpenCV function is called:
cvCaptureFromAVI
. To create the Open File dialog box, I am using the Windows function:
GetOpenFileName
I suspect that the trouble I am having has something to do with the fact that my whole project is written in Unicode, and the OpenCV function expects const char*. If I hard-code the AVI filename as a char* variable, and I don't open the dialog box, everything seems to work. However, as soon as I try to use the dialog box, the
cvCaptureFromAVI
function won't work. In other words, even if I don't use the filename stored from the dialog box, I still won't be able to use my AVI file. Just opening the dialog box itself seems to screw it up.
Here is what works:
char filename[40] = "C:\\Users\\weylspinor\\Desktop\\test.avi";
CvCapture *G_movie_file = cvCaptureFromAVI(filename);
Now if I add the following, it doesnt work. (Note, I'm not even using the filename stored in the OPENFILENAME structure):
OPENFILENAME ofn; char szFile[260] = ""; HANDLE hf;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = h_main;
ofn.lpstrFile = LPWSTR(szFile);
ofn.lpstrFile = LPWSTR(szFile);
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = TEXT("Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0");
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn) == TRUE) {
hf = CreateFile(ofn.lpstrFile,
GENERIC_READ,
0,
(LPSECURITY_ATTRIBUTES) NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
(HANDLE) NULL);
}
char filename[40] = "C:\\Users\\weylspinor\\Desktop\\test.avi";
CvCapture *G_movie_file = cvCaptureFromAVI(filename);
I can get it to work again by just commenting out the GetOpenFileName function.
OPENFILENAME ofn; char szFile[260] = ""; HANDLE hf;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = h_main;
ofn.lpstrFile = LPWSTR(szFile);
ofn.lpstrFile = LPWSTR(szFile);
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = TEXT("Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0");
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
char filename[40] = "C:\\Users\\weylspinor\\Desktop\\test.avi";
CvCapture *G_movie_file = cvCaptureFromAVI(filename);
I'd appreciate it if anyone can point me to my error.
Cheers,
-J