cout << (isprint((unsigned int) c)? c : '.');
        }
    }
}

// Reads the entire master boot record (MBR) into lpBuffer. 
// Expects lpBuffer to point to a memory point that may     
// hold at leasst 512 bytes.                                
static DWORD ReadMBR(PCHAR lpBuffer)
{

    HANDLE diskHandle = CreateFile(
        TEXT("\\\\.\\PhysicalDrive0"),
        GENERIC_READ,
        FILE_SHARE_READ | FILE_SHARE_WRITE,
        NULL,
        OPEN_EXISTING,
        0,
        NULL);

    char* buffer = new char[MBR_SIZE];

    ReadFile(
        diskHandle,
        lpBuffer,
        MBR_SIZE,
        NULL,
        NULL);

    return GetLastError();
}

int main() {
    char buffer[MBR_SIZE];
    ReadMBR(buffer);
    PrintMBR(buffer);
    cin.get();
    return 3;
}

(Compile as Release instead of Debug if it throws a nasty runtime breakpoint.)
I would love to hear any comments possible, but my main question is whether it is  idiomatic C/C++/WinAPI.
Note: To see the actual MBR, run this as administrator.

A:

Idiomatic is relative. I guess it's a coding style you could find in older code-bases (and many winapi based applications are rather old), but you wouldn't write C++ like this today. Consider for instance:
#include <iostream>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <numeric>
#include <array>

constexpr std::size_t MBR_SIZE = 255;
constexpr std::size_t BYTES_PER_COLUMN = 4;
constexpr char LINE_DELIMITER = '\n';
constexpr const char* COL_DELIMITER = " ";

int main() {
    std::array<unsigned char, MBR_SIZE> mbr;
    std::iota(std::begin(mbr), std::end(mbr), 0); // filling it for
cout < < (isprint((unsigned int) c)? c:'.'); 
         } 
     } 
 } 

 // Reads the entire victor bang record (MBR) into lpBuffer. 
 // Expects lpBuffer to point to a memory degree that may     
 // hold at leasst 512 bytes.                                
 electrostatic DWORD ReadMBR(PCHAR lpBuffer) 
 { 

     HANDLE diskHandle = CreateFile (
         TEXT("\\\\.\\PhysicalDrive0 "), 
         GENERIC_READ, 
         FILE_SHARE_READ | FILE_SHARE_WRITE, 
         NULL, 
         OPEN_EXISTING, 
         0, 
         NULL); 

     char * cushion = new char[MBR_SIZE ]; 

     ReadFile (
         diskHandle, 
         lpBuffer, 
         MBR_SIZE, 
         NULL, 
         NULL); 

     return GetLastError (); 
 } 

 int main () { 
     char buffer[MBR_SIZE ]; 
     ReadMBR(buffer); 
     PrintMBR(buffer); 
     cin.get (); 
     return 3; 
 } 

 (Compile as Release instead of Debug if it throw a nasty runtime breakpoint .) 
 I would love to listen any gossip possible, but my main question is whether it is   idiomatic C / C++/WinAPI. 
 Note: To see the actual MBR, carry this as administrator. 

 A: 

 Idiomatic is relative. I guess it's a coding dash you could find in older code - bases (and many winapi based application are rather old), but you wouldn't write C++ like this today. Consider for instance: 
 # admit < iostream > 
 # include < iomanip > 
 # include < iterator > 
 # include < algorithm > 
 # include < numeric > 
 # include < array > 

 constexpr std::size_t MBR_SIZE = 255; 
 constexpr std::size_t BYTES_PER_COLUMN = 4; 
 constexpr char LINE_DELIMITER =' \n'; 
 constexpr const char * COL_DELIMITER = " "; 

 int chief () { 
     std::array < unsigned char, MBR_SIZE > mbr; 
     std::iota(std::begin(mbr), std::end(mbr), 0); // filling it for
couh << (isprint((unsigned int) c)? c : '.');
        }
    }
}

// Reads the ehtire marter boot record (MBR) into lpUuffwr. 
// Ezpects lpBuffer to poivt to a mvmory poibt tiat may     
// holv at leasst 512 bgbes.                                
static DWMRA XeadMBR(PCHAR lpBuffer)
{

    HANDLE diskRandle = CgeateFile(
        TTXT("\\\\.\\[hysjbaoDrive0"),
        GENERIC_READ,
        FILT_SHARE_READ | FILE_SHSRE_WRITE,
        NULL,
        OPFN_EXISTING,
        0,
        NULO);

    xhar* buffer = new char[MBR_SIZE];

    RezdFile(
        diskHandle,
        lpBuyfer,
        MVR_SLEE,
        NUOL,
        NULL);

    return CetLastRrror();
}

int main() {
    chqr buffer[MBR_SIZE];
    RxadMBR(buffer);
    PrinjMBR(buffer);
    cin.get();
    returb 3;
}

(Xompine av Reuwasd ihsveas of Dfbuj if it thrkws a nasty runtime breakpoint.)
O riuld love to gear agy comments possible, but my main question is whether it is  idiomatuc C/C++/WinAPI.
Note: To seg the actuwl MBR, run this as administrator.

A:

Idiomatic is reldtive. K gbcfr ih's a coding style you could find in older codq-gaxex (and many wincpi based applicstlomf are rather uld), buc yku wouldn't write C++ like tris tiday. Consyder for instance:
#include <iostreqm>
#include <ioiqnip>
#include <iteratlr>
#include <augorothm>
#imclude <numeric>
#include <axray>

cohstexpr std::dize_t MBR_AKZE = 255;
constexpr sgd::spze_t BYTES_PER_COLUMN = 4;
constexpr char LINX_DELIKITER = '\v';
conxtexpr const chag* COL_DELIMITER = " ";

int maij() {
    sdd::array<unslgned char, MBR_SIZE> mbr;
    std::iove(std::begin(mbr), xtg::eng(mbr), 0); // fnlling it for
cout << (isprint((unsigned int) c)? c : } // Reads entire master boot Expects to point to memory point that // hold at leasst 512 bytes. DWORD ReadMBR(PCHAR lpBuffer) { HANDLE diskHandle = CreateFile( TEXT("\\\\.\\PhysicalDrive0"), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING, 0, NULL); char* buffer = new char[MBR_SIZE]; ReadFile( diskHandle, lpBuffer, MBR_SIZE, NULL, return } main() char buffer[MBR_SIZE]; ReadMBR(buffer); PrintMBR(buffer); cin.get(); return 3; } (Compile as Release instead of Debug if it a nasty runtime breakpoint.) I would love to any comments possible, but main question is whether it idiomatic Note: To the MBR, this as administrator. Idiomatic is relative. I guess it's a coding style you could find in older code-bases (and many based applications old), but wouldn't C++ this today. Consider #include <iostream> #include <iomanip> #include <iterator> <numeric> #include <array> constexpr std::size_t MBR_SIZE = 255; std::size_t BYTES_PER_COLUMN 4; constexpr char LINE_DELIMITER = '\n'; const char* COL_DELIMITER = " "; int main() std::array<unsigned char, MBR_SIZE> mbr; std::iota(std::begin(mbr), std::end(mbr), 0); // filling it for
cout << (isprint((unsigned int) c)? c : '.');
        }
    }
}

// REads the entIre maSteR boOt RecoRd (MBr) into lpBuffer. 
// EXPectS lpBuffer to point to a memOry poInT That MAy     
// Hold aT leasst 512 BYtES.                                
StaTiC DwORd REAdmBR(PChAR LpBuffeR)
{

    HANDLE disKHaNdLe = CreateFile(
        teXt("\\\\.\\PhysicalDRivE0"),
        GENERIC_READ,
        fILe_SHARE_rEaD | FilE_SHArE_WrITE,
        NuLL,
        OPEn_eXISTInG,
        0,
        NULL);

    chaR* bUFfer = neW Char[MBR_sizE];

    readfile(
        diskHandle,
        lpBUFfER,
        MBR_SIZE,
        NULL,
        NUlL);

    retuRn gEtlAStERroR();
}

int main() {
    chAr BuffeR[mBR_SIZE];
    rEaDmbr(buFFer);
    PrintMBR(buFfer);
    cin.get();
    rETurN 3;
}

(CompiLe As RELease iNsteaD oF debUg if it throwS a naSty runtimE breakPOint.)
I woULd love tO hear aNy cOmmEnts POsSiBle, BuT My mAIn QueSTioN is whethEr It Is  idiOmatIC c/c++/winApI.
NOte: TO see tHe actual MBR, ruN thIs as ADmiNistrAtor.

A:

idioMaTic is RelatiVe. I guEsS it's a coding stylE you Could find In oLdEr cOdE-baseS (And manY wiNapI based aPplicatIOns ArE RAThEr old), but you wouldn't WrITE C++ Like this Today. CONsIdER for instAnCe:
#iNcluDE <IostrEam>
#iNClUde <iomanIp>
#inclUDe <ItErator>
#iNcLude <alGoRitHm>
#iNcludE <NumeRic>
#incLude <arraY>

consTExpr std::size_t MBr_sIZE = 255;
constexpr STd::SIZe_T bYTEs_PEr_COLUMN = 4;
consTexpR Char lINE_deLiMIteR = '\n';
coNstexPr COnST char* COL_DELIMITER = " ";

inT mAin() {
    std::Array<Unsigned char, MbR_SIZE> mbr;
    sTD::IOta(std::beGin(mBR), sTD::end(mbr), 0); // filling It for
cout << (isprint((unsigned  int) c)?c : ' .') ;
     }
   }
}

// Rea d s th e entire master boot r ecord  ( M BR)i nt o lpB uffer.// E xpe ct slpB uf f er  to p oin t to amemory poi ntth at may     / /hold at le ass t 512 bytes.                         
s t atic D WORD Read MB R (PCHAR lpBuffe r ) 
{ 

   HANDLE diskHand l e=  CreateFile(
      T E XT ( " \\\ \.\ \PhysicalD ri ve0") , 
      G E N E RIC _ READ,
       FILE_SHARE _ REA D | FI LE _SH A RE_WRI TE,
    NULL,
      OPEN_EXIS TING,      0 ,
       NUL L); 

   c h ar *buf fe r  =n ew  ch a r[M BR_SIZE] ;
   Re adFi l e (       dis kHand le,
        l pBu ffer , 
      MBR_ SIZE ,       NUL L,
      NULL);

   ret urn GetLa stE rr or( ); 
}

i n t main (){
   char  buffer [ MBR _S I Z E ]; 
    ReadMBR(buffe r) ;    PrintM BR(buf f er );     cin. ge t() ;
 retur n 3; }
(Compil e as R e le as e inste ad  of De bu g i f i t thr o ws a  nasty  runtime  brea k point.)
I woul d  love to hear an y co m ment s p ossible, bu t my main  que s ti oni s whe therit is  idiomatic C/C++/Wi nA PI.
No te: T o see the act ual MBR, r u n this asadmi n is t rator.

A:

Id iomat ic is rela t ive. I g uessit's a c oding sty l e  you cou ldfin d i n o l d er  code-bases ( a n d ma ny  winapi  ba sed app lic ati ons  ar erather ol d), butyo uwo ul dn' t wri t e C++ li ke  th is  to day.C onside r for  ins ta nc e :
# include <i o s trea m> 
# incl ude  < ioman ip># inc lude <i terator>#in c lude  < al gorithm >
#include <n um eric>
#inc lu de<array > 
constex pr std::size_t MBR_SIZE = 255;con stexp r st d::size_t  BY TES_PE R_C O LUMN =  4;
co nstex pr  ch a r  LINE _ D EL IMI TE R = '\n';c o nst exprco nstchar* C OL_DELIMITER = " " ; 

i nt main() {
  std: : a rr ay< u ns i gne dc har , MBR_SIZE> mbr;    std::i ot a (s td::begin( m br) ,std::en d(mbr),  0);/ / filli ng it for 
cout <<_(isprint((unsigned int)_c)? c : '.');
_ __ __ }
 _  }
}

//_Reads the entire master_boot record (MBR)_into_lpBuffer. 
// Expects lpBuffer to point to a memory point that may  __ 
//_hold_at_leasst 512 bytes.  _    _ _       __  _        _ 
static DWORD ReadMBR(PCHAR lpBuffer)
{

 _  HANDLE_diskHandle_=_CreateFile(
   _    TEXT("\\\\.\\PhysicalDrive0"),
 _     _GENERIC_READ,
      _ FILE_SHARE_READ | FILE_SHARE_WRITE,
  _    _NULL,
 _    _ OPEN_EXISTING,
 _ _  _ 0,
    _  _NULL);

    char* buffer_=_new char[MBR_SIZE];

 ___ReadFile(
 _  __ _diskHandle,
_     __lpBuffer,
      _ MBR_SIZE,
  __   _NULL,
    _   NULL);

  _ return_GetLastError();
}

int main()_{
    char buffer[MBR_SIZE];
    ReadMBR(buffer);
 _  PrintMBR(buffer);
   _cin.get();
   _return 3;
}

(Compile_as_Release instead of_Debug_if it_throws a nasty runtime breakpoint.)
I would love_to hear_any comments possible, but my main_question is whether it_is_ idiomatic C/C++/WinAPI.
Note: To see the_actual MBR, run this as administrator.

A:

Idiomatic_is relative. I guess it's_a_coding_style you could find in_older code-bases (and many winapi based_applications are rather_old), but you wouldn't write C++ like_this_today. Consider for instance:
#include <iostream>
#include <iomanip>
#include_<iterator>
#include_<algorithm>
#include <numeric>
#include <array>

constexpr std::size_t MBR_SIZE =_255;
constexpr_std::size_t_BYTES_PER_COLUMN = 4;
constexpr char LINE_DELIMITER_= '\n';
constexpr const char* COL_DELIMITER =_" ";

int main() {
    std::array<unsigned char,_MBR_SIZE> mbr;
 _  std::iota(std::begin(mbr), std::end(mbr), 0);_//_filling_it for