Rust ReportEventW returns The stub received bad data

Oliver 20 Reputation points
2024-09-12T07:45:46.25+00:00

Hello!

Im currently experimenting with the Rust windows crate.

I have a problem with the ReportEventW function, its returning the message: "The stub received bad data." and i cant figure out what ive done wrong.

Maybe there are a helpful soul here that can give me some pointers?

Thanks!

fn write_event() -> ::windows_core::Result<()> {
    let eventsource: PCWSTR = w!("Application");
    let handle: HANDLE = unsafe { RegisterEventSourceW(None, eventsource)? };
    let message = w!("Test log");
    let message2 = w!("Test log2");
    let strings = &[message, message2];
    unsafe {
        ReportEventW(
            handle,
            EVENTLOG_INFORMATION_TYPE,
            0,
            1,
            None,
            strings.len() as u32,
            Some(strings),
            None,
        )?;
    }
    unsafe { DeregisterEventSource(handle)? };
    Ok(())
}
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,592 questions
{count} votes

Accepted answer
  1. RLWA32 45,326 Reputation points
    2024-09-12T09:59:51.75+00:00

    I don't use Rust, but it appears that the posted code does not conform to the documented arguments that should be passed to the ReportEventW function. For example, the function takes nine arguments but the code passes only eight. The posted code should be passing a 16-bit value for the number of strings in the array but does not appear to be doing so. The related parameter is wNumStrings. In your example the dwDataSize parameter should be 0 but the code appears to be passing something else.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Oliver 20 Reputation points
    2024-09-12T09:28:27.2933333+00:00

    Im testing this on:

    Microsoft Windows 11

    Version 10.0.22621 Build 22621

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.