Пример #1
0
static VOID WINAPI hbwin_SvcMainFunction( DWORD dwArgc, LPTSTR * lpszArgv )
{
    s_ServiceStatus.dwServiceType             = SERVICE_WIN32;
    s_ServiceStatus.dwCurrentState            = SERVICE_START_PENDING;
    s_ServiceStatus.dwControlsAccepted        = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
    s_ServiceStatus.dwWin32ExitCode           = 0;
    s_ServiceStatus.dwServiceSpecificExitCode = 0;
    s_ServiceStatus.dwCheckPoint              = 0;
    s_ServiceStatus.dwWaitHint                = 0;

    s_hStatus = RegisterServiceCtrlHandler( s_lpServiceName, ( LPHANDLER_FUNCTION ) hbwin_SvcControlHandler );

    if( s_hStatus != ( SERVICE_STATUS_HANDLE ) 0 )
    {
        if( s_pHarbourEntryFunc != NULL )
        {
            if( hb_vmRequestReenterExt() )
            {
                DWORD i;
                int iArgCount = 0;

                if( ! s_pHarbourControlFunc )
                {
                    /* We report the running status to SCM. */
                    s_ServiceStatus.dwCurrentState = SERVICE_RUNNING;
                    SetServiceStatus( s_hStatus, &s_ServiceStatus );
                }

                hb_vmPushEvalSym();
                hb_vmPush( s_pHarbourEntryFunc );

                for( i = 1; i < dwArgc; ++i )
                {
                    PHB_ITEM pItem = hb_stackAllocItem();

                    HB_ITEMPUTSTR( pItem, lpszArgv[ i ] );
                    if( hb_cmdargIsInternal( hb_itemGetCPtr( pItem ), NULL ) )
                        hb_stackPop();
                    else
                        ++iArgCount;
                }

                hb_vmSend( ( HB_USHORT ) iArgCount );

                hb_vmRequestRestore();
            }
            else
                HB_TRACE( HB_TR_DEBUG, ( "HVM stack not available" ) );
        }
        else
            HB_TRACE( HB_TR_DEBUG, ( "Harbour service entry function not found" ) );
    }
    else
        HB_TRACE( HB_TR_DEBUG, ( "Error registering service" ) );
}
Пример #2
0
int hb_cmdargPushArgs( void )
{
   int iArgCount = 0, i;

   for( i = 1; i < s_argc; i++ )
   {
      /* Filter out any parameters beginning with //, like //INFO */
      if( ! hb_cmdargIsInternal( s_argv[ i ], NULL ) )
      {
#if defined( HB_OS_WIN )
         if( s_lpArgV )
            HB_ITEMPUTSTR( hb_stackAllocItem(), s_lpArgV[ i ] );
         else
#endif
            hb_vmPushString( s_argv[ i ], strlen( s_argv[ i ] ) );
         iArgCount++;
      }
   }

   return iArgCount;
}
Пример #3
0
static void hb_GetDefaultPrinter( PHB_ITEM pPrinterName )
{
#if ! defined( HB_OS_WIN_CE )
   HB_BOOL bResult = HB_FALSE;

   hb_itemPutC( pPrinterName, NULL );

   if( hb_iswin2k() ) /* Windows 2000 or later */
   {
      typedef BOOL( WINAPI * DEFPRINTER ) ( LPTSTR, LPDWORD );
      DEFPRINTER fnGetDefaultPrinter;
      HMODULE hWinSpool = hbwapi_LoadLibrarySystem( TEXT( "winspool.drv" ) );

      if( hWinSpool )
      {
         fnGetDefaultPrinter = ( DEFPRINTER ) GetProcAddress( hWinSpool,
             HB_WINAPI_FUNCTION_NAME( "GetDefaultPrinter" ) );

         if( fnGetDefaultPrinter )
         {
            TCHAR lpPrinterName[ 256 ];
            DWORD dwSize = HB_SIZEOFARRAY( lpPrinterName ) - 1;

            bResult = ( *fnGetDefaultPrinter )( lpPrinterName, &dwSize );

            HB_ITEMPUTSTR( pPrinterName, lpPrinterName );
         }

         FreeLibrary( hWinSpool );
      }
   }

   if( ! bResult ) /* Win9x and Windows NT 4.0 or earlier & 2000+ if necessary for some reason i.e. dll could not load! */
   {
      TCHAR lpPrinterName[ 256 ];

      DWORD dwSize = GetProfileString( TEXT( "windows" ), TEXT( "device" ), TEXT( "" ), lpPrinterName, ( DWORD ) HB_SIZEOFARRAY( lpPrinterName ) - 1 );

      if( dwSize && dwSize < HB_SIZEOFARRAY( lpPrinterName ) )
      {
         dwSize = 0;
         while( lpPrinterName[ dwSize ] != '\0' && lpPrinterName[ dwSize ] != ',' )
            dwSize++;
         lpPrinterName[ dwSize ] = '\0';

         bResult = HB_TRUE;

         HB_ITEMPUTSTRLEN( pPrinterName, lpPrinterName, dwSize );
      }
   }

   if( ! bResult && hb_iswin9x() )
   {
      /* This option should never be required but is included because of this article
            http://support.microsoft.com/kb/246772/en-us

         This option will not enumerate any network printers.

         From the SDK technical reference for EnumPrinters();
            If Level is 2 or 5, Name is a pointer to a null-terminated string that specifies
            the name of a server whose printers are to be enumerated.
            If this string is NULL, then the function enumerates the printers installed on the local machine.
       */
      DWORD dwNeeded = 0, dwReturned = 0;

      if( EnumPrinters( PRINTER_ENUM_DEFAULT, NULL, 2, NULL, 0, &dwNeeded, &dwReturned ) )
      {
         if( dwNeeded )
         {
            PRINTER_INFO_2 * pPrinterInfo = ( PRINTER_INFO_2 * ) hb_xgrab( dwNeeded );

            if( EnumPrinters( PRINTER_ENUM_DEFAULT, NULL, 2, ( LPBYTE ) pPrinterInfo, dwNeeded, &dwNeeded, &dwReturned ) && dwReturned )
               HB_ITEMPUTSTR( pPrinterName, pPrinterInfo->pPrinterName );

            hb_xfree( pPrinterInfo );
         }
      }
   }
#else
   hb_itemPutC( pPrinterName, NULL );
#endif
}