On 26/03/2015 5:52 p.m., Belly wrote:
Hello, just installed D today. I have this code:

import std.stdio;
import win32.windef;
import win32.winbase;

void main()
{
     LPSTR lpBuffer;
     PDWORD lpnSize;
     int result = GetComputerNameA(lpBuffer, lpnSize);

     writeln(result);
}

It passes zeroes to the API, I'm stuck and can't find a suitable sample
in the win32 repository here:
https://github.com/AndrejMitrovic/DWinProgramming

According to MSDN you need to preallocate the buffer.

import std.stdio;
import win32.windef;
import win32.winbase;

void main() {
        char[] buffer;
        buffer.length = MAX_COMPUTERNAME_LENGTH + 1;
        size_t size = MAX_COMPUTERNAME_LENGTH;

        int result = GetComputerNameA(buffer.ptr, &size);

        writeln(buffer[0 .. size]);
}

I haven't tested it. But I think that should work.
Also I think writeln will be outputting with a null terminator. So may need to -1 it.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms724295%28v=vs.85%29.aspx

Reply via email to