Mafa Dev

getdrive ( 최근의 드라이버 불러오는 함수) 본문

개발/USB

getdrive ( 최근의 드라이버 불러오는 함수)

마파_ 2013. 2. 18. 01:12

<MSDN 예제>

 

// crt_getdrive.c
// compile with: /c
// Illustrates drive functions including:
//    _getdrive       _chdrive        _getdcwd
//

#include <stdio.h>
#include <direct.h>
#include <stdlib.h>
#include <ctype.h>

int main( void )
{
   int ch, drive, curdrive;
   static char path[_MAX_PATH];

   // Save current drive.
   curdrive = _getdrive();

   printf( "Available drives are:\n" );

   // If we can switch to the drive, it exists.
   for( drive = 1; drive <= 26; drive++ )
   {
      if( !_chdrive( drive ) )
      {
         printf( "%c:", drive + 'A' - 1 );
         if( _getdcwd( drive, path, _MAX_PATH ) != NULL )
            printf( " (Current directory is %s)", path );
         putchar( '\n' );
      }
   }

   // Restore original drive.
   _chdrive( curdrive );
}

=====================================================================================================================

< 실행화면 >

Available drives are:
A: (Current directory is A:\)
C: (Current directory is C:\)
E: (Current directory is E:\testdir\bin)
F: (Current directory is F:\)
G: (Current directory is G:\)

 

 

 

 

 

< 실행 예제 >

 

int i=1;
char j[100]={0,};
char k='\0';
char* park1;
char* q;

 

 

 switch(nEventType){
 case DBT_DEVICEARRIVAL:


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

  curdrive = _getdrive();
  park1 = ":\\security.exe.";
  

  for( drive = 1; drive <= 26; drive++ )
  {
   if( !_chdrive( drive ) )
   {
    //여기다 함수를 추가하세요
    j[drive] = drive + 'A';
    i++;
   }
  }

  
  k=j[i]+2;
  q = &k;
  strcat(q, park1);
  AfxMessageBox(q);
  printf("%c:",k);
  putchar( '\n' );

  _chdrive( curdrive );

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

  WinExec(q,SW_SHOW);
  AfxMessageBox("USB장치 연결은 성공");
  break;