PKCS#7 How do I get X509 certificates in C++ CAPI

I am trying to extract teh X509 Certificates from a PKCS#7.

Currently I do this:

BOOL WINAPI CertDllVerifyRevocation(IN DWORD dwEncodingType, etc..

dwEncodingType = PKCS_7_ASN_ENCODING

Then check theencoding type as such:

if((dwEncodingType & PKCS_7_ASN_ENCODING) == PKCS_7_ASN_ENCODING)
// MessageBoxA(NULL,"PKCS_7_ASN_ENCODING","",MB_OK);


How do I get the X509 Certificates from the PKCS#7 which contains
certificates (if specified)?

The reason I need this is I have to check for revocation which is
performed by our own authentication server (builds paths, and performs
OCSP or CRL checks).

I need to call the SOAP interface (no problem) but it only takes X509
DER encoded Certificates :)

I would be EXTREMLEY greatful for any advice or help offered (or 2
cents) on my approach.