<In Story>

Visual C++ disk format 강좌 // [C,C++] [MS Windows] [MFC] [Programming] 본문

Programming/MFC

Visual C++ disk format 강좌 // [C,C++] [MS Windows] [MFC] [Programming]

<In Story, Hi story, History> 2015. 4. 4. 19:36

http://veye.vitzro.com/Language/VisualC.htm

https://drive.google.com/folderview?id=0B6Wmc4bVWT_bbXVra0pOSjBOa28&usp=sharing

http://ultracap.tistory.com/6

http://m.blog.naver.com/whiteme7/110082652816

https://msdn.microsoft.com/en-us/library/windows/desktop/aa363870(v=vs.85).aspx

http://gparted-forum.surf4.info/viewtopic.php?id=17284

http://greenfishblog.tistory.com/149

MFC강좌

http://www.oopman.com/?page=15

 

참고 : http://kurapa.com/content-a4546_FormatEx

< 코드 >

volatile BOOLEAN bFormatExResult;

BOOLEAN __stdcall FormatExCallback(int Command,
         DWORD Modifier, PVOID Argument)
{
 if( Command == FMIFS_DONE )
  bFormatExResult = *(BOOLEAN *)Argument;

 return TRUE;
}

 

typedef void (__stdcall *PFORMATEX)(PWCHAR DriveRoot, DWORD MediaFlag,
       PWCHAR Format, PWCHAR Label,
       BOOL QuickFormat, DWORD ClusterSize,
       BOOLEAN (__stdcall *Func)(int Command, DWORD SubAction, PVOID ActionInfo) );

 

// format을 실행하는 멤버함수

int CCreateDrvDlg::FormatDrive()
{
 // format
 m_iRet = FALSE;
 WCHAR wcDrive[8];
 CString strDrive, str;
 memset( wcDrive, 0x00, sizeof(wcDrive) );
 wcscpy( wcDrive, m_wsDriveName );  
 wcscat( wcDrive, L"\\" );
 strDrive.Format( "%s:\\", wcDrive );

 str.Format( _T("Format the %ws..."), m_wsDriveName );
 m_StaticMsg.SetWindowText( str );

 while(1)
 {
  HMODULE hModule;
  hModule = LoadLibrary( _T("fmifs.dll") );
  if (hModule == NULL)
  {
   AfxMessageBox(_T("LoadLibrary(fmifs) failed"));
   str = L"LoadLibrary(fmifs) failed";
   break;
  }

  PFORMATEX FormatEx = (PFORMATEX)GetProcAddress(GetModuleHandle(_T("fmifs.dll")), "FormatEx");
  if (FormatEx == NULL)
  {
   AfxMessageBox(_T("GetProcAddress(fmifs) failed"));
   str = L"GetProcAddress(fmifs) failed";
   FreeLibrary(hModule);
   break;
  }

  FormatEx( wcDrive, FMIFM_HARDDISK, L"NTFS", L"", TRUE, 0, FormatExCallback );
  FreeLibrary(hModule);

  if( bFormatExResult == TRUE )
  {
   str.Format( _T("Complete the %ws drive format!"), m_wsDriveName );
   m_iRet = TRUE;
  }
  else
  {
   str.Format( _T("Failed the %ws drive format!"), m_wsDriveName );
   AfxMessageBox( str );
  }

  break;
 }

 m_StaticMsg.SetWindowText( str );
 return m_iRet;
}