<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[A5] Native Dialog, or path issue?</title>
		<link>http://www.allegro.cc/forums/view/608189</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 27 Aug 2011 07:59:53 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello,</p><p>I&#39;m using 5.0.4, and al_get_native_file_dialog_path() seems to be returning &#39;const ALLEGRO_PATH *&#39; when according to the documentation it should be returning &#39;const char&#39;.</p><p>Attempting to use al_path_cstr() on the return of al_get_native_file_dialog_path() yields an access violation.</p><p>Here is my example:
</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span>
<span class="number">  2</span>string filePath<span class="k2">;</span>
<span class="number">  3</span>
<span class="number">  4</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_FILECHOOSER"><span class="a">ALLEGRO_FILECHOOSER</span></a> <span class="k3">*</span>fileDialog<span class="k2">;</span>
<span class="number">  5</span>
<span class="number">  6</span>  ALLEGRO_PATH <span class="k3">*</span>path<span class="k2">;</span>
<span class="number">  7</span>
<span class="number">  8</span>  path <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_path_for_directory"><span class="a">al_create_path_for_directory</span></a><span class="k2">(</span> <span class="s">"/"</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number">  9</span>
<span class="number"> 10</span>  fileDialog <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_native_file_dialog"><span class="a">al_create_native_file_dialog</span></a><span class="k2">(</span> path, <span class="s">"Choose File..."</span>, <span class="s">"*.drp;*.cel"</span>, ALLEGRO_FILECHOOSER_SAVE<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span>
<span class="number"> 12</span>  <a href="http://www.allegro.cc/manual/al_show_native_file_dialog"><span class="a">al_show_native_file_dialog</span></a><span class="k2">(</span>display, fileDialog<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>
<span class="number"> 14</span>  <span class="c">//if file selected</span>
<span class="number"> 15</span>  <span class="k1">if</span><span class="k2">(</span> <a href="http://www.allegro.cc/manual/al_get_native_file_dialog_count"><span class="a">al_get_native_file_dialog_count</span></a><span class="k2">(</span>fileDialog<span class="k2">)</span> <span class="k3">&gt;</span> <span class="n">0</span> <span class="k2">)</span>
<span class="number"> 16</span>  <span class="k2">{</span>
<span class="number"> 17</span>    filePath.clear<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 18</span><span class="c">//uncommenting the next line won't compile</span>
<span class="number"> 19</span>    <span class="c">//filePath = string( al_get_native_file_dialog_path(fileDialog, SIZE_MAX) );</span>
<span class="number"> 20</span>
<span class="number"> 21</span><span class="c">//uncommenting the next line causes an access violation</span>
<span class="number"> 22</span>     <span class="c">//filePath = al_path_cstr( al_get_native_file_dialog_path( fileDialog, SIZE_MAX), ALLEGRO_NATIVE_PATH_SEP );</span>
<span class="number"> 23</span>
<span class="number"> 24</span>  <span class="k2">}</span>
</div></div><p>

I&#39;m probably doing something noobish, please advise.<br /><img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Spreggo)</author>
		<pubDate>Sat, 27 Aug 2011 05:48:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Make sure you have actually installed 5.0.4. The return type of <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_native_file_dialog_path"><span class="a">al_get_native_file_dialog_path</span></a><span class="k2">(</span><span class="k2">)</span></span> was changed to <span class="source-code"><span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span></span> shortly before the 5.0.0 release.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Todd Cope)</author>
		<pubDate>Sat, 27 Aug 2011 06:02:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve ensured that 5.0.4 is installed, which did not solve the issue.</p><p>I&#39;m using the windows builds (allegro-5.0.4-msvc-10.0.7z) from this thread: <a href="http://www.allegro.cc/forums/thread/608100">http://www.allegro.cc/forums/thread/608100</a></p><p>Are there any other low-hanging fruits I should investigate?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Spreggo)</author>
		<pubDate>Sat, 27 Aug 2011 06:39:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What&#39;s the error message the compiler is giving you?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Sat, 27 Aug 2011 06:47:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The violation when using &quot;filePath = al_path_cstr( al_get_native_file_dialog_path( fileDialog, SIZE_MAX), ALLEGRO_NATIVE_PATH_SEP );&quot; is:</p><p>Unhandled exception at 0x5516b75b in Droplet.exe: 0xC0000005: Access violation reading location 0x0000001c.</p><p>When using &quot;filePath = string( al_get_native_file_dialog_path(fileDialog, SIZE_MAX) );&quot;, the compiler says:</p><p>1&gt;main.cpp(4117): error C2440: &#39;&lt;function-style-cast&gt;&#39; : cannot convert from &#39;const ALLEGRO_PATH *&#39; to &#39;std::string&#39;
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Spreggo)</author>
		<pubDate>Sat, 27 Aug 2011 06:51:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I see the error now. The second argument to <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_native_file_dialog_path"><span class="a">al_get_native_file_dialog_path</span></a><span class="k2">(</span><span class="k2">)</span></span> is the path index. You need to use 0 for the second argument unless you are using the <span class="source-code">ALLEGRO_FILECHOOSER_MULTIPLE</span> flag.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Todd Cope)</author>
		<pubDate>Sat, 27 Aug 2011 07:09:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Unfortunately using &quot;filePath = al_path_cstr( al_get_native_file_dialog_path( fileDialog, 0 ), ALLEGRO_NATIVE_PATH_SEP );&quot; instead yielded another access violation.</p><p>I&#39;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  &#39;path = al_create_path_for_directory( &quot;/&quot; );&#39; the result is the same. It seems like this might possibly be related??</p><p>Thanks for the help everyone <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Spreggo)</author>
		<pubDate>Sat, 27 Aug 2011 07:17:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Why should &quot;/&quot; work under Windows?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sat, 27 Aug 2011 07:27:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/608189/929400#target">Matthew Leverton</a> said:</div><div class="quote"><p> Why should &quot;/&quot; work under Windows?</p></div></div><p>That stumped me for a couple minutes.</p><div class="spoiler"><p>
I think you need a drive letter, e.g. &quot;C:/&quot;.
</p></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Sat, 27 Aug 2011 07:32:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think you&#39;ve got some old headers still installed somewhere.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Sat, 27 Aug 2011 07:36:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The only headers I have anywhere are the 5.0.4 ones from the archive I mentioned before.</p><p>As for the directory thing, I guess I&#39;m ignorant on how to write it. I&#39;m assuming that &quot;C:/&quot; would work, but using that doesn&#39;t change which directory the file dialog opens to.</p><p>I think I am going to start a fresh project to try out the file dialog in isolation and see what happens.</p><p>Edit: Not sure what is going on, but the forum won&#39;t allow me to reply to this thread now. </p><p>Here is the program I created to test the native file dialog:</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span>
<span class="number">  2</span><span class="p">#include "stdafx.h"</span>
<span class="number">  3</span>
<span class="number">  4</span><span class="p">#include &lt;string&gt;</span>
<span class="number">  5</span>
<span class="number">  6</span><span class="p">#include &lt;allegro5/allegro.h&gt;</span>
<span class="number">  7</span><span class="p">#include &lt;allegro5/allegro_native_dialog.h&gt;</span>
<span class="number">  8</span><span class="p">#include &lt;allegro5/path.h&gt;</span>
<span class="number">  9</span>
<span class="number"> 10</span>
<span class="number"> 11</span><a href="http://www.allegro.cc/manual/ALLEGRO_DISPLAY"><span class="a">ALLEGRO_DISPLAY</span></a> <span class="k3">*</span>display<span class="k2">;</span>
<span class="number"> 12</span>
<span class="number"> 13</span><span class="k1">using</span> <span class="k1">namespace</span> std<span class="k2">;</span>
<span class="number"> 14</span>
<span class="number"> 15</span><span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span>
<span class="number"> 16</span><span class="k2">{</span>
<span class="number"> 17</span>  
<span class="number"> 18</span>  <span class="c">//Allegro set up</span>
<span class="number"> 19</span>  
<span class="number"> 20</span>  <a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> <span class="c">//initiate allegro 5</span>
<span class="number"> 21</span>
<span class="number"> 22</span>  display <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_display"><span class="a">al_create_display</span></a><span class="k2">(</span><span class="n">800</span>, <span class="n">600</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 23</span>
<span class="number"> 24</span>  
<span class="number"> 25</span>  <span class="c">//File dialog</span>
<span class="number"> 26</span>
<span class="number"> 27</span>  string filePath<span class="k2">;</span>
<span class="number"> 28</span>
<span class="number"> 29</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_FILECHOOSER"><span class="a">ALLEGRO_FILECHOOSER</span></a> <span class="k3">*</span>fileDialog<span class="k2">;</span>
<span class="number"> 30</span>
<span class="number"> 31</span>  ALLEGRO_PATH <span class="k3">*</span>path<span class="k2">;</span>
<span class="number"> 32</span>
<span class="number"> 33</span>  path <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_path_for_directory"><span class="a">al_create_path_for_directory</span></a><span class="k2">(</span> <span class="s">"C:/"</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number"> 34</span>
<span class="number"> 35</span>  fileDialog <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_native_file_dialog"><span class="a">al_create_native_file_dialog</span></a><span class="k2">(</span> path, <span class="s">"Choose File..."</span>, <span class="s">"*.*"</span>, ALLEGRO_FILECHOOSER_SAVE<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 36</span>
<span class="number"> 37</span>  <span class="c">//Check if fileDialog successfully created...</span>
<span class="number"> 38</span>  <span class="k1">if</span><span class="k2">(</span> fileDialog <span class="k3">=</span><span class="k3">=</span> NULL <span class="k2">)</span>
<span class="number"> 39</span>  <span class="k2">{</span>
<span class="number"> 40</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_345.html" target="_blank">fprintf</a><span class="k2">(</span> stderr, <span class="s">"Unable to create file dialog...\n"</span> <span class="k2">)</span><span class="k2">;</span>    
<span class="number"> 41</span>  <span class="k2">}</span>
<span class="number"> 42</span>
<span class="number"> 43</span>  <a href="http://www.allegro.cc/manual/al_show_native_file_dialog"><span class="a">al_show_native_file_dialog</span></a><span class="k2">(</span>display, fileDialog<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 44</span>
<span class="number"> 45</span>  <span class="k1">if</span><span class="k2">(</span> <a href="http://www.allegro.cc/manual/al_get_native_file_dialog_count"><span class="a">al_get_native_file_dialog_count</span></a><span class="k2">(</span>fileDialog<span class="k2">)</span> <span class="k3">&gt;</span> <span class="n">0</span> <span class="k2">)</span>
<span class="number"> 46</span>  <span class="k2">{</span>
<span class="number"> 47</span>    
<span class="number"> 48</span>    filePath.clear<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 49</span>    filePath <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_path_cstr"><span class="a">al_path_cstr</span></a><span class="k2">(</span> <a href="http://www.allegro.cc/manual/al_get_native_file_dialog_path"><span class="a">al_get_native_file_dialog_path</span></a><span class="k2">(</span> fileDialog, <span class="n">0</span><span class="k2">)</span>, ALLEGRO_NATIVE_PATH_SEP <span class="k2">)</span><span class="k2">;</span>
<span class="number"> 50</span>
<span class="number"> 51</span>  <span class="k2">}</span>
<span class="number"> 52</span>
<span class="number"> 53</span>
<span class="number"> 54</span>  <span class="c">//clean up</span>
<span class="number"> 55</span>
<span class="number"> 56</span>  <a href="http://www.allegro.cc/manual/al_destroy_native_file_dialog"><span class="a">al_destroy_native_file_dialog</span></a><span class="k2">(</span>fileDialog<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 57</span>
<span class="number"> 58</span>  <a href="http://www.allegro.cc/manual/al_destroy_display"><span class="a">al_destroy_display</span></a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 59</span>
<span class="number"> 60</span>  <span class="k1">return</span><span class="k2">(</span><span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 61</span><span class="k2">}</span>
</div></div><p>

This compiled but produces the following error:<br />Unhandled exception at 0x5daa1d39 in Native Dialog Test.exe: 0xC0000005: Access violation reading location 0x555c3a4b.</p><p>I&#39;m at a loss really, since from what I understand, it shouldn&#39;t even compile...</p><p>Maybe someone could try compiling using the same libraries ( <a href="http://77.55.66.239/thedmd/allegro/5.0.4/allegro-5.0.4-msvc-10.0.7z">http://77.55.66.239/thedmd/allegro/5.0.4/allegro-5.0.4-msvc-10.0.7z</a> ) and see if it reproduces?</p><p>Edit: Yep! I was doing something noobish. I looked high and low for old headers and couldn&#39;t find a thing. And then I realized that there were indeed old headers in the visual studio include folder. <img src="http://www.allegro.cc/forums/smileys/lipsrsealed.gif" alt=":-X" /></p><p>It works perfectly now, thank you all who tried to point me in the right direction from the start!</p><p>p.s. Also, the file path I was meaning to call should have been &quot;.//&quot; to get the program&#39;s directory in windows.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Spreggo)</author>
		<pubDate>Sat, 27 Aug 2011 07:59:53 +0000</pubDate>
	</item>
</rss>
