Click here to Skip to main content
16,006,845 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: RLIOTD Pin
Gary Wheeler7-May-21 2:56
Gary Wheeler7-May-21 2:56 
JokeRe: RLIOTD Pin
Greg Utas7-May-21 3:41
professionalGreg Utas7-May-21 3:41 
GeneralRe: RLIOTD Pin
Gary Wheeler7-May-21 3:46
Gary Wheeler7-May-21 3:46 
GeneralRe: RLIOTD Pin
jsc427-May-21 6:01
professionaljsc427-May-21 6:01 
GeneralUhhh... Pin
Brisingr Aerowing20-Apr-21 12:50
professionalBrisingr Aerowing20-Apr-21 12:50 
GeneralRe: Uhhh... Pin
Jon McKee20-Apr-21 13:23
professionalJon McKee20-Apr-21 13:23 
GeneralRe: Uhhh... Pin
MarkTJohnson21-Apr-21 5:00
professionalMarkTJohnson21-Apr-21 5:00 
GeneralRe: Uhhh... Pin
Gary Wheeler5-May-21 10:51
Gary Wheeler5-May-21 10:51 
GeneralRe: Uhhh... Pin
Brisingr Aerowing7-May-21 13:37
professionalBrisingr Aerowing7-May-21 13:37 
GeneralRe: Uhhh... Pin
Gary Wheeler7-May-21 13:47
Gary Wheeler7-May-21 13:47 
GeneralRe: Uhhh... Pin
Greg Utas7-May-21 14:41
professionalGreg Utas7-May-21 14:41 
GeneralRe: Uhhh... Pin
Gary Wheeler7-May-21 15:01
Gary Wheeler7-May-21 15:01 
GeneralThere are times when I really wonder exactly what I was thinking ... Pin
OriginalGriff29-Mar-21 23:26
mveOriginalGriff29-Mar-21 23:26 
GeneralRe: There are times when I really wonder exactly what I was thinking ... Pin
Marc Clifton6-Apr-21 14:45
mvaMarc Clifton6-Apr-21 14:45 
GeneralRe: There are times when I really wonder exactly what I was thinking ... Pin
Sander Rossel11-Apr-21 0:32
professionalSander Rossel11-Apr-21 0:32 
GeneralRe: There are times when I really wonder exactly what I was thinking ... Pin
Bernhard Hiller6-Apr-21 20:52
Bernhard Hiller6-Apr-21 20:52 
GeneralRe: There are times when I really wonder exactly what I was thinking ... Pin
Dan Neely20-Apr-21 5:39
Dan Neely20-Apr-21 5:39 
GeneralC++ & Thinking about SSD & wear level Pin
raddevus27-Mar-21 11:58
mvaraddevus27-Mar-21 11:58 
GeneralRe: C++ & Thinking about SSD & wear level (updated) Pin
Peter_in_278027-Mar-21 16:03
professionalPeter_in_278027-Mar-21 16:03 
GeneralRe: C++ & Thinking about SSD & wear level (updated) Pin
raddevus27-Mar-21 17:47
mvaraddevus27-Mar-21 17:47 
GeneralRe: C++ & Thinking about SSD & wear level (updated) Pin
David O'Neil28-Mar-21 3:29
professionalDavid O'Neil28-Mar-21 3:29 
GeneralRe: C++ & Thinking about SSD & wear level (updated) Pin
raddevus28-Mar-21 3:37
mvaraddevus28-Mar-21 3:37 
GeneralRe: C++ & Thinking about SSD & wear level Pin
David O'Neil28-Mar-21 4:14
professionalDavid O'Neil28-Mar-21 4:14 
GeneralRe: C++ & Thinking about SSD & wear level Pin
raddevus28-Mar-21 5:11
mvaraddevus28-Mar-21 5:11 
GeneralRe: C++ & Thinking about SSD & wear level Pin
David O'Neil28-Mar-21 11:56
professionalDavid O'Neil28-Mar-21 11:56 
Here's a version without the GCC specific code, and a more C++ approach to the thousands separator (not that I care for that - I always have to look it up and it is a pain).

For those who use it, you will need to set your project to Multi-byte.
C++
#include <windows.h>
<h1>include <iostream></h1>

<h1>include <locale></h1>

<h1>include <sysinfoapi.h></h1>

void getOsRunTime();

struct threes : std::numpunct<char> {
    std::string do_grouping() const { return "\3"; }
    // note: comma is provided by std::numpunct<char>
};

int main() { 
    HANDLE dev = CreateFile(LPCSTR("\\\\.\\C:"), 
        FILE_READ_ATTRIBUTES, 
        FILE_SHARE_READ | FILE_SHARE_WRITE, 
        NULL, 
        OPEN_EXISTING, 
        0, 
        NULL);

    DISK_PERFORMANCE disk_info { };
    DWORD bytes;

    if (dev == INVALID_HANDLE_VALUE) {
        std::cerr << "Error opening disk\n";
        return 1;
    }

    if (!DeviceIoControl(dev, 
            IOCTL_DISK_PERFORMANCE, 
            NULL, 
            0, 
            &disk_info, 
            sizeof(disk_info), 
            &bytes, 
            NULL))
    {
        std::cerr << "Failure in DeviceIoControl\n";
        return 1;
    }
    std::cout.imbue(std::locale(std::cout.getloc(), new threes));
    std::cout << "Bytes read: " << disk_info.BytesRead.QuadPart << "\n";
    std::cout << "Bytes read: " << disk_info.BytesRead.QuadPart << "\n";
    std::cout << "Bytes written: " << disk_info.BytesWritten.QuadPart << "\n";
    getOsRunTime();
}

void getOsRunTime(){
    ULONGLONG milli = GetTickCount64();
    //3600000 milliseconds in an hour
    long days = milli / (ULONGLONG)(3600000 *24);
    milli = milli - ((ULONGLONG)3600000 *24) * days;
    long hr = milli / 3600000;
    milli = milli - (ULONGLONG)3600000 * hr;
    //60000 milliseconds in a minute
    long min = milli / 60000;
    milli = milli - (ULONGLONG)60000 * min;

    //1000 milliseconds in a second
    long sec = milli / 1000;
    milli = milli - (ULONGLONG)1000 * sec;
    std::cout << "OS has been running " << days << " days " << hr << " hours " << min << " minutes " << sec << " seconds " << milli << " ms." << std::endl;
}

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.