Quantcast
Channel: MicroStation Programming - Forum - Recent Threads
Viewing all articles
Browse latest Browse all 1677

fseek, ftell Problems in C-style native code DLL

$
0
0

Hi to all,

I am porting our MDL sources to native code and get crashes when calling fseek() and ftell(). (This source worked since more than 10 years.)

I tried the dlmSystem_mdlFopen(),... and mdlTextFile_open()... functions without success.


Here is an example of the code:

int  divutilsCreateSeekFile(char *dialogfile, char *seekfile)
{
   FILE   *fpdia=NULL, *fpseek=NULL;
   char   buf[1024], *p=NULL;
 
  int      nr=0;
  
long   position=0L;

   buf[0]= '\0';

   sprintf_s(buf,1024,"creating new seek file %s",seekfile);
   mdlOutput_promptU(buf);

   if((fpdia=dlmSystem_mdlFopen(dialogfile,"r"))!=(FILE*)NULL){
     i
f((fpseek=dlmSystem_mdlFopen(seekfile,"w"))!=(FILE*)NULL){     
          /* write all filepositions for existing dialog numbers */
        
while(fgets(buf,1023,fpdia)!=NULL){
             
    
               position= ftell(fpdia);   // CRASH

                    if(buf[0]=='['&& (p=strstr(buf,"]"))!=(char*)NULL){
                    
/* get the dialog number */
    
                  *p= '\0';
       
                nr= atoi(&buf[1]);                
                        if(nr>0)   
     
                     fprintf(fpseek,"%d %ld\n",nr,position);
               }
         }
         dlmSystem_mdlFclose(fpseek); 
      }
      dlmSystem_mdlFclose(fpdia);

   }
   return(1);

}

... same result, when using:

if((fpdia=mdlTextFile_open(dialogfile,TEXTFILE_READ))!=(FILE*)NULL){
   
if((fpseek=mdlTextFile_open(seekfile,TEXTFILE_WRITE))!=(FILE*)NULL){

        position= ftell(fpdia);   // CRASH

        ....

         mdlTextFile_close(fpseek); 

      }

      mdlTextFile_close(fpdia);

....

 
... using fssek leads also to a System Crash:

if((fpdia=dlmSystem_mdlFopen(diafile,"r"))!=(FILE*)NULL){
  ...

   fseek(fpdia,position,SEEK_SET);    // CRASH
 ...


These functions could be compiled and linked with VC2005 to a DLL without warnings or errors. The crash always occurs when the function is used after program start.

Which functions could I use to sustitute ftell and fseek?

any hints are welcome,

Thanks,

Willi


Viewing all articles
Browse latest Browse all 1677

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>