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. I really need help here! guru plz help

I really need help here! guru plz help

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestioncsharpvisual-studio
7 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.
  • Y Offline
    Y Offline
    YaronNir
    wrote on last edited by
    #1

    i've created a visual studio add in using the wizard. i copied a method from other project (that i found here in code project) that retrieves the *.dsw file path. here is the code:

    CString CCommands::GetWorkspacePath()
    {
    CWinApp* pApp = AfxGetApp();
    CString szWorkspace;

    POSITION posdt = pApp->GetFirstDocTemplatePosition();
    while (NULL != posdt)
    {
    	CDocTemplate\* pdt = pApp->GetNextDocTemplate(posdt);
    	if (0 == strcmp("CProjectWorkspaceDocTemplate", 
    		pdt->GetRuntimeClass()->m\_lpszClassName))
    	{
    		POSITION posdoc = pdt->GetFirstDocPosition();
    		if (NULL == posdoc) 
    			break;
    
    		CDocument\* pdoc = pdt->GetNextDoc(posdoc);
    		if (NULL == pdoc) 
    			break;
    
    		szWorkspace = pdoc->GetPathName();
    		if (0 == szWorkspace.GetLength()) 
    			break;
    	}
    }
    
    return szWorkspace;
    

    }

    problem is that this line :

    POSITION posdt = pApp->GetFirstDocTemplatePosition();

    returns NULL for the postd. when i try this code in the other project it works ok please, i already post this question before, and didn't get any reply can any1 help me? thanks in advanced Yaron Ask not what your application can do for you, Ask what you can do for your application

    S 1 Reply Last reply
    0
    • Y YaronNir

      i've created a visual studio add in using the wizard. i copied a method from other project (that i found here in code project) that retrieves the *.dsw file path. here is the code:

      CString CCommands::GetWorkspacePath()
      {
      CWinApp* pApp = AfxGetApp();
      CString szWorkspace;

      POSITION posdt = pApp->GetFirstDocTemplatePosition();
      while (NULL != posdt)
      {
      	CDocTemplate\* pdt = pApp->GetNextDocTemplate(posdt);
      	if (0 == strcmp("CProjectWorkspaceDocTemplate", 
      		pdt->GetRuntimeClass()->m\_lpszClassName))
      	{
      		POSITION posdoc = pdt->GetFirstDocPosition();
      		if (NULL == posdoc) 
      			break;
      
      		CDocument\* pdoc = pdt->GetNextDoc(posdoc);
      		if (NULL == pdoc) 
      			break;
      
      		szWorkspace = pdoc->GetPathName();
      		if (0 == szWorkspace.GetLength()) 
      			break;
      	}
      }
      
      return szWorkspace;
      

      }

      problem is that this line :

      POSITION posdt = pApp->GetFirstDocTemplatePosition();

      returns NULL for the postd. when i try this code in the other project it works ok please, i already post this question before, and didn't get any reply can any1 help me? thanks in advanced Yaron Ask not what your application can do for you, Ask what you can do for your application

      S Offline
      S Offline
      sam India
      wrote on last edited by
      #2

      you are getting Null value returned by pApp->GetFirstDocTemplatePosition() bcoz you are using the base class pointer, and the base class pointer in not aware your projects Doc Template positions. If you type cast it into your project's application class, it won't return null value; CWinApp* pApp = AfxGetApp(); CString szWorkspace; ((MyPrjApp*)pApp)->GetFirstDocTemplatePosition(); never say die

      Y 1 Reply Last reply
      0
      • S sam India

        you are getting Null value returned by pApp->GetFirstDocTemplatePosition() bcoz you are using the base class pointer, and the base class pointer in not aware your projects Doc Template positions. If you type cast it into your project's application class, it won't return null value; CWinApp* pApp = AfxGetApp(); CString szWorkspace; ((MyPrjApp*)pApp)->GetFirstDocTemplatePosition(); never say die

        Y Offline
        Y Offline
        YaronNir
        wrote on last edited by
        #3

        thanks for the response, that didn't work! here is what i wrote and i got still a null:

        CWinApp* pApp = AfxGetApp();
        CString szWorkspace;
        //POSITION posdt = pApp->GetFirstDocTemplatePosition();
        POSITION posdt = ((CBackITUp_AddinApp*)pApp)->GetFirstDocTemplatePosition();

        i even try the extern thing:

        extern CBackITUp_AddinApp theApp;
        .
        .
        POSITION posdt = theApp.GetFirstDocTemplatePosition();

        that didn't work as well!!! please please i need help (try to create a new visual studio add in project in VC6, then try the lines above, you will get the same result.....i am doing something wrong, but i can't figure out what is wrong.... thanks again Yaron Ask not what your application can do for you, Ask what you can do for your application

        S 1 Reply Last reply
        0
        • Y YaronNir

          thanks for the response, that didn't work! here is what i wrote and i got still a null:

          CWinApp* pApp = AfxGetApp();
          CString szWorkspace;
          //POSITION posdt = pApp->GetFirstDocTemplatePosition();
          POSITION posdt = ((CBackITUp_AddinApp*)pApp)->GetFirstDocTemplatePosition();

          i even try the extern thing:

          extern CBackITUp_AddinApp theApp;
          .
          .
          POSITION posdt = theApp.GetFirstDocTemplatePosition();

          that didn't work as well!!! please please i need help (try to create a new visual studio add in project in VC6, then try the lines above, you will get the same result.....i am doing something wrong, but i can't figure out what is wrong.... thanks again Yaron Ask not what your application can do for you, Ask what you can do for your application

          S Offline
          S Offline
          sam India
          wrote on last edited by
          #4

          CWinApp* pApp = AfxGetApp();CString szWorkspace;//POSITION posdt = pApp->GetFirstDocTemplatePosition();POSITION posdt = ((CBackITUp_AddinApp*)pApp)->GetFirstDocTemplatePosition(); this code runs well when i executed it in newly created project. i executed this code in CMainFrame class message handler function. i suggest you to try this code in CMainFrame Class for testing purpose only the problem could be in base class of CCommons class, you haven't mentioned anything about its base class. never say die

          Y 1 Reply Last reply
          0
          • S sam India

            CWinApp* pApp = AfxGetApp();CString szWorkspace;//POSITION posdt = pApp->GetFirstDocTemplatePosition();POSITION posdt = ((CBackITUp_AddinApp*)pApp)->GetFirstDocTemplatePosition(); this code runs well when i executed it in newly created project. i executed this code in CMainFrame class message handler function. i suggest you to try this code in CMainFrame Class for testing purpose only the problem could be in base class of CCommons class, you haven't mentioned anything about its base class. never say die

            Y Offline
            Y Offline
            YaronNir
            wrote on last edited by
            #5

            thanks for reply. As I mentioned before, I am using a visual studio add in project the objects: 1. CBackITUp_AddinApp - the application 2. CCommands - the commands object 3. CDSAddIn - the developer studio add in object 4. ICommands - the commands interface as you can see i am not using CMainFrame..... I think I know what my problem is. the method GetFirstDocTemplatePosition will work only on the dev studio exe (the application which runs the add in) and not on the add in itself.... therefor when i am using

            CWinApp* pApp = AfxGetApp()

            I am getting a pointer to the add in (dll) main application object and not the exe main application object..... now can you help? thanks again Yaron Ask not what your application can do for you, Ask what you can do for your application

            S 1 Reply Last reply
            0
            • Y YaronNir

              thanks for reply. As I mentioned before, I am using a visual studio add in project the objects: 1. CBackITUp_AddinApp - the application 2. CCommands - the commands object 3. CDSAddIn - the developer studio add in object 4. ICommands - the commands interface as you can see i am not using CMainFrame..... I think I know what my problem is. the method GetFirstDocTemplatePosition will work only on the dev studio exe (the application which runs the add in) and not on the add in itself.... therefor when i am using

              CWinApp* pApp = AfxGetApp()

              I am getting a pointer to the add in (dll) main application object and not the exe main application object..... now can you help? thanks again Yaron Ask not what your application can do for you, Ask what you can do for your application

              S Offline
              S Offline
              sam India
              wrote on last edited by
              #6

              according to me, you can solve the problem by creating a DLL project which has a fuction MyFunc() returning application object's address. Include this Dll in your addin and call MyFunc(). never say die

              Y 1 Reply Last reply
              0
              • S sam India

                according to me, you can solve the problem by creating a DLL project which has a fuction MyFunc() returning application object's address. Include this Dll in your addin and call MyFunc(). never say die

                Y Offline
                Y Offline
                YaronNir
                wrote on last edited by
                #7

                Hi, I am not sure i follow, can you show me code on how to do that? thanks Yaron Ask not what your application can do for you, Ask what you can do for your application

                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