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. COM
  4. why do have to restart to get excel/ word application. every time

why do have to restart to get excel/ word application. every time

Scheduled Pinned Locked Moved COM
c++comquestiontestingtools
8 Posts 3 Posters 1 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.
  • P Offline
    P Offline
    pnpfriend
    wrote on last edited by
    #1

    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<<" ..."<

    S S 2 Replies Last reply
    0
    • P pnpfriend

      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<<" ..."<

      S Offline
      S Offline
      SHaroz
      wrote on last edited by
      #2

      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.

      P 1 Reply Last reply
      0
      • S SHaroz

        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.

        P Offline
        P Offline
        pnpfriend
        wrote on last edited by
        #3

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

        S 1 Reply Last reply
        0
        • P pnpfriend

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

          S Offline
          S Offline
          SHaroz
          wrote on last edited by
          #4

          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.

          P 1 Reply Last reply
          0
          • S SHaroz

            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.

            P Offline
            P Offline
            pnpfriend
            wrote on last edited by
            #5

            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...

            S 1 Reply Last reply
            0
            • P pnpfriend

              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...

              S Offline
              S Offline
              SHaroz
              wrote on last edited by
              #6

              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.

              P 1 Reply Last reply
              0
              • S SHaroz

                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.

                P Offline
                P Offline
                pnpfriend
                wrote on last edited by
                #7

                yeah.. they all have office 2000. even on my machine, the program doesn't work everytime i restart the computer.. only sometimes. that's ok if you don't know , you do the best you can to help me. and I really appreciate it. Thank you Sharoz.

                1 Reply Last reply
                0
                • P pnpfriend

                  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<<" ..."<

                  S Offline
                  S Offline
                  soptest
                  wrote on last edited by
                  #8

                  What is the error (HRESULT value)? soptest

                  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