On Thursday, 26 March 2015 at 17:41:37 UTC, rumbu wrote:
On Thursday, 26 March 2015 at 16:46:06 UTC, Belly wrote:
No, wait, the first code is even better because it uses the headers so I don't need to declare the API myself and it uses the MAX_COMPUTERNAME_LENGTH define, too, nice!

Using this will return only the first 15 characters of the computer name, if longer.

Please use the unicode version of the function GetComputerNameW instead of the ANSI one (GetComputerNameA), because the second one has a known bug, returning always 0 as required buffer size.

import std.stdio;
import std.c.windows.windows;

wstring getComputerName()
{
        enum ERROR_BUFFER_OVERFLOW = 111;
        uint size;
if (GetComputerNameW(null, &size) == 0 && GetLastError() == ERROR_BUFFER_OVERFLOW)
        {
                wchar[] buf = new wchar[size];
                if (GetComputerNameW(buf.ptr, &size))
                        return buf[0 .. size].idup;
        }
        return "Unknown";
}

int main(string[] argv)
{
        writeln(getComputerName());
        getchar();
    return 0;
}

I changed the code to use GetComputerName, so I guess GetComputerNameA is actually used, right? Anyway it's not really important, I'm just playing around with winAPIs to get a feel of things. I'm making a simple health cheat for a game I've written in FreeBasic!

I'm going through a nice D2 tutorial here:
http://ddili.org/ders/d.en

If anyone reading this can save me some time and help me with this: How to declare a byte pattern, for example to pass to WriteProcessMemory?

I guess it's uint[] bytes;
How do I set it to 0x12345678 ?

Reply via email to