I am using winalleg.h's GetOpenFileName() to retrieve the path to a file. I have it working such that I get a path form GetOpenFileName(). However the next time I call load_bitmap() I get NULL returned instead of the bitmap pointer.
All my previous calls to load_bitmap() return the a bitmap pointer. Also the load_bitmap call that fails is hardcoded with the file name. The load_bitmap call works if GetOpenFileName() was not called previously. Oddly it also works if GetOpenFileName() was called but was canceled instead of successfully retrieving a file name.
My best guess is that something in the GetOpenFileName() is setting some sort of windows flag that forbids allegro's load_bitmap() from functioning properly.
Has this happened to any of you? How can I fix this?
My best guess is that something in the GetOpenFileName() is setting some sort of windows flag that forbids allegro's load_bitmap() from functioning properly.
Or setting a flag that messes with the retrival of the filename data itself. The OPENFILENAME structure is .... not small.
Has this happened to any of you?
Only when using Win32 straight up. Sadly, I forget the solutions I came up with, and I don't know how they might work with Allegro ....
Here is the problem code, in case any of you can spot what I am doing wrong. I have added the load_bitmap right after the GetOpenFileName to remove the chance something else is messing up the load_bitmap call. Normally the load_bitmap call happens else where.
1 | char * WinLoader::getLoadPath(char * path, char * filter){ |
2 | PALETTE pal; |
3 | BITMAP * tempBMP; |
4 | OPENFILENAME ofn; |
5 | char myPath[260]; |
6 | char szFile[260]=""; |
7 | get_palette(pal); |
8 | memset(&ofn,0,sizeof(ofn)); |
9 | // set path to current program directory |
10 | _getdcwd(0,myPath,260); //program path; |
11 | strncat(myPath, "\\",5); |
12 | strncat(myPath, path,102); |
13 | |
14 | //set important ofn values |
15 | ofn.lStructSize = sizeof(OPENFILENAME); |
16 | ofn.hwndOwner = win_get_window(); |
17 | ofn.nMaxFile = sizeof(szFile); |
18 | ofn.lpstrFile = szFile; |
19 | ofn.lpstrFilter = filter; |
20 | ofn.lpstrInitialDir = myPath; |
21 | ofn.Flags = OFN_HIDEREADONLY & OFN_FILEMUSTEXIST ; |
22 | |
23 | if(GetOpenFileName(&ofn) == false){ |
24 | } |
25 | /*************************************************** |
26 | * The Error occures here. If the user selects Cancel |
27 | * in the Open file dialog box tempBMP will get a |
28 | * bitmap pointer. If the user selects a valid file |
29 | * tempBMP will get NULL. |
30 | **************************************************/ |
31 | tempBMP = load_bitmap("Data//BackDrops//INST_DN.bmp", pal); |
32 | // copy save path to a more permanent string |
33 | strncpy(fileName, szFile, 206); |
34 | return fileName; |
35 | } |