Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Saving the current file in a Visual Studio Addin

Saving the current file in a Visual Studio Addin

Scheduled Pinned Locked Moved C / C++ / MFC
csharpvisual-studioquestion
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gilfrog
    wrote on last edited by
    #1

    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 ); } } }

    R 1 Reply Last reply
    0
    • G Gilfrog

      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 ); } } }

      R Offline
      R Offline
      Rama Krishna Vavilala
      wrote on last edited by
      #2

      how do you know that it is not working?

      G 1 Reply Last reply
      0
      • R Rama Krishna Vavilala

        how do you know that it is not working?

        G Offline
        G Offline
        Gilfrog
        wrote on last edited by
        #3

        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

        R 1 Reply Last reply
        0
        • G Gilfrog

          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

          R Offline
          R Offline
          Rama Krishna Vavilala
          wrote on last edited by
          #4

          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.

          G 1 Reply Last reply
          0
          • R Rama Krishna Vavilala

            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.

            G Offline
            G Offline
            Gilfrog
            wrote on last edited by
            #5

            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

            R 1 Reply Last reply
            0
            • G Gilfrog

              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

              R Offline
              R Offline
              Rama Krishna Vavilala
              wrote on last edited by
              #6

              #include . . . spDoc->Save(vtMissing, _variant_t(true), &status);

              G 1 Reply Last reply
              0
              • R Rama Krishna Vavilala

                #include . . . spDoc->Save(vtMissing, _variant_t(true), &status);

                G Offline
                G Offline
                Gilfrog
                wrote on last edited by
                #7

                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)

                R 1 Reply Last reply
                0
                • G Gilfrog

                  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)

                  R Offline
                  R Offline
                  Rama Krishna Vavilala
                  wrote on last edited by
                  #8

                  You need to have comsupp.lib linked

                  G 1 Reply Last reply
                  0
                  • R Rama Krishna Vavilala

                    You need to have comsupp.lib linked

                    G Offline
                    G Offline
                    Gilfrog
                    wrote on last edited by
                    #9

                    works great, thanks!

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups