<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Opening Files in ObjectARX Forum</title>
    <link>https://forums.autodesk.com/t5/objectarx-forum/opening-files/m-p/325976#M33414</link>
    <description>Jacob:&lt;BR /&gt;
&lt;BR /&gt;
  You are assigning the returned string to 'filename', then releasing its&lt;BR /&gt;
memory with acutRelRb().  Since you have a 'delete filename' later in your&lt;BR /&gt;
function, I assume you intended to copy the string as in&lt;BR /&gt;
'filename=strdup(fname-&amp;gt;resval.rstring)'.  However, a more efficient&lt;BR /&gt;
approach that doesn't require additional memory to be allocated would be to&lt;BR /&gt;
hijack the string from the result buffer:&lt;BR /&gt;
&lt;BR /&gt;
filename = fname-&amp;gt;resval.rstring;&lt;BR /&gt;
fname-&amp;gt;resval.rstring = NULL;&lt;BR /&gt;
...&lt;BR /&gt;
acutDelString(filename); //instead of delete&lt;BR /&gt;
-- &lt;BR /&gt;
Owen Wengerd&lt;BR /&gt;
President, ManuSoft ==&amp;gt; http://www.manusoft.com&lt;BR /&gt;
VP Americas, CADLock, Inc. ==&amp;gt; http://www.cadlock.com</description>
    <pubDate>Wed, 29 Oct 2003 10:09:10 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2003-10-29T10:09:10Z</dc:date>
    <item>
      <title>Opening Files</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/opening-files/m-p/325974#M33412</link>
      <description>I'm writing an arx program that asks a user for a file input, and then &lt;BR /&gt;
opens the file they select from a dialog box.  For some reason though, &lt;BR /&gt;
my program seems to get messed up with the filename after the user &lt;BR /&gt;
selects the file.  That is, sometimes when I select the file, it reports &lt;BR /&gt;
it's trying to open a filename which is blank, or garbled.  But if I try &lt;BR /&gt;
to open the file several times in a row, it will work again.&lt;BR /&gt;
&lt;BR /&gt;
Any Clues?&lt;BR /&gt;
&lt;BR /&gt;
Much Appreciated&lt;BR /&gt;
-Jacob&lt;BR /&gt;
&lt;BR /&gt;
bool GetFile( /* inout */ ::ifstream&amp;amp; inFile,&lt;BR /&gt;
				/* in */  char *msg)&lt;BR /&gt;
{&lt;BR /&gt;
&lt;BR /&gt;
	char *fileName;&lt;BR /&gt;
&lt;BR /&gt;
	// AutoCAD specific file open dialog control&lt;BR /&gt;
	const char* title = msg;			// Dialog box title&lt;BR /&gt;
	const char* defaultd = "/work/";	// Default directory&lt;BR /&gt;
	struct resbuf *fname;				// Result buffer&lt;BR /&gt;
&lt;BR /&gt;
	fname = acutNewRb(RTSTR);&lt;BR /&gt;
&lt;BR /&gt;
	if(acedGetFileD(title, defaultd, "LIN", 16, fname) == RTNORM)&lt;BR /&gt;
	{&lt;BR /&gt;
		fileName = fname-&amp;gt;resval.rstring;&lt;BR /&gt;
	}&lt;BR /&gt;
&lt;BR /&gt;
	// Release the result buffer&lt;BR /&gt;
	acutRelRb(fname);&lt;BR /&gt;
	&lt;BR /&gt;
	// Now that the AutoCAD part is done, lets open the file.&lt;BR /&gt;
	acutPrintf("\n Attempting to open the file %s \n",fileName);&lt;BR /&gt;
&lt;BR /&gt;
	inFile.open(fileName);&lt;BR /&gt;
&lt;BR /&gt;
	if ( !inFile )&lt;BR /&gt;
	{&lt;BR /&gt;
		acutPrintf("\n *** Can't open input file *** \n");&lt;BR /&gt;
	&lt;BR /&gt;
		delete fileName;&lt;BR /&gt;
		return false;&lt;BR /&gt;
	}&lt;BR /&gt;
	&lt;BR /&gt;
	// Report success and delete our filename pointer.&lt;BR /&gt;
	acutPrintf("\n File Opened Successfully \n");	&lt;BR /&gt;
	delete fileName;&lt;BR /&gt;
	return true;&lt;BR /&gt;
}</description>
      <pubDate>Wed, 29 Oct 2003 07:41:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/opening-files/m-p/325974#M33412</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-10-29T07:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: Opening Files</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/opening-files/m-p/325975#M33413</link>
      <description>I'm not familiar with the "ifstream" object, so i can't comment on whether&lt;BR /&gt;
or not that's causing any problems.  The one thing that i can say off the&lt;BR /&gt;
top of my head, however, is that you continue to execute the function even&lt;BR /&gt;
if acedGetFileD returns something other than RTNORM.  This means that the&lt;BR /&gt;
fileName may or may not be NULL.  Since you don't initialize the pointer&lt;BR /&gt;
fileName to NULL, it may come back as a garbled string.&lt;BR /&gt;
&lt;BR /&gt;
-Rich&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
"Jacob Feindt" &lt;JHFEINDT&gt; wrote in message&lt;BR /&gt;
news:6B7BA91C4CC7693AD73EFD754192C9A3@in.WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; I'm writing an arx program that asks a user for a file input, and then&lt;BR /&gt;
&amp;gt; opens the file they select from a dialog box.  For some reason though,&lt;BR /&gt;
&amp;gt; my program seems to get messed up with the filename after the user&lt;BR /&gt;
&amp;gt; selects the file.  That is, sometimes when I select the file, it reports&lt;BR /&gt;
&amp;gt; it's trying to open a filename which is blank, or garbled.  But if I try&lt;BR /&gt;
&amp;gt; to open the file several times in a row, it will work again.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Any Clues?&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Much Appreciated&lt;BR /&gt;
&amp;gt; -Jacob&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; bool GetFile( /* inout */ ::ifstream&amp;amp; inFile,&lt;BR /&gt;
&amp;gt; /* in */  char *msg)&lt;BR /&gt;
&amp;gt; {&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; char *fileName;&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; // AutoCAD specific file open dialog control&lt;BR /&gt;
&amp;gt; const char* title = msg; // Dialog box title&lt;BR /&gt;
&amp;gt; const char* defaultd = "/work/"; // Default directory&lt;BR /&gt;
&amp;gt; struct resbuf *fname; // Result buffer&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; fname = acutNewRb(RTSTR);&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; if(acedGetFileD(title, defaultd, "LIN", 16, fname) == RTNORM)&lt;BR /&gt;
&amp;gt; {&lt;BR /&gt;
&amp;gt; fileName = fname-&amp;gt;resval.rstring;&lt;BR /&gt;
&amp;gt; }&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; // Release the result buffer&lt;BR /&gt;
&amp;gt; acutRelRb(fname);&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; // Now that the AutoCAD part is done, lets open the file.&lt;BR /&gt;
&amp;gt; acutPrintf("\n Attempting to open the file %s \n",fileName);&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; inFile.open(fileName);&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; if ( !inFile )&lt;BR /&gt;
&amp;gt; {&lt;BR /&gt;
&amp;gt; acutPrintf("\n *** Can't open input file *** \n");&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; delete fileName;&lt;BR /&gt;
&amp;gt; return false;&lt;BR /&gt;
&amp;gt; }&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; // Report success and delete our filename pointer.&lt;BR /&gt;
&amp;gt; acutPrintf("\n File Opened Successfully \n");&lt;BR /&gt;
&amp;gt; delete fileName;&lt;BR /&gt;
&amp;gt; return true;&lt;BR /&gt;
&amp;gt; }&lt;BR /&gt;
&amp;gt;&lt;/JHFEINDT&gt;</description>
      <pubDate>Wed, 29 Oct 2003 08:24:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/opening-files/m-p/325975#M33413</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-10-29T08:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: Opening Files</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/opening-files/m-p/325976#M33414</link>
      <description>Jacob:&lt;BR /&gt;
&lt;BR /&gt;
  You are assigning the returned string to 'filename', then releasing its&lt;BR /&gt;
memory with acutRelRb().  Since you have a 'delete filename' later in your&lt;BR /&gt;
function, I assume you intended to copy the string as in&lt;BR /&gt;
'filename=strdup(fname-&amp;gt;resval.rstring)'.  However, a more efficient&lt;BR /&gt;
approach that doesn't require additional memory to be allocated would be to&lt;BR /&gt;
hijack the string from the result buffer:&lt;BR /&gt;
&lt;BR /&gt;
filename = fname-&amp;gt;resval.rstring;&lt;BR /&gt;
fname-&amp;gt;resval.rstring = NULL;&lt;BR /&gt;
...&lt;BR /&gt;
acutDelString(filename); //instead of delete&lt;BR /&gt;
-- &lt;BR /&gt;
Owen Wengerd&lt;BR /&gt;
President, ManuSoft ==&amp;gt; http://www.manusoft.com&lt;BR /&gt;
VP Americas, CADLock, Inc. ==&amp;gt; http://www.cadlock.com</description>
      <pubDate>Wed, 29 Oct 2003 10:09:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/opening-files/m-p/325976#M33414</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-10-29T10:09:10Z</dc:date>
    </item>
  </channel>
</rss>

