Results 1 to 9 of 9

Thread: Please Please help with this API : CertFindCertificateInStore

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2021
    Posts
    1

    Please Please help with this API : CertFindCertificateInStore

    @dimsumZ, @Merrion,
    long time passed since this post was first posted (20 years actually...)

    Due to technical contraints, I am forced to use Excel and VBA.
    Trying to run the code you did, but when calling "i = CertFindCertificateInStoreByLong..." Excel simply crashes.

    this is my call:
    Dim i As LongPtr
    Dim j As CERT_CONTEXT

    ' https://referencesource.microsoft.co...18d2a75444cd00
    ' internal const uint PKCS_7_ASN_ENCODING = 0x00010000;

    Dim X509_ASN_ENCODING As LongPtr
    Dim CERT_FIND_ANY As LongPtr

    ' internal const uint X509_ASN_ENCODING = 0x00000001;
    X509_ASN_ENCODING = 1

    'internal const uint CERT_COMPARE_SHIFT = 16;
    'internal const uint CERT_COMPARE_ANY = 0;
    'internal const uint CERT_FIND_ANY = ((int)CERT_COMPARE_ANY << (int)CERT_COMPARE_SHIFT);
    CERT_FIND_ANY = 0

    i = CertFindCertificateInStoreByLong( _
    CLngPtr(system_Store_Handler), _
    X509_ASN_ENCODING, _
    0, _
    CERT_FIND_ANY, _
    vbNull, _
    vbNull) '<--This must be null the first time...


    If you guys have running code, I would love to see the full example.

    Thanks and god bless you...

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Please Please help with this API : CertFindCertificateInStore

    There is little to no chance that the people who started that other thread would ever see your request, so I made your post a new thread in case any current user has some familiarity with the problem.
    My usual boring signature: Nothing

  3. #3
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Please Please help with this API : CertFindCertificateInStore

    The first two parameters look wrong.
    You're passing LongPtr, but I'd guess they have to be Long's
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  4. #4
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Please Please help with this API : CertFindCertificateInStore

    I'm wondering if instead of a Long they should Integer or IntPtr. If the original code was VB6, then a Long would be 32-bits, which would be an Integer in .Net.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  5. #5
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Please Please help with this API : CertFindCertificateInStore

    Passel,
    the first two params are DWORD in the C-Header
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  6. #6
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Please Please help with this API : CertFindCertificateInStore

    Which confirms with what I said, i.e. WORD = 16-bits, DWORD = 32 bits, QWORD would be 64-bits.

    A Long in .Net is a QWORD, an Integer would be a DWORD.

    That is a true for Windows and DOS, but doesn't necessarily hold true for other Operating systems.
    Last edited by passel; Sep 2nd, 2021 at 12:41 PM.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  7. #7
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Please Please help with this API : CertFindCertificateInStore

    He‘s forced to use Excel/VBA
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  8. #8
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Please Please help with this API : CertFindCertificateInStore

    True, but these days, with the latest Excel/VBA, isn't the VBA 64-bits rather than 32-bits. I don't know, it is just something I thought that the latest versions of Office supported, i.e. 64-bit Excel etc...

    I guess I probably don't know what I'm talking about, so should bow out, especially since we haven't heard back from the OP whether LongPtr to Long fixed the problem.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  9. #9
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Please Please help with this API : CertFindCertificateInStore

    Passel,
    Yes, VBA is dependent on the bitness of the Office-Package (Not Windows!), but even in 64-Bit Office a Long is still a signed 32-Bit Integer
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width