Tech Support > Microsoft Windows > Drivers > Question about structure of "USBCAMD_DEVICE_EXTENSION"
Question about structure of "USBCAMD_DEVICE_EXTENSION"
Posted by SL Chang on September 30th, 2005


When I try to add new field for RemoveLock, I notice that there is one
special field "CameraDeviceContext".

PUCHAR CameraDeviceContext[0];

So I search keyword "CameraDeviceContext" than I only found one :

#define USBCAMD_GET_DEVICE_CONTEXT(de)
((PVOID)(&(de)->CameraDeviceContext[0]))

Now, my question is :
1. Why declare a zero size array here, array[num] mean index 0~(num-1) array
, right ?

2. I don't see any initialize about CameraDeviceContext, how can I sure
CameraDeviceContext[0] point to DEVICE_CONTEXT ?
Does it possible point to invalid memory space ?

3. When I add field "IO_REMOVE_LOCK RemoveLock;" after CameraDeviceContext
will make error.
But if I put new field before CameraDeviceContext, there is no error. Is
it reasonable?

Any advice would be appreciated,

Thanks!


Posted by SL Chang on September 30th, 2005


Sorry, I forget say that.
USBCAMD_DEVICE_EXTENSION is a structure inside "USBCAMD" in DDK sample.


Posted by Doron Holan [MS] on September 30th, 2005


I think it is

UCHAR CameraDeviceContext[0];

what you declared is an array of PUCHARs. Give the macro below, what i have
makes sense. This is something that you can do in C where you have an open
ended array at the end of the structure. this allows you to allocate a
dymamically sized array (or in this case, the structure + your context) in
one allocation. this is how it works

typedef struct _CONTEXT {
ULONG Foo;
UCHAR More[0];
} CONTEXT, *PCONTEXT;

typedef struct _EXTRA {
ULONG Data[50];
} EXTRA,*PEXTRA
;
PCONTEXT pContext = (PCONTEXT) ExAllocatePoolWithTag(NonPagedPool,
sizeof(CONTEXT) + sizeof(EXTRA), ' gat');

if (pContext != NULL) {
PEXTRA pExtra = (PEXTRA) (&pContext->More[0]);
}

d

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


"SL Chang" <slchang@sq.com.tw> wrote in message
news:u$UnhfYxFHA.2924@TK2MSFTNGP15.phx.gbl...


Posted by SL Chang on September 30th, 2005


I got it !
Thank you very much


Posted by Doron Holan [MS] on September 30th, 2005


and because of the way this works, this open ended array needs to be the
*last* parameter in the structure, otherwise the array will overwrite the
fields that follow it.

d

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


"SL Chang" <slchang@sq.com.tw> wrote in message
news:OdxWahZxFHA.3892@TK2MSFTNGP12.phx.gbl...



Similar Posts