Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3026

CComPtr System.AccessViolationException

$
0
0
Hi all,


I have a C++/CLI console application and I should pass a CComPtr<T> to a class but when I try to access it, occours a System.AccessViolationException.


Following the main code:

Code:

CComPtr<IAuga> auga;

CLSID clsAuga;
HRESULT hr = CLSIDFromProgID(L"Heimdall.Auga.1", &clsAuga);
if (hr > -1)
{
        hr = CoCreateInstance(clsAuga, NULL, CLSCTX_INPROC_SERVER, __uuidof (IAuga), (void**)&auga);
        if (hr > -1)
        {
                printf("Auga COM component created successfully!\n");
        }
        else
        {
                //error
        }
}

CameraHook^ cam = gcnew CameraHook((CComPtr<IAuga>*&)auga);

cam->StartCamera();

And following the CameraHook.h and CameraHook.cpp:

Code:

ref class CameraHook
{
private:
        CComPtr<IAuga> *auga;
public:
        CameraHook(CComPtr<IAuga> *ag);
        void StartCamera();
};

Code:

CameraHook::CameraHook(CComPtr<IAuga> *ag)
{
        auga = ag;
}
void CameraHook::StartCamera()
{
        HRESULT hr = auga->p->SetCameraIDispatch(........);
}


When the console reachs auga->p->SetCameraIDispatch(), it breaks.


What's the problem?

Thanks a lot!

Marco

Viewing all articles
Browse latest Browse all 3026

Trending Articles