views:

155

answers:

4

I am currently trying to make a call to this function call. Here's the declaration:

const void* WINAPI CertCreateContext(
  __in      DWORD dwContextType,
  __in      DWORD dwEncodingType,
  __in      const BYTE *pbEncoded,
  __in      DWORD cbEncoded,
  __in      DWORD dwFlags,
  __in_opt  PCERT_CREATE_CONTEXT_PARA pCreatePara
);

As you can see, the third input param calls for a const BYTE * which represents the encoded certificate you are trying to create. How do I define such a variable in c++?

A: 

You only need to declare a BYTE*, the compiler will automatically cast's non-consts to consts.

Joe D
+7  A: 

You don't need to. The function parameter is a pointer to a const BYTE, which means the function will not change the byte it points to. A simple example:

void f( const BYTE * p ) {
    // stuff
}

BYTE b = 42;
BYTE a[] = { 1, 2, 3 };

f( & b );
f( a );

You will of course need to #include the header that declares the type BYTE.

anon
And the downvote was because what?
anon
@Neil: Down-votes on simple answers are the most baffling.
GMan
@GMan I know, which is why they are the only ones I ask about, in the forlorn hope the downvoter might explain themselves.
anon
Agreed- the answer is perfectly valid.
DeadMG
@Neil: perhaps an old-school Microsoft zealot wanted the answer in Hungarian to match the question. Or maybe it was punishment for missing a `;`. Either way, +1 for being right.
Mike Seymour
@Mike I normally compile real code before I post it, but for questions like this rely on my code writing prowess - thanks :-)
anon
A: 

According to the documentation:

pbEncoded is a pointer to a buffer that contains the existing encoded context content to be copied.

karlphillip
+1  A: 

Pass in a regular pointer to BYTE. The const there indicates that the pointed-to object will not be modified inside the function.

bta
Thanks for catching that, Neil. I meant to say the *object being pointed to* will not be modified. The pointer itself certainly can't be modified when passed by value, `const` or otherwise. Fixed
bta