S
S
Sergey2013-12-22 22:01:05
Qt
Sergey, 2013-12-22 22:01:05

Type casting for WinAPI functions in Qt

Actually, there is such a code that does not work correctly in Qt Creator:

unsigned __int64 FreeBytesToCaller, TotalBytes, FreeBytes;

????? WinApiLibrary::GetHardDriveInfo(int flag)
{
    GetDiskFreeSpaceEx((LPCTSTR)"c:\\", (PULARGE_INTEGER)&FreeBytesToCaller, (PULARGE_INTEGER)&TotalBytes, (PULARGE_INTEGER)&FreeBytes);
    switch (flag)
    {
    case 1:
        return FreeBytesToCaller;
        break;
    case 2:
        return TotalBytes;
        break;
    case 3:
        return FreeBytes;
        break;
    }
}

I call like this:
qDebug() << wl.GetHardDriveInfo(1);
Instead of questions, I put everything that is possible (ULARGE_INTEGER, PULARGE_INTEGER, unsigned __int64) and always some left ones are obtained instead of a normal value. By the way, in codeblock this code works fine:
unsigned __int64 i64FreeBytesToCaller,
                       i64TotalBytes,
                       i64FreeBytes;

    GetDiskFreeSpaceEx ("c:/",
                                 (PULARGE_INTEGER)&i64FreeBytesToCaller,
                                 (PULARGE_INTEGER)&i64TotalBytes,
                                 (PULARGE_INTEGER)&i64FreeBytes);

    cout << i64FreeBytes/1024/1024 << "/" << i64TotalBytes/1024/1024 << '\n';

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
Zelimkhan Beltoev, 2013-12-22
@Pjeroo

long long GetHardDriveInfo(int flag)
{
  ULARGE_INTEGER FreeBytesToCaller, TotalBytes, FreeBytes;
    GetDiskFreeSpaceEx(TEXT("c:\\"), &FreeBytesToCaller, &TotalBytes, &FreeBytes);
    switch (flag)
    {
    case 1:
        return FreeBytesToCaller.QuadPart;
        break;
    case 2:
        return TotalBytes.QuadPart;
        break;
    case 3:
        return FreeBytes.QuadPart;
        break;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question