On Monday, 16 October 2017 at 21:48:35 UTC, Nieto wrote:
How do I convert/create a D string from LPVOID (void*)?
string GetLastErrorMessage() {
LPVOID lpMsgBuf;
DWORD errorMessageID = GetLastError();
FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
errorMessageID,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
cast(LPSTR) &lpMsgBuf,
0, NULL);
return ??
}
If you're using this solely for Windows error messages, the
std.windows.syserror module has a function, sysErrorString, which
wraps it up for you. It also provides a WindowsException you can
throw which, given an Windows error code, will contain a
formatted system error message.
https://dlang.org/phobos/std_windows_syserror.html