Я получаю read access violation exception
в Base
деструкторе класса, так как root_dse
выходит из области видимости после CoUninitialize();
#include <atlbase.h>
#include <ActiveDS.h>
#include <memory>
#pragma comment(lib, "activeds.lib")
#pragma comment(lib, "adsiid.lib")
using namespace std;
class Base {
protected:
CComPtr<IADs> root_dse = nullptr;
public:
Base()
{
CoInitialize(nullptr);
}
virtual ~Base()
{
CoUninitialize();
}
virtual void do_stuff() = 0;
};
class Derived : public Base {
private:
void do_stuff() override {
const auto h_result = ADsOpenObject(L"LDAP://rootDSE",
NULL,
NULL,
ADS_SECURE_AUTHENTICATION,
IID_IADs,
(void**)&root_dse);
}
};
int main() {
std::shared_ptr<Base> base = std::make_shared<Derived>();
base->do_stuff();
return 0;
}
Как я могу убедиться, что root_dse
равен release
доCoUninitialize();
чтобы избежать read access violation exception
?Примечание. Все производные классы используют root_dse
, поэтому он должен быть в классе Base
.