Example of C Functions Returning Numeric Types to Basic (48206)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0

This article was previously published under Q48206

SUMMARY

The two programs shown below demonstrate how Microsoft C functions can return common numeric types to Basic.

MORE INFORMATION

For more information about passing other types of parameters between Basic and C, and a list of which Basic and C versions are compatible with each other, query in the Microsoft Knowledge Base using the following word:

BAS2C

Code Example

The following Basic program is BFUNC.BAS, which invokes several C functions, and prints out the values returned by the functions:
DECLARE FUNCTION cintfunc% CDECL ()
DECLARE FUNCTION clongfunc& CDECL ()
DECLARE FUNCTION cdoublefunc# CDECL ()
PRINT "Integer: "; cintfunc
PRINT "Long   : "; clongfunc
PRINT "Double : "; cdoublefunc
				
The following program is CFUNC.C, which contains several functions called from Basic. These functions return standard numeric types to the calling Basic program.
int cintfunc(void)        /* Basic INTEGER */ 
{
   int theint = 32767;
   return(theint);
}

long clongfunc(void)      /* Basic LONG */ 
{
   long thelong = 32769;

   return(thelong);
}

double cdoublefunc(void)  /* Basic DOUBLE */ 
{
   double thedouble = 129381.123;
   return(thedouble);
}
				
To demonstrate these programs from an .EXE program, compile and link as follows:
   BC BFUNC.BAS;
   CL /c /AM CFUNC.C;
   LINK /NOE BFUNC CFUNC;
				
BFUNC.EXE produces the following output:

Integer: 32767
Long : 32769
Double : 129381.123


Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB48206