mb_set_printer

Previous  Next

 

status_t mb_set_printer( mb_interpreter_t* s, mb_print_func_t pHandler )

 


 

Set the output handler.  To remove the handler, supply NULL.  This format uses the standard handler format.

 

typedef int (*mb_print_func_t)( const char*, ... );

 

Example

 

/////////////////////////////////////////////////////////////////////////////

//

static void _setup_basic_interpreter( mb_interpreter_t* s, CConsoleCmdLineInfo::RUN_E eEnvironment )

  {

  // MyBASIC Environments defined from 0 (ENV_NONE) to 6 (ENV_MAXGRAPH) so we need to convert

  // If we're not running, set environment to ENV_NONE.  This is the same as running in cmd window

 

  int nEnvironment = eEnvironment > CConsoleCmdLineInfo::eNORUN ? int( eEnvironment ) - 1 : ENV_NONE;

 

  mb_set_environment( s, nEnvironment );

  mb_set_error_handler( s, _on_error );

  mb_set_inputer( s, _getstring );

  mb_set_printer( s, _printstring );

  mb_set_check_keyboard_handler( s, _check_keyboard );

  }

endfunc

 

/////////////////////////////////////////////////////////////////////////////

//

static int _printstring( const char* pStr, ... )

  {

  char  pBuffer[4096];

 

  va_list params;

 

  va_start( params, pStr );

  sprintf( pBuffer, pStr, va_arg( params, void* ) );

  va_end( params );

 

  if ( mb_get_environment( g_bas ) == ENV_WINDOWS )

     {

     AfxMessageBox( pBuffer );

     }

  else

     {

     printf( pBuffer );

     }

  endif

 

  return strlen( pStr );

  }

endfunc