why do have to restart to get excel/ word application. every time
-
Hi COM Expert. I have a ms word automation, dos-based, application that support MFC. The programming is running perfectly right now. and a few minues later i got " Couldn't create MS Word Application Object". at
app.CreateDispatch("Word.Application");
But I restart the computer and the program works again. why is that? is it because of OLE did not get initialized? why i have to restart the computer in order to work fine. what is wrong with that? here are my code// PrintMSWord.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "PrintMSWord.h" #include // OLE2 Definitions #include #include "msword9.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // The one and only application object CWinApp theApp; using namespace std; int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; // initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs cerr << _T("Fatal Error: MFC initialization failed") << endl; nRetCode = 1; } else { // TODO: code your application's behavior here. // getting the file name CString fileName; for (int i = 1; i < argc; i++) { fileName += argv[i]; fileName += " "; } //fileName = "e:\\apqad.doc"; cout<<"Opening "<<(const char*)fileName<<" ..."<
-
Hi COM Expert. I have a ms word automation, dos-based, application that support MFC. The programming is running perfectly right now. and a few minues later i got " Couldn't create MS Word Application Object". at
app.CreateDispatch("Word.Application");
But I restart the computer and the program works again. why is that? is it because of OLE did not get initialized? why i have to restart the computer in order to work fine. what is wrong with that? here are my code// PrintMSWord.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "PrintMSWord.h" #include // OLE2 Definitions #include #include "msword9.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // The one and only application object CWinApp theApp; using namespace std; int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; // initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs cerr << _T("Fatal Error: MFC initialization failed") << endl; nRetCode = 1; } else { // TODO: code your application's behavior here. // getting the file name CString fileName; for (int i = 1; i < argc; i++) { fileName += argv[i]; fileName += " "; } //fileName = "e:\\apqad.doc"; cout<<"Opening "<<(const char*)fileName<<" ..."<
I don't know MFC very well, but in VB you have to set all your office objects to nothing when you are done with them. Otherwise, the reference stays alive despite app.quit. Try to find a way to nullify or destroy all your reference objects rather than just letting them go out of scope. I see that you call CoUninitialize() and ReleaseDispatch(), but like I said I don't know enough about MFC to know how these work. Maybe try testing your objects before you return to see if they are fully destroyed. Hope I helped.
-
I don't know MFC very well, but in VB you have to set all your office objects to nothing when you are done with them. Otherwise, the reference stays alive despite app.quit. Try to find a way to nullify or destroy all your reference objects rather than just letting them go out of scope. I see that you call CoUninitialize() and ReleaseDispatch(), but like I said I don't know enough about MFC to know how these work. Maybe try testing your objects before you return to see if they are fully destroyed. Hope I helped.
what do you mean by saying
Try to find a way to nullify or destroy all your reference objects rather than just letting them go out of scope
I'm using network though. this program has been 4 days.. it works fine now and later it is not.. i have no clue at all coz this is my very first COM or Automation application. I tried so hard to understand what is really going on within my application that sometimes works and mostly not. I couldn't find any book that's talk about why i can't get my word.application. I though it is because I couldn't initialize OLE libs. Anybody Anyone can tell me what is wrong with my code? what is causing my application not to app.createdispatch("Word.Applicaiton"); -
what do you mean by saying
Try to find a way to nullify or destroy all your reference objects rather than just letting them go out of scope
I'm using network though. this program has been 4 days.. it works fine now and later it is not.. i have no clue at all coz this is my very first COM or Automation application. I tried so hard to understand what is really going on within my application that sometimes works and mostly not. I couldn't find any book that's talk about why i can't get my word.application. I though it is because I couldn't initialize OLE libs. Anybody Anyone can tell me what is wrong with my code? what is causing my application not to app.createdispatch("Word.Applicaiton");If it works at first and then suddenly stops working, then unreleased references are likely the cause. Try to set your Word.Application object to null or something of that sort. I wish I could help more, but I don't know MFC well enough. Hopefully someone on CP can be more useful.
-
If it works at first and then suddenly stops working, then unreleased references are likely the cause. Try to set your Word.Application object to null or something of that sort. I wish I could help more, but I don't know MFC well enough. Hopefully someone on CP can be more useful.
Thanks for your explaination. You are helping me and I don't know VB either but I think as long as the classes or functions is win32 API, both VB and C++ programmers can use in the same way, ofcourse the syntax will be different. Anyway..Let's talk about my problem. Let me tell you one thing I just found out. As I told you, I'm using Network. I have C:\,J:\,I:\,H:\,G:\...etc. C:\ and G:\ drives is only I can access. It is private. but J:\, I:\ and H:\ are public. All the users can access to those drives. J:\ is a common one. All the users are on J:\ all the time. My program give me a message "Couldn't create MS Word Application Object ",
_Application app if(!app.CreateDispatch("Word.Application")) { AfxMessageBox("Couldn't create MS Word Application Object "); return 1; }
but not from other running from C:\ and G:\. So can you give me any suggestion what do I need to change or do inorder to let my program run correctly on J:\?oh.. it is only works on my machine.. i mean even I copy my program and paste other users' c:\(machines). still it doesn't work.. the same message is giving me... -
Thanks for your explaination. You are helping me and I don't know VB either but I think as long as the classes or functions is win32 API, both VB and C++ programmers can use in the same way, ofcourse the syntax will be different. Anyway..Let's talk about my problem. Let me tell you one thing I just found out. As I told you, I'm using Network. I have C:\,J:\,I:\,H:\,G:\...etc. C:\ and G:\ drives is only I can access. It is private. but J:\, I:\ and H:\ are public. All the users can access to those drives. J:\ is a common one. All the users are on J:\ all the time. My program give me a message "Couldn't create MS Word Application Object ",
_Application app if(!app.CreateDispatch("Word.Application")) { AfxMessageBox("Couldn't create MS Word Application Object "); return 1; }
but not from other running from C:\ and G:\. So can you give me any suggestion what do I need to change or do inorder to let my program run correctly on J:\?oh.. it is only works on my machine.. i mean even I copy my program and paste other users' c:\(machines). still it doesn't work.. the same message is giving me...Make sure the other user's machine has Word 2000 or XP. If not, then it is a compatability issue. If you're using .NET then it could be something with the security permisions. Set everything to full trust and see if that works. Other than that, I don't know what could be causing it. Sorry.
-
Make sure the other user's machine has Word 2000 or XP. If not, then it is a compatability issue. If you're using .NET then it could be something with the security permisions. Set everything to full trust and see if that works. Other than that, I don't know what could be causing it. Sorry.
-
Hi COM Expert. I have a ms word automation, dos-based, application that support MFC. The programming is running perfectly right now. and a few minues later i got " Couldn't create MS Word Application Object". at
app.CreateDispatch("Word.Application");
But I restart the computer and the program works again. why is that? is it because of OLE did not get initialized? why i have to restart the computer in order to work fine. what is wrong with that? here are my code// PrintMSWord.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "PrintMSWord.h" #include // OLE2 Definitions #include #include "msword9.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // The one and only application object CWinApp theApp; using namespace std; int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; // initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs cerr << _T("Fatal Error: MFC initialization failed") << endl; nRetCode = 1; } else { // TODO: code your application's behavior here. // getting the file name CString fileName; for (int i = 1; i < argc; i++) { fileName += argv[i]; fileName += " "; } //fileName = "e:\\apqad.doc"; cout<<"Opening "<<(const char*)fileName<<" ..."<