views:

81

answers:

2
VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)pmtConfig->pbFormat;;
...
WriteFile( hHandle, pVih, sizeof(VIDEOINFOHEADER), NULL, NULL );

Through debugging I found WriteFile reports exception, how to solve it?

+2  A: 

Is pVih initialized? If not, that's your problem.

follow up

Since pVih is initialized, I looked at the documentation. The fourth parameter, lpNumberOfBytesWritten, cannot be NULL if the fifth parameter, lpOverlapped, is NULL. Provide a pointer to a variable to accept the number of bytes written.

second follow up

Is pmtConfig->pbFormat properly pointing to a VIDEOINFOHEADER?

wallyk
Yes, it's initialized.
Passing NULL as lpNumberOfBytesWritten results in a failure with ERROR_INVALID_PARAMETER, not exception.
atzz
@user: Is it *correctly* initialized? The initialization in the question contains a cast, so are you sure the pointer you cast really does point to a `VIDEOINFOHEADER`?
sth
It turns out to be `cannot be NULL if the fifth parameter, lpOverlapped, is NULL`,but why?
@user198729: The short answer is that is because the function is specified so. While Microsoft's APIs are often inexplicably gnarly, the reason is probably because it is envisioned that a non-asynchronous call (that is, the code will wait for the write to complete before continuing) would always want to know how many bytes transferred. It seems sensible to me that there could be occasions where no one cares, but that's different from the point of view of the designer of `WriteFile`.
wallyk
+2  A: 

Probably, pmtConfig->pbFormat is NULL or invalid. Give us more details on exception, please.

atzz