ununderstood behaviour with file handles passed by a library

 

Hi everyone,

i have experienced a problem with a file handle passed by a function resident in an external library (.ex4).

Basically i was creating a function that opens a text file (to write all the initial standard text lines) and then passes back its handle to the expert for the prosecution (write something more ... and then close the file).

Of course the expert "receives" the handle of the opened file correctly - i made it print it out - but when "he" tries to write down something more and then close the file it will report "handle 1 does not exist in filewrite" / "handle 1 does not exist in fileclose".

i'm sure that "1" its the right file handle, since it's the only one open file and i made it print it out both from the library and from the expert.

Also, if I open the same file from the same expert instead from a library, everything will work fine.

anybody can help to understand this behaviour?

 
Once you close the file, the handle will be invalid
 

no zuegg, while the expert tries to write something else the file is still open.

here's a piece of the code:

the expert:

int h=MyFileOpen (title, FILE_WRITE);

string s0= "..."; 
FileWrite(h,s0);
FileClose(h); 

the external function:

int MyFileOpen (string title, int mod)
{
   int handle;
   string s, fname;
   //----->
   fname = title+".txt";
   handle = FileOpen(fname, mod);
   if(handle<1)
    {
     Print("File not found, the last error is: ", GetLastError());
     return(handle);
    }

   FileWrite(handle,"something");
 
return (handle);
}