Hello,
I'm using 5.0.4, and al_get_native_file_dialog_path() seems to be returning 'const ALLEGRO_PATH *' when according to the documentation it should be returning 'const char'.
Attempting to use al_path_cstr() on the return of al_get_native_file_dialog_path() yields an access violation.
Here is my example:
I'm probably doing something noobish, please advise.
Make sure you have actually installed 5.0.4. The return type of al_get_native_file_dialog_path() was changed to const char * shortly before the 5.0.0 release.
I've ensured that 5.0.4 is installed, which did not solve the issue.
I'm using the windows builds (allegro-5.0.4-msvc-10.0.7z) from this thread: http://www.allegro.cc/forums/thread/608100
Are there any other low-hanging fruits I should investigate?
What's the error message the compiler is giving you?
The violation when using "filePath = al_path_cstr( al_get_native_file_dialog_path( fileDialog, SIZE_MAX), ALLEGRO_NATIVE_PATH_SEP );" is:
Unhandled exception at 0x5516b75b in Droplet.exe: 0xC0000005: Access violation reading location 0x0000001c.
When using "filePath = string( al_get_native_file_dialog_path(fileDialog, SIZE_MAX) );", the compiler says:
1>main.cpp(4117): error C2440: '<function-style-cast>' : cannot convert from 'const ALLEGRO_PATH *' to 'std::string'
I see the error now. The second argument to al_get_native_file_dialog_path() is the path index. You need to use 0 for the second argument unless you are using the ALLEGRO_FILECHOOSER_MULTIPLE flag.
Unfortunately using "filePath = al_path_cstr( al_get_native_file_dialog_path( fileDialog, 0 ), ALLEGRO_NATIVE_PATH_SEP );" instead yielded another access violation.
I've also noticed that no matter how I create the path, the native file dialog always opens the same directory. Even if I comment out 'path = al_create_path_for_directory( "/" );' the result is the same. It seems like this might possibly be related??
Thanks for the help everyone
Why should "/" work under Windows?
Why should "/" work under Windows?
That stumped me for a couple minutes.
I think you need a drive letter, e.g. "C:/".
I think you've got some old headers still installed somewhere.
The only headers I have anywhere are the 5.0.4 ones from the archive I mentioned before.
As for the directory thing, I guess I'm ignorant on how to write it. I'm assuming that "C:/" would work, but using that doesn't change which directory the file dialog opens to.
I think I am going to start a fresh project to try out the file dialog in isolation and see what happens.
Edit: Not sure what is going on, but the forum won't allow me to reply to this thread now.
Here is the program I created to test the native file dialog:
This compiled but produces the following error:
Unhandled exception at 0x5daa1d39 in Native Dialog Test.exe: 0xC0000005: Access violation reading location 0x555c3a4b.
I'm at a loss really, since from what I understand, it shouldn't even compile...
Maybe someone could try compiling using the same libraries ( http://77.55.66.239/thedmd/allegro/5.0.4/allegro-5.0.4-msvc-10.0.7z ) and see if it reproduces?
Edit: Yep! I was doing something noobish. I looked high and low for old headers and couldn't find a thing. And then I realized that there were indeed old headers in the visual studio include folder.
It works perfectly now, thank you all who tried to point me in the right direction from the start!
p.s. Also, the file path I was meaning to call should have been ".//" to get the program's directory in windows.