Saving the current file in a Visual Studio Addin
-
I'm trying to save the current file i'm working on in a visual studio file from an Addin. I can not get the save command to work. How do you use the command? Examples, Suggestions? Here is the code STDMETHODIMP CCommands::FileFavoritesCommandMethod() { AFX_MANAGE_STATE(AfxGetStaticModuleState()) //Get the current file working on CString csCurrentFile; CComPtr pActiveDocument; m_pApplication->get_ActiveDocument(&pActiveDocument); if(pActiveDocument) { CComQIPtr spActDoc(pActiveDocument); if(spActDoc) { spActDoc->Save(); BSTR bstrName; spActDoc->get_FullName( &bstrName ); } } }
-
I'm trying to save the current file i'm working on in a visual studio file from an Addin. I can not get the save command to work. How do you use the command? Examples, Suggestions? Here is the code STDMETHODIMP CCommands::FileFavoritesCommandMethod() { AFX_MANAGE_STATE(AfxGetStaticModuleState()) //Get the current file working on CString csCurrentFile; CComPtr pActiveDocument; m_pApplication->get_ActiveDocument(&pActiveDocument); if(pActiveDocument) { CComQIPtr spActDoc(pActiveDocument); if(spActDoc) { spActDoc->Save(); BSTR bstrName; spActDoc->get_FullName( &bstrName ); } } }
how do you know that it is not working?
-
how do you know that it is not working?
It's not compiling. I'm not sure On what to pass in on the parameters, It wants ::Save(THIS_ VARIANT vFilename, VARIANT vBoolPrompt, DsSaveStatus FAR* pSaved) I've tried DsSaveStatus saved; Save(NULL, TRUE, &saved); return --cannot convert parameter 1 from 'const int' to 'struct tagVARIANT Pluss plenty more and they all say they cannot convert parameter 1 to struct tagVARIANT Scott
-
It's not compiling. I'm not sure On what to pass in on the parameters, It wants ::Save(THIS_ VARIANT vFilename, VARIANT vBoolPrompt, DsSaveStatus FAR* pSaved) I've tried DsSaveStatus saved; Save(NULL, TRUE, &saved); return --cannot convert parameter 1 from 'const int' to 'struct tagVARIANT Pluss plenty more and they all say they cannot convert parameter 1 to struct tagVARIANT Scott
Use the following code VARIANT vtErr; vtErr.vt = VT_ERROR; vtErr.scode = DISP_E_PARAMNOTFOUND; VARIANT vtPrompt; vtPrompt.vt = VT_BOOL; vtPrompt.boolVal = VARIANT_TRUE; spDoc->Save(vtErr, vtPrompt, &saved); This would work but life would be much cool if you use CComVariant or _variant_t.
-
Use the following code VARIANT vtErr; vtErr.vt = VT_ERROR; vtErr.scode = DISP_E_PARAMNOTFOUND; VARIANT vtPrompt; vtPrompt.vt = VT_BOOL; vtPrompt.boolVal = VARIANT_TRUE; spDoc->Save(vtErr, vtPrompt, &saved); This would work but life would be much cool if you use CComVariant or _variant_t.
-
that worked, thanks. I tried using _variant_t but it gave an error when compiling. How do you use CComVariant and _variant_t. thanks Scott
#include . . . spDoc->Save(vtMissing, _variant_t(true), &status);
-
#include . . . spDoc->Save(vtMissing, _variant_t(true), &status);
That gave me the linking errors Commands.obj : error LNK2001: unresolved external symbol "class _variant_t vtMissing" (?vtMissing@@3V_variant_t@@A) Commands.obj : error LNK2001: unresolved external symbol "void __stdcall _com_issue_error(long)" (?_com_issue_error@@YGXJ@Z)
-
That gave me the linking errors Commands.obj : error LNK2001: unresolved external symbol "class _variant_t vtMissing" (?vtMissing@@3V_variant_t@@A) Commands.obj : error LNK2001: unresolved external symbol "void __stdcall _com_issue_error(long)" (?_com_issue_error@@YGXJ@Z)
You need to have comsupp.lib linked
-
You need to have comsupp.lib linked