Q2) What does the above do?
Does it say that 'fn' is a function with the same signature as the prototype and that fn is located at the address of Ptr_TargetFunction.
Why the *'s in the above?
Q1)what is the meaning of *pDataIn? is it that pDataIn is a pointer to a DataBlob then what is *pDataIn ?
A1) Yes the declaration DATA_BLOB *pDataIn is a pointer to type DATA_BLOB
The * in a declaration denotes that a pointer type is being declared.
so type *variablename means variablename is a pointer to type
Q2) PrototypeOfTargetFunction* fn = (PrototypeOfTargetFunction*)Ptr_TargetFunction;What does the above do?
Does it say that 'fn' is a function with the same signature as the prototype and that fn is located at the address of Ptr_TargetFunction.
Why the *'s in the above?
This is a declaration&initialisation all in one. We can split it into 2 parts as follows: PrototypeOfTargetFunction* fn This is declaring a pointer (named fn ) to type PrototypeOfTargetFunction.
We already defined the type PrototypeOfTargetFunction earlier.
So fn is a pointer to a function that takes (
DATA_BLOB *, LPWSTR *, DATA_BLOB *, PVOID , CRYPTPROTECT_PROMPTSTRUCT *, int dwFlags, DATA_BLOB *) and returns an BOOL
the second part is: fn = (PrototypeOfTargetFunction*)Ptr_TargetFunction
This assigns the address of the functionPtr_TargetFunction to the function pointer fn.
The cast operation (PrototypeOfTargetFunction*) just makes sure that the address of the function is of the right type to match the pointer fn.
(In this case it may be redundant).
Q3 BOOL RV = (*fn)(pDataIn,ppszDataDescr,pOptionalEntropy,pvReserved,pPromptStruct,dwFlags,pDataOut); why (*fn) in the calling statement?
This is how you call a function through a function pointer. Note you can just write it as BOOL RV = fn(pDataIn,ppszDataDescr,pOptionalEntropy,pvReserved,pPromptStruct,dwFlags,pDataOut);
Q4. why no * in the arg list? why pDataIn and not *pDataIn in the arg list?
If you passed *pDataIn (for example) you will be dereferencing the pointer - which would be in-correct.
int a,b, result, x;
a = 2;
b = 3;
result = a*b; //Multiplication;
int *p; //pointer declaration;
p = &x;
*p = 10; //pointer dereferencing (using the contents of the pointer)