⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ramdisk.cpp

📁 利用系统内存建立虚拟磁盘
💻 CPP
📖 第 1 页 / 共 3 页
字号:
{
    static
    DEV_BROADCAST_VOLUME    DevHdr                                  ;
    DWORD                   dwFlag = BSM_ALLCOMPONENTS;
    DWORD                   volumeMask = 1 << (DriveLetter - L'A')  ;

    // Allocate our broadcast header and keep it around (static)
    // We have to keep it around because if we post the broadcast the buffers that we
    // pass into the broadcast have to stick around after this call returns.

    // Initialize our broadcast header
    DevHdr.dbcv_devicetype  = DBT_DEVTYP_VOLUME;
    DevHdr.dbcv_size        = sizeof(DEV_BROADCAST_VOLUME);
    DevHdr.dbcv_flags       = DBTF_NET;
    DevHdr.dbcv_unitmask    = volumeMask;

    // Broadcast the device change notification
    BroadcastSystemMessage( BSF_IGNORECURRENTTASK | BSF_FORCEIFHUNG | BSF_SENDNOTIFYMESSAGE ,
                            &dwFlag,
                            WM_DEVICECHANGE,
                            Notification,
                            (LPARAM)&DevHdr);

    return NO_ERROR ;
}

//==========================================================================

#pragma TODO ( ---> ClassIntaller <--- ) 

extern "C"
DWORD
WINAPI
ClassInstaller(
    IN DI_FUNCTION      InstallFunction,
    IN HDEVINFO         DeviceInfoSet,
    IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
/*

Routine Description:

    This routine acts as the class installer for Ports devices.

Arguments:

    InstallFunction - Specifies the device installer function code indicating
        the action being performed.

    DeviceInfoSet - Supplies a handle to the device information set being
        acted upon by this install action.

    DeviceInfoData - Optionally, supplies the address of a device information
        element being acted upon by this install action.

Return Value:

    If this function successfully completed the requested action, the return
        value is NO_ERROR.

    If the default behavior is to be performed for the requested action, the
        return value is ERROR_DI_DO_DEFAULT.

    If an error occurred while attempting to perform the requested action, a
        Win32 error code is returned.

*/
{
    /* these declarations are used with the original PNPPorts.DLL sample

    SP_MOVEDEV_PARAMS       MoveDevParams;
    SP_INSTALLWIZARD_DATA   iwd;
    HKEY                    hDeviceKey;
    DWORD                   Err,
                            size;

    BOOL                    result;
    */

    #ifdef _DEBUG
    WCHAR                   __string[256] ;
    CString                 cString ;
    wsprintfW( &__string[0] , L"--> 'ClassInstaller' called : Function = %s [ 0x%08X ]\n" , 
                              __DIFConverter[InstallFunction] ,
                              InstallFunction ) ;
    cString.FormatMessageW ( &__string[0] ) ; // = LPCSTR ( &__string[0] ) ;
    OutputDebugStringW ( LPCTSTR ( cString ) ) ;
    #endif

    switch(InstallFunction) {

        case DIF_INSTALLDEVICE :

            if(!SetupDiInstallDevice(DeviceInfoSet, DeviceInfoData))
            {
                #ifdef _DEBUG
                wsprintfW( &__string[0] , L"--> 'ClassInstaller' called : SetupDiInstallDevice not successfull = %d\n" , GetLastError() ) ;
                OutputDebugStringW ( &__string[0] ) ;
                #endif
                return GetLastError();
            }
            return NO_ERROR;

        case DIF_MOVEDEVICE :

            if (!SetupDiMoveDuplicateDevice(DeviceInfoSet, DeviceInfoData))
            {
                #ifdef _DEBUG
                wsprintfW( &__string[0] , L"--> 'ClassInstaller' called : SetupDiMoveDuplicateDevice not successfull = %d\n" , GetLastError() ) ;
                OutputDebugStringW ( &__string[0] ) ;
                #endif
                return GetLastError();
            }
            return NO_ERROR;


        case DIF_REMOVE:

            if (!SetupDiRemoveDevice(DeviceInfoSet, DeviceInfoData))
            {
                #ifdef _DEBUG
                wsprintfW( &__string[0] , L"--> 'ClassInstaller' called : SetupDiRemoveDevice not successfull = %d\n" , GetLastError() ) ;
                OutputDebugStringW ( &__string[0] ) ;
                #endif
                return GetLastError();
            }
            {
                HKEY    hDeviceKey              ;
                WCHAR   szDriveLetter[16]       ;

                // query drive letter
                if ( RegOpenKeyW (   HKEY_LOCAL_MACHINE , szRegServices , &hDeviceKey ) == ERROR_SUCCESS ) 
                {
                    DWORD   dwSize  ;
                    DWORD   dwError ;

                    dwSize  =   sizeof(szDriveLetter) ;
                    dwError =   RegQueryValueExW (   hDeviceKey , L"DriveLetter" , NULL , NULL , (LPBYTE)&szDriveLetter[0] , &dwSize ) ;

                    RegCloseKey(hDeviceKey);

                    BroadcastVolumeDeviceChange ( DBT_DEVICEREMOVECOMPLETE, szDriveLetter[0] );
                }
            }
            return NO_ERROR;

        case DIF_ADDPROPERTYPAGE_ADVANCED :

            #ifdef _DEBUG
            // just to demonstrate that you can use the "AfxMessageBox". More high level MFC stuff can 
            // probably not be used ...
            ::AfxMessageBox ( L" ClassInstaller ( DIF_ADDPROPERTYPAGE_ADVANCED , ... ) " , MB_OK , -1 ) ;
            #endif
            return NO_ERROR;


        case DIF_NEWDEVICEWIZARD_FINISHINSTALL :
            // we have still to update the drive view after the wizard has finished
            {
                HKEY    hDeviceKey              ;
                WCHAR   szDriveLetter[16]       ;

                // query drive letter
                if ( RegOpenKeyW (   HKEY_LOCAL_MACHINE , szRegServices , &hDeviceKey ) == ERROR_SUCCESS ) 
                {
                    DWORD   dwSize  ;
                    DWORD   dwError ;

                    dwSize  =   sizeof(szDriveLetter) ;
                    dwError =   RegQueryValueExW (   hDeviceKey , L"DriveLetter" , NULL , NULL , (LPBYTE)&szDriveLetter[0] , &dwSize ) ;

                    RegCloseKey(hDeviceKey);

                    BroadcastVolumeDeviceChange ( DBT_DEVICEARRIVAL, szDriveLetter[0] );
                }
            }
            return ERROR_DI_DO_DEFAULT;

        default :
            // Just do the default action.
            return ERROR_DI_DO_DEFAULT;
    }
}

//==========================================================================

#pragma TODO (  ---> PropPageProvider <---  )

extern "C"
BOOL APIENTRY PropPageProvider  (   LPVOID                  Info,
                                    LPFNADDPROPSHEETPAGE    AddFunc,
                                    LPARAM                  Lparam
                                )
{
   PSP_PROPSHEETPAGE_REQUEST pprPropPageRequest;
   PROPSHEETPAGE             psp;
   HPROPSHEETPAGE            hpsp;
   PQSOFT_PARAMS             params = NULL; 

   pprPropPageRequest = (PSP_PROPSHEETPAGE_REQUEST) Info;

   //
   // Allocate and zero out memory for the struct that will contain
   // page specific data
   //
   params = (PQSOFT_PARAMS)LocalAlloc ( LPTR , sizeof(QSOFT_PARAMS) ) ;
 
   if ( !params )
   {
        #ifdef _DEBUG
        CString                 cString ;
        cString.FormatMessageW ( L"Could not get sizeof(QSOFT_PARAMS) bytes of local memory ...." ) ; // = LPCSTR ( &__string[0] ) ;
        OutputDebugStringW ( LPCTSTR ( cString ) ) ;
        #endif
        return FALSE;
   }
   memset ( (void*)params , 0 , sizeof(QSOFT_PARAMS) ) ;

   if ( pprPropPageRequest->PageRequested == SPPSR_ENUM_ADV_DEVICE_PROPERTIES)
   {
        //
        // Add the property page
        //
        psp.dwSize      = sizeof(PROPSHEETPAGE);
        psp.dwFlags     = PSP_USECALLBACK; // | PSP_HASHELP;
        psp.hInstance   = (HMODULE)g_hInst;
        psp.pszTemplate = MAKEINTRESOURCE(IDD_QSOFTPROPPAGE);

        //
        // following points to the dlg window proc
        //
        psp.pfnDlgProc = PropPageDlgProc;
        psp.lParam     = (LPARAM)params;

        //
        // following points to some control callback of the dlg window proc
        //
        psp.pfnCallback = PropPageDlgCallback ;

        //
        // allocate our sheet
        //
        hpsp = CreatePropertySheetPage ( &psp ) ;
      
        if ( !hpsp )
        {
            #ifdef _DEBUG
            WCHAR                   __string[256] ;
            CString                 cString ;
            wsprintfW( &__string[0] , L"--> 'PropPageProvider' : 'CreatePropertySheetPage' not successfull\n" ) ;
            cString.FormatMessageW ( &__string[0] ) ;
            OutputDebugStringW ( LPCTSTR ( cString ) ) ;
            #endif

            LocalFree ( (PVOID)psp.lParam )    ;
            psp.lParam = NULL           ;
            return FALSE;
        }

        if (!(*AddFunc) ( hpsp, Lparam) )
        {
            DestroyPropertySheetPage( hpsp ) ;

            #ifdef _DEBUG
            WCHAR                   __string[256] ;
            CString                 cString ;
            wsprintfW( &__string[0] , L"--> 'PropPageProvider' : '*AddFunc' not successfull\n" ) ;
            cString.FormatMessageW ( &__string[0] ) ;
            OutputDebugStringW ( LPCTSTR ( cString ) ) ;
            #endif

            LocalFree ( (PVOID)psp.lParam )    ;
            psp.lParam = NULL           ;

            return FALSE;
        }
   }

   return TRUE;
} /* PropPageProvider */

//==========================================================================

extern "C"
UINT CALLBACK
PropPageDlgCallback(HWND hwnd,
                    UINT uMsg,
                    LPPROPSHEETPAGE ppsp)
{

    PQSOFT_PARAMS pParams ;
    #ifdef _DEBUG
    WCHAR                   __string[256] ;
    CString                 cString ;
    #endif

    switch (uMsg)
    {
        case PSPCB_CREATE:
        
            #ifdef _DEBUG
            wsprintfW( &__string[0] , L"--> 'PropPageDlgCallback' called  (PSPCB_CREATE)\n" ) ;
            cString.FormatMessageW ( &__string[0] ) ;
            OutputDebugStringW ( LPCTSTR ( cString ) ) ;
            #endif
        
            // in case we should need data from our " temporary storage "
            pParams = (PQSOFT_PARAMS)ppsp->lParam ;




            return TRUE;    // return TRUE to continue with creation of page

        case PSPCB_RELEASE:

            #ifdef _DEBUG
            wsprintfW( &__string[0] , L"--> 'PropPageDlgCallback' called  (PSPCB_RELEASE)\n" ) ;
            cString.FormatMessageW ( &__string[0] ) ;
            OutputDebugStringW ( LPCTSTR ( cString ) ) ;
            #endif

            if ( ppsp->lParam )
            {
                // in case we should need data from our " temporary storage "
                pParams = (PQSOFT_PARAMS)(ppsp->lParam) ;                

			    // do specific stuff here .....
				



                LocalFree ( (PVOID)ppsp->lParam )   ;
                ppsp->lParam = NULL                 ; 
            }
            return 0;       // return value ignored

        default:
        break;
    }

    return TRUE;

}

//==========================================================================

extern "C"
INT_PTR APIENTRY
PropPageDlgProc(IN HWND   hDlg,
                IN UINT   uMessage,
                IN WPARAM wParam,
                IN LPARAM lParam)
{
   
    PQSOFT_PARAMS           pParams         ;
    HWND                    hCtrlHwnd       ;
    WCHAR                   __string[256]   ;

    #ifdef _DEBUG
    CString                 cString ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -