How to get DXGI_ERROR description? - error-handling

In a D3D12 program, I encounter a DGXI_ERROR (CreateSharedHandle returns an int <0), but I could not find a way to translate it into the "error description" or "error name" (or both).
I have a description by Microsoft: https://learn.microsoft.com/en-us/windows/win32/direct3ddxgi/dxgi-error
Is there such function out there ?

For development purposes, the "Error Lookup Tool" in Visual Studio can tell you the translation and code from a value.
You can also enable "DXGI Debugging" which will provide more information about error cases in the debug output window for your debug builds. See this blog post.
Programmatically, you can do it with FormatMessage on Windows 10:
LPWSTR errorText = nullptr;
DWORD result = FormatMessageW(
FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ALLOCATE_BUFFER, nullptr, hr,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPWSTR>(&errorText), 0, nullptr );
if (result > 0)
{
// errorText contains the description of the error code hr
LocalFree( errorText );
}
else
{
// Error not known by the OS
}
See this blog post.

Related

sd_bus_get_property_string equivalent for gdbus?

I try to read out the ActiveState property of a systemd unit with gdbus/glib-2.0. For sd-bus there exists the convenient function sd_bus_get_property_string. What would the equivalent call if gdbus is used. I am ware of the gdbus introspect command, but I need to implement that in C/C++.
I managed to start and stop units already. Now I need to verify that a unit has been successful started/stopped. I am new to dbus and have been searching the internet for some hours for an example, without finding something helpful.
I also implemented some systemd stuff in C++. Here was my solution:
std::string Unit::GetPropertyString(const std::string& property) const
{
sd_bus_error err = SD_BUS_ERROR_NULL;
char* msg = nullptr;
int r;
r = sd_bus_get_property_string(m_bus,
"org.freedesktop.systemd1",
("/org/freedesktop/systemd1/unit/" + m_unit).c_str(),
"org.freedesktop.systemd1.Unit",
property.c_str(),
&err,
&msg);
if (r < 0)
{
std::string err_msg(err.message);
sd_bus_error_free(&err);
std::string err_str("Failed to get " + property + " for service "
+ m_name + ". Error: " + err_msg);
throw slib_exception(err_str);
}
sd_bus_error_free(&err);
// Free memory (avoid leaking)
std::string ret(msg);
free (msg);
return ret;
}
From this, you can call
activestate = GetPropertyString("ActiveState");
substate = GetPropertyString("SubState");
I found that a lot of the <systemd/sd-bus.h> wasn't well documented. There is a fantastic explanation by the author here:
http://0pointer.net/blog/the-new-sd-bus-api-of-systemd.html
But outside of the few examples he gives, I found it was easier to inspect the source code. Specifically, I found it nice looking into the source-code of the systemctl and journalctl applications to see how sd-bus was used in those contexts.

Linux-Xenomai Serial Communication using xeno_16550A module

I'm starter of RTOS and I'm using Xenomai v2.6.3.
I'm trying to get some data using Serial communication.
I did my best on the task following the xenomai's guide and open sources, but it doesn't work well.
the link of the guide --> (https://xenomai.org//serial-16550a-driver/)
I just followed the sequence to use the module xeno_16550A. (with port io = 0x2f8 and irq=3)
I followed open source http://www.acadis.org/pages/captain.at/serial-port-example
It works well in write task, but read task doesn't work well.
It gave me the error sentence with error while RTSER_RTIOC_WAIT_EVENT, code -110 (it means connection timed out)
Moreover I checked the irq number3 by typing command 'cat /proc/xenomai/irq', but the interrupt number doesn't increase.
In my case, I don't need to write data, so I erase the write task code.
The read task proc is follow
void read_task_proc(void *arg) {
int ret;
ssize_t red = 0;
struct rtser_event rx_event;
while (1) {
/* waiting for event */
ret = rt_dev_ioctl(my_fd, RTSER_RTIOC_WAIT_EVENT, &rx_event );
if (ret) {
printf(RTASK_PREFIX "error while RTSER_RTIOC_WAIT_EVENT, code %d\n",ret);
if (ret == -ETIMEDOUT)
continue;
break;
}
unsigned char buf[1];
red = rt_dev_read(my_fd, &buf, 1);
if (red < 0 ) {
printf(RTASK_PREFIX "error while rt_dev_read, code %d\n",red);
} else {
printf(RTASK_PREFIX "only %d byte received , char : %c\n",red,buf[0]);
}
}
exit_read_task:
if (my_state & STATE_FILE_OPENED) {
if (!close_file( my_fd, READ_FILE " (rtser)")) {
my_state &= ~STATE_FILE_OPENED;
}
}
printf(RTASK_PREFIX "exit\n");
}
I could guess the causes of the problem.
buffer size or buffer is already full when new data is received.
rx_interrupt doesn't work....
I want to check whether the two things are wrong or not, but How can I check?
Furthermore, does anybody know the cause of the problem? Please give me comments.

How to get description of winhttp errors using error codes?

I am making a program that uses winhttp library. To handle various exceptions, I have created a header file. The error is thrown by using GetLastError() function which is passed to the exception class as DWORD variable. But I want to print the description of error and not just the error number. I tried using FormatMessage function, its working for error 6 but not for others viz error 12002. I am using it like:
WinHttpException(DWORD error)
{
LPTSTR lpszFunction = "Function";
LPVOID lpMsgBuf;
LPVOID lpDisplayBuf;
DWORD dw = error;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
// Display the error message and exit the process
lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
(lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) * sizeof(TCHAR));
StringCchPrintf((LPTSTR)lpDisplayBuf,
LocalSize(lpDisplayBuf) / sizeof(TCHAR),
TEXT("%s failed with error %d: %s"),
lpszFunction, dw, lpMsgBuf);
MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK);
m_message = boost::lexical_cast<std::string>(lpDisplayBuf);
}
I got this code from this Microsoft link.. Is there any other way to do that? Or what arguments should i use in FormatMessage function to make this work?
Thanks in advance.
WinHTTP error messages are contained in the winhttp.dll module and FormatMessage() function allows you to retrieve them using FORMAT_MESSAGE_FROM_HMODULE flag (as per FormatMessage() documentation):
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_HMODULE |
FORMAT_MESSAGE_IGNORE_INSERTS,
GetModuleHandle(TEXT("winhttp.dll")),
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPTSTR>(&lpMsgBuf),
0, NULL);

Microsoft Speech Platform: "SPF_NLP_SPEAK_PUNC" does not work

I'm using Speech Platform for TTS(text-to-speech).
I want to get speech outputs with pronunciation of symbols (punctuation marks).
MSDN says:
ISpVoice::Speak speaks the contents of a text string or file.
HRESULT Speak(
LPCWSTR *pwcs,
DWORD dwFlags,
ULONG *pulStreamNumber
);
...
dwFlags
[in] Flags used to control the rendering process for this call. The flag values are contained in the SPEAKFLAGS enumeration.
...
http://msdn.microsoft.com/en-us/library/speechplatform_ispvoice_speak.aspx
SPEAKFLAGS
...
SPF_NLP_SPEAK_PUNC
Punctuation characters should be expanded into words (for example, "This is a sentence." would become "This is a sentence period").
...
http://msdn.microsoft.com/en-us/library/speechplatform_speakflags.aspx
so, I wrote code below:
#define TOKEN_ID L"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech Server\\v11.0\\Voices\\Tokens\\TTS_MS_en-US_Helen_11.0"
int main(void) {
CoInitialize(NULL);
ISpVoice* spVoice = NULL;
CoCreateInstance(CLSID_SpVoice, NULL,
CLSCTX_INPROC_SERVER, IID_ISpVoice, (void**)&spVoice);
ISpObjectToken* token = NULL;
SpGetTokenFromId(TOKEN_ID, &token, FALSE);
spVoice->SetVoice(token);
spVoice->Speak(L"This is a sentence.",
SPF_DEFAULT | SPF_NLP_SPEAK_PUNC, NULL);
CoUninitialize();
return 0;
}
But this doesn't work as expected.
This outputs speech of "this is a sentence", not pronouncing "period".
Please help me.
Looking at your code, it appears you're using the Server voices. Those voices (as far as I can tell) don't support SPF_NLP_SPEAK_PUNC.

tftpGet error from tftpLib in VxWorks

I'm writing a little function that downloads a file from a TFTP server using VxWork's tftpLib (http://www.vxdev.com/docs/vx55man/vxworks/ref/tftpLib.html) - now I realized that my tftpGet() command is returning an error 1 but I'm not sure what errorcode 1 means. On the posted website it says:
ERRNO
S_tftpLib_INVALID_DESCRIPTOR
S_tftpLib_INVALID_ARGUMENT
S_tftpLib_NOT_CONNECTED
But how do I know what 1 corresponds with?
The get portion of my code looks like this:
/* Initialize and createlocal file handle */
pFile = fopen("ngfm.bin","wb");
if (pFile != NULL)
{
/* Get file from TFTP server and write it to the file descriptor */
status = tftpGet (pTftpDesc, pFilename, pFile, TFTP_CLIENT);
printf("GOT %s\n",pFilename);
}
else
{
printf("Error in tftpGet()\nfailed to get %s from %s\nERRNO %d",pFilename,pHost, status);
}
Try this code:
int status;
if (OK == (status = tftpGet (pTftpDesc, pFilename, fd, TFTP_CLIENT))) {
printf("tftpGet() successful\n");
} else {
printf("Error has occurred: %d\n", errno); // errno is where the error is stored
}
No,The problem in fact was, that I didn';t get a valid file pointer but NULL because there's no such thing as a "current directory" like in Linux in VxWorks but I had to change my fopen to say something like pFile = fopen("flash:/ngfm.bin","wb"); instead.