8000 FormatMessageA · Issue #213 · holdyounger/ScopeBlog · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
FormatMessageA #213
Open
Open
@holdyounger

Description

@holdyounger

FormatMessageA

string get_sys_error_msg(unsigned long err)
{
	char _inner_msg[10240] = { 0 };
	memset(_inner_msg, 0, sizeof(_inner_msg));

	if (err == 0)
		err = GetLastError();
	LPSTR buf = NULL;
	if (::FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | 
						 FORMAT_MESSAGE_IGNORE_INSERTS,
						 NULL, 
						 err, 
						 MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
						(LPSTR)&buf, 
						0, 
						NULL))
	{


		sprintf_s(_inner_msg, sizeof(_inner_msg),"[%d]%s", err, buf);
		::LocalFree(buf);
	}
	else
	{
		snprintf(_inner_msg, sizeof(_inner_msg), " [0x%x]Unknown error", err);
	}
	string str_error_msg(_inner_msg);
	return str_error_msg;
}

blog link FormatMessageA

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0