Microsoft KB Archive/71795

= Basic PDS 7.10 Call to C Routine to Open > 15 Files Fails =

Article ID: 71795

Article Last Modified on 11/21/2006



This article was previously published under Q71795



SYMPTOMS
Calling a Microsoft C 6.00 routine from a Microsoft Basic Professional Development System (PDS) version 7.10 program and trying to open more than 15 files in the C routine will fail. The C routine cannot open more than 15 files even if the C run-time library has been modified to support more than 15 files, and the Basic program calls interrupt 21 Hex, with function 67 Hex, to obtain more file handles.



STATUS
Microsoft has confirmed this to be a bug in Microsoft Basic Professional Development System (PDS) version 7.10 and Microsoft C PDS version 6.00. We are researching the problem and will post new information here in the Microsoft Knowledge Base as it becomes available.



MORE INFORMATION
The failure occurs because the C file-open routines check the run-time variable _nfile to see if there are enough file handles available to open the file.

You can modify the C 6.00 run time to support more than 15 files, as described in the C 6.00 documentation; however, if you link a C 6.00 routine with Microsoft Basic PDS 7.10, the modified portion of the run time will not get incorporated into the actual executable program (the Basic run-time code is used instead).

Increasing the file handle count by calling interrupt 21 Hex with function 67 Hex in Basic does not resolve the problem because this method does not change the run-time variable that C 6.00 is checking (_nfile) to indicate the new number of available file handles.

The following method to work around the problem directly modifies the run-time variable _nfile from the C 6.00 function that is called from Basic PDS 7.10. This workaround is based on internal details of the C and Basic run-time routines, and is not guaranteed to work for versions other than those specified above. If you chose to use this workaround, be certain that the call to interrupt 21 Hex with function 67 Hex (to increase the available file handles) has been done and returned successfully before calling the C function that modifies _nfile.

Compile and link the workaround programs as follows: BC /o test ; CL /c /AM files.c ; LINK test files,,,BCL71ENR MLIBCE QBX /NOE /NOD ;

TEST.BAS
'$INCLUDE: 'QBX.BI' DECLARE SUB profile CDECL DIM InRegs AS RegType, OutRegs AS RegType CLS InRegs.ax = &H6700 InRegs.bx = 40 CALL Interrupt(&H21, InRegs, OutRegs) 'Increases MS-DOS file handles. CALL profile  ' Calls the C routine. PRINT &quot;In Basic again.&quot; END

FILES.C

 * 1) define SYSCALL 0x21
 * 2) include 
 * 3) include 
 * 4) include 
 * 5) include 
 * 6) include 
 * 7) include 
 * 8) include 
 * 9) include 
 * 10) include 
 * 11) include 
 * 12) include 

union REGS regs; extern int _nfile;                 /* run-time variable */ void extern profile(void);

void extern profile(void) {  int i,handle[20]; char filename[20][20];

_nfile = 40;

strcpy(filename[0],&quot;t1.tmp\0&quot;);  strcpy(filename[1],&quot;t2.tmp\0&quot;); strcpy(filename[2],&quot;t3.tmp\0&quot;);  strcpy(filename[3],&quot;t4.tmp\0&quot;); strcpy(filename[4],&quot;t5.tmp\0&quot;);  strcpy(filename[5],&quot;t6.tmp\0&quot;); strcpy(filename[6],&quot;t7.tmp\0&quot;);  strcpy(filename[7],&quot;t8.tmp\0&quot;); strcpy(filename[8],&quot;t9.tmp\0&quot;);  strcpy(filename[9],&quot;t10.tmp\0&quot;); strcpy(filename[10],&quot;t11.tmp\0&quot;); strcpy(filename[11],&quot;t12.tmp\0&quot;); strcpy(filename[12],&quot;t13.tmp\0&quot;); strcpy(filename[13],&quot;t14.tmp\0&quot;); strcpy(filename[14],&quot;t15.tmp\0&quot;); strcpy(filename[15],&quot;t16.tmp\0&quot;); strcpy(filename[16],&quot;t17.tmp\0&quot;); strcpy(filename[17],&quot;t18.tmp\0&quot;); strcpy(filename[18],&quot;t19.tmp\0&quot;); strcpy(filename[19],&quot;t20.tmp\0&quot;);

for (i=0;i<20;i++) {       handle[i] = sopen(filename[i], O_BINARY | O_RDWR | O_CREAT,                          SH_DENYNO, S_IREAD | S_IWRITE); if( handle[i] == -1 ) printf( &quot;Can't open file %d\n&quot;,i ); else printf( &quot;Opened file %d!\n&quot;,i); } printf(&quot;end of C, going back to Basic \n&quot;); }

Additional query words: BasicCom SR# S910228-82 buglist7.10 S_C

Keywords: KB71795

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.