1

I'm trying to compile a simple C++ program that uses some functions and datastructures from the Win32 API and Wincrypt:

#include <memory>
using std::unique_ptr;

#include <Windows.h>
#include <Wincrypt.h>

using CERTSTORE_ptr = unique_ptr<CERTSTORE, decltype(&:: CertCloseStore)>;

int main(int argc, char* argv[])
{
    return 0;
}

When I attempt to compile it, I get errors at the using CERTSTORE_ptr ... line. The errors:

test.cpp(18): error C2873: 'CERTSTORE_ptr' : symbol cannot be used in a using-declaration
test\certstoreexporttest.cpp(18): error C2513: 'int' : no variable declared before '='
test\certstoreexporttest.cpp(18): error C2065: 'CERTSTORE' : undeclared identifier
...

The problem appears to be with CERTSTORE and HCERTSTORE, which is typedef'd as:

typedef void *HCERTSTORE;

How do I declare the using statement so I can enjoy the automatic cleanup? (I'm trying to avoid the __try\__finally).

Or is this simply the wrong approach and should be abandoned? (I'm ready to go back to __try\__finally so I can finish up this test program).

jww
  • 97,681
  • 90
  • 411
  • 885
  • `'CERTSTORE' : undeclared identifier` Start with that... – deviantfan Jun 18 '14 at 07:40
  • Type aliases are only supported in VS2013. I don't think `CERTSTORE` is a type (as opposed to `HCERTSTORE`), and I'm not sure if it's possible to beat `unique_ptr` into submission for your purpose. It should be quite easy to write your own RAII wrapper, though. – T.C. Jun 18 '14 at 07:42
  • 1
    I can't test it right now, but why don't you just use a typedef? – MikeMB Jun 18 '14 at 07:42
  • Thanks everyone. I abandoned the strategy. I went back to `__try/__finally` since it was a test program. It just was not a good fit. – jww Jun 18 '14 at 10:13

0 Answers0