Author Topic: Code compiles and loads, but causes fatal error.  (Read 3601 times)

0 Members and 1 Guest are viewing this topic.

shawndoe

  • Guest
Code compiles and loads, but causes fatal error.
« on: April 19, 2012, 08:36:37 PM »

I have to publish drawings to a path that I have no control over.  To this end I am writting a routine to find a file using a recursive search of sub-directories, and return it's path (still incomplete).  My C++ coding is not advanced (I'm still weak with pointers and classes), but it is improving.

The code below compiles fine and loads into AutoCAD no problem, but when I run it I get a fatal exception.

Code: [Select]
static void FileLocator_FileLocator() {
TCHAR * SearchRootPath = NULL;// = _T("Hold");
(acedGetString (1, _T("\nEnter Search Directory Path: "), SearchRootPath));
TCHAR * SearchFileName = NULL;
(acedGetString (1, _T("\nEnter Search File Name: "), SearchFileName));
TCHAR * SearchWildCard = NULL;
(acedGetString (1, _T("\nEnter Directory Wildcard Filter<*.*>: "), SearchWildCard));
FileCheck (SearchRootPath, SearchFileName, SearchWildCard);
}// FileLocator
//
//
//
static void FileCheck (CString RootPath, CString FileName, CString DirWildCard){
int Count = 0;
CString CrntSubDir;
CString NewSubDirPath;
CFileFind finder;
if (DirWildCard){
DirWildCard = "*.*";
};
bool Testing = finder.FindFile (RootPath+DirWildCard);
TrueFalseTest (Testing, "Root Path Tested ");
while (Testing)
{
   if ((finder.MatchesMask(FILE_ATTRIBUTE_DIRECTORY)) && ((finder.IsDots()) == 0))
   {
   if (RootPath.Right(1) != _T("\\")){
CrntSubDir = _T("\\")+finder.GetFileName();
   };// if
   acutPrintf (_T("\nSub-Directory: %s\n"), CrntSubDir);
   NewSubDirPath = RootPath + CrntSubDir;
   acutPrintf (_T("\nNext Sub-Directory: %s\n"), NewSubDirPath);
   }// If MatchesMask
   else {
   acutPrintf (_T("\nFileName: %s"), (LPCTSTR) finder.GetFileName());
   }// else
   if (Count < 1000) {
   Count++;
   }// if Failsafe counter
   else if (Count >= 1000){
   Testing = FALSE;
   }// Failsafe reached
   Testing = finder.FindNextFile();
}// while
acutPrintf (_T("\nCount = %d"), Count);

}// Filecheck

My current configuration is as follows:
   Window 7 and AutoCAD 2012(64bit)
   Visual Studio 2008
   3.47GHz dual processor 6 core
   24Gig RAM
   Invidia Quadro 4000
   238Gig SSD
   
I tested this using VS2008, AutoCAD 2010 on a 32bit XP machine and the same thing happened.  I'll would be happy for any help or advise, what have I done wrong.

Thanks again for your help.
Shawndoe

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7045
  • AKA Daniel
Re: Code compiles and loads, but causes fatal error.
« Reply #1 on: April 20, 2012, 12:42:35 AM »
try allocating memory for your strings
change
Code: [Select]
TCHAR * SearchRootPathto
Code: [Select]
TCHAR  SearchRootPath[133]

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7045
  • AKA Daniel
Re: Code compiles and loads, but causes fatal error.
« Reply #2 on: April 20, 2012, 12:47:23 AM »
also have a look at acedGetFullString, to be used in combination with acutDelString() as is does the allocation for you
so you would continue to use TCHAR * SearchRootPath with this method : )

Cheers

LE3

  • Guest
Re: Code compiles and loads, but causes fatal error.
« Reply #3 on: April 20, 2012, 10:59:37 AM »
Don't do much of arx anymore... but you might also can try to use something like:
Code: [Select]
ACHAR SearchRootPath[512];
if (acedGetString (1, _T("\nEnter Search Directory Path: "), SearchRootPath) != RTNORM) return;
ACHAR SearchFileName[512];
if (acedGetString (1, _T("\nEnter Search File Name: "), SearchFileName) != RTNORM) return;
ACHAR SearchWildCard[512];
if (acedGetString (1, _T("\nEnter Directory Wildcard Filter<*.*>: "), SearchWildCard) != RTNORM) return;
... do your mojo here...

shawndoe

  • Guest
Re: Code compiles and loads, but causes fatal error.
« Reply #4 on: April 24, 2012, 05:17:19 PM »
Hi,

Sorry I haven't had a chance to try your changes and respond until now.  It has been a busy weekend. 

Changing to acedGetFullString() worked wonders.  Still not sure why it caused a fatal error, but I've never been afraid to break AutoCAD trying to find out. 

I'm making a routine to find a file in a sub-directory that changes without notice to me and replace it.  Most of this is done in LISP, but hunting a file using LISP is SSSLLOOOOWWW, especially when it may be 6 or more levels down in the tree.  So I decided to work on a file location ARX to find the file and return it's current path.  It is much faster and I need a project to cut my teeth on ARX and do real world work.

My next task is to figure out how to convert my I/O to accept and return LISP values.

There is never enough cold beer, but if either of you are in town I'll be happy to move you a few closer to that unattainable goal.

Have a good one, and thanks again.
Shawndoe

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7045
  • AKA Daniel
Re: Code compiles and loads, but causes fatal error.
« Reply #5 on: April 26, 2012, 08:40:07 AM »
mmmm beer  :laugh: