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