I am trying to learn how to make VStudio addins and am a little new to the COM objects, I'd like to know if I'm doing this at all right, I had to modify the code created by the wizard by adding the typecast (LPVOID*) and (IDispatch**) which I just added by a guess. I created a project using the addin wizard with minimum features to simplify the code. Just to start off if I want to make the cursor backspace 2 spaces. This is the code I've got(in Commands.cpp), followed by the error I get when I build.
PHP Code:
STDMETHODIMP CCommands::TestCommandMethod()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: Replace this with the actual code to execute this command
// Use m_pApplication to access the Developer Studio Application object,
// and VERIFY_OK to see error strings in DEBUG builds of your add-in
// (see stdafx.h)
IGenericDocument* pDoc;
m_pApplication->get_ActiveDocument((IDispatch**)&pDoc);
BSTR bstrType;
pDoc->get_Type(&bstrType);
if (!wcscmp(bstrType, L"Text"))
{
// It is a text document,
// ..so QI for the right interface
ITextSelection* pTextDoc;
pDoc->QueryInterface(IID_ITextSelection, (LPVOID*)&pTextDoc);
pTextDoc->Backspace(2);
// Now, we can use text-specific
// members of pTextDoc
pTextDoc->Release();
}
SysFreeString(bstrType);
pDoc->Release();
return S_OK;
}
The error:
--------------------Configuration: test - Win32 Debug--------------------
Compiling...
Commands.cpp
C:\test\Commands.cpp(62) : error C2664: 'Backspace' : cannot convert parameter 1 from 'const int' to 'struct tagVARIANT'
No constructor could take the source type, or constructor overload resolution was ambiguous
Error executing cl.exe.
test.dll - 1 error(s), 0 warning(s)
This is the object model thing for the backspace method.
I don't understand what STDMETHOD, THIS_ VARIANT, or the PURE things do. I'm confused and really would like to learn how to use this stuff.
STDMETHOD(Backspace)(THIS_ VARIANT Count) PURE;