trying to call Find and get error:c0000005 (Attempted to read or write protected memory. This is often an indication that other memory is corrupt.)
has all the usual COM stuff and register's fine just cant get the find call to work.
pretty new to c++ and COM but im thinking its not seeing the Find function, not coded right? looking for some pointers.
Test.exe
public partial class Form1 : Form
{
private CRock foo = null;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.foo = (CRock)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("DA798219-043F-4B3A-B0E2-78232DA3FF4F")));
int num = foo.Find();
if(num == 1)
{
}
}
[ComImport, CoClass(typeof(object)), TypeIdentifier, CompilerGenerated, Guid("0D77311E-D13A-485A-8206-F99422E34E82")]
public interface CRock : IRock
{
}
[ComImport, TypeIdentifier, CompilerGenerated, Guid("0D77311E-D13A-485A-8206-F99422E34E82")]
public interface IRock
{
int Find();
}
}
test.dll COM
IRock.h
typedef [uuid("0D77311E-D13A-485A-8206-F99422E34E82")]
struct IRock : public IUnknown
{
STDMETHOD_(ULONG, AddRef)() PURE;
STDMETHOD_(ULONG, Release)() PURE;
STDMETHOD(QueryInterface)(REFIID riid, void** ppv) PURE;
STDMETHOD_(INT32, Find)() PURE;
};
CRock.h
#include "IRock.h"
class CRock : public IRock
{
public:
CRock();
virtual ~CRock();
STDMETHOD_(ULONG, AddRef)();
STDMETHOD_(ULONG, Release)();
STDMETHOD(QueryInterface)(REFIID riid, void** ppv);
STDMETHOD_(INT32, Find)();
protected:
ULONG m_uRefCount;
};
CRock.cpp
#include "stdafx.h"
#include "CRock.h"
#include "uuid.h" // for __uuidof info
CRock::CRock()
{
m_uRefCount = 0;
g_uDllLockCount++;
}
CRock::~CRock()
{
g_uDllLockCount--;
}
STDMETHODIMP_(ULONG) CRock::AddRef()
{
return ++m_uRefCount; }
STDMETHODIMP_(ULONG) CRock::Release()
{
ULONG uRet = --m_uRefCount;
if (0 == m_uRefCount) delete this;
return uRet;
}
STDMETHODIMP CRock::QueryInterface(REFIID riid, void** ppv)
{
HRESULT hrRet = S_OK;
if (IsBadWritePtr(ppv, sizeof(void*)))
return E_POINTER;
*ppv = NULL;
if (InlineIsEqualGUID(riid, IID_IUnknown))
{
*ppv = (IUnknown*) this;
}
else if (InlineIsEqualGUID(riid, __uuidof(IRock)))
{
*ppv = (IRock*) this;
}
else
{
hrRet = E_NOINTERFACE;
}
if (S_OK == hrRet)
{
((IUnknown*)*ppv)->AddRef();
}
return hrRet;
}
STDMETHODIMP_(INT32) CRock::Find()
{
return 1;
}
What I have tried:
changed layout several times of STDMETHOD_(INT32, Find)() PURE; just not sure where to go from here