|
Prev: MultibyteToWideChar not working properly?
Next: My Application detected as Virus by some Anti virus software
From: mtuzhilov on 24 Apr 2008 15:38 I get a Type Mismatch error when trying to open word file by using automation. I am using msword.h header from Office 2007 and compiling with VC++ 6.0. CoInitialize(0); _Application oWord ; Documents oDocs; _Document oDoc; COleVariant vOpt(DISP_E_PARAMNOTFOUND, VT_ERROR); //For optional args //Start Word if(!(oWord.CreateDispatch("Word.Application", NULL))) { AfxMessageBox("Error starting Word.", MB_SETFOREGROUND); return 0; } //Open a document oDocs = oWord.GetDocuments(); //error happens on this line oDoc = oDocs.Open(COleVariant("C:\\PROJECTS\\RRD_OFFICE2007\ \test.rtf"), vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt); Does any one have an idea? Thanks
From: Joseph M. Newcomer on 24 Apr 2008 16:51 I would suggest showing the actual type mismatch error, and possibly the prototype of the Open method; it would help a lot. Also the prototype for COleVariant; are you sure there is a version that takes an LPCSTR (as opposed to an LPCTSTR, or possibly an LPWSTR or a BSTR) joe On Thu, 24 Apr 2008 12:38:55 -0700 (PDT), mtuzhilov(a)gmail.com wrote: >I get a Type Mismatch error when trying to open word file by using >automation. I am using msword.h header from Office 2007 and compiling >with VC++ 6.0. > > >CoInitialize(0); > >_Application oWord ; >Documents oDocs; >_Document oDoc; >COleVariant vOpt(DISP_E_PARAMNOTFOUND, VT_ERROR); //For optional args > >//Start Word >if(!(oWord.CreateDispatch("Word.Application", NULL))) > >{ > AfxMessageBox("Error starting Word.", MB_SETFOREGROUND); > return 0; >} > > >//Open a document >oDocs = oWord.GetDocuments(); > >//error happens on this line >oDoc = oDocs.Open(COleVariant("C:\\PROJECTS\\RRD_OFFICE2007\ >\test.rtf"), vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, >vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt); > >Does any one have an idea? > >Thanks Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
From: mtuzhilov on 24 Apr 2008 17:54 On Apr 24, 3:51 pm, Joseph M. Newcomer <newco...(a)flounder.com> wrote: > I would suggest showing the actual type mismatch error, and possibly the prototype of the > Open method; it would help a lot. Also the prototype for COleVariant; are you sure there > is a version that takes an LPCSTR (as opposed to an LPCTSTR, or possibly an LPWSTR or a > BSTR) > joe > > > > > > On Thu, 24 Apr 2008 12:38:55 -0700 (PDT), mtuzhi...(a)gmail.com wrote: > >I get a Type Mismatch error when trying to open word file by using > >automation. I am using msword.h header from Office 2007 and compiling > >with VC++ 6.0. > > >CoInitialize(0); > > >_Application oWord ; > >Documents oDocs; > >_Document oDoc; > >COleVariant vOpt(DISP_E_PARAMNOTFOUND, VT_ERROR); //For optional args > > >//Start Word > >if(!(oWord.CreateDispatch("Word.Application", NULL))) > > >{ > > AfxMessageBox("Error starting Word.", MB_SETFOREGROUND); > > return 0; > >} > > >//Open a document > >oDocs = oWord.GetDocuments(); > > >//error happens on this line > >oDoc = oDocs.Open(COleVariant("C:\\PROJECTS\\RRD_OFFICE2007\ > >\test.rtf"), vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, > >vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt); > > >Does any one have an idea? > > >Thanks > > Joseph M. Newcomer [MVP] > email: newco...(a)flounder.com > Web:http://www.flounder.com > MVP Tips:http://www.flounder.com/mvp_tips.htm- Hide quoted text - > > - Show quoted text - This error is called. Run-time error '13': Type Mismatch. Here is a link to msword.h, it contains the open method that i am using: http://www.koders.com/cpp/fid370AD5EFB3C6A2E188159CCF3AD6900AB213B121.aspx. I think the call is correct, i followed number of guides on the word automation with mfc. Here is one of them on word autimation: http://support.microsoft.com/kb/252719. It works correctly when running from the stand along win32 consol application but starts complaining about "Type mismatch" when running in the DLL called by the windows service. Thanks for any help on this.
From: Joseph M. Newcomer on 24 Apr 2008 23:11 Well, you REALLY need to be explicit about what the error is. You used a completely vague description, which in no way suggested it was a *runtime* error. Please, in the future, report the exact text of any error and the conditions during which it occurs. On Thu, 24 Apr 2008 14:54:35 -0700 (PDT), mtuzhilov(a)gmail.com wrote: >On Apr 24, 3:51�pm, Joseph M. Newcomer <newco...(a)flounder.com> wrote: >> I would suggest showing the actual type mismatch error, and possibly the prototype of the >> Open method; it would help a lot. �Also the prototype for COleVariant; are you sure there >> is a version that takes an LPCSTR (as opposed to an LPCTSTR, or possibly an LPWSTR or a >> BSTR) >> � � � � � � � � � � � � � � � � � � � � joe >> >> >> >> >> >> On Thu, 24 Apr 2008 12:38:55 -0700 (PDT), mtuzhi...(a)gmail.com wrote: >> >I get a Type Mismatch error when trying to open word file by using >> >automation. I am using msword.h header from Office 2007 and compiling >> >with VC++ 6.0. >> >> >CoInitialize(0); >> >> >_Application oWord ; >> >Documents oDocs; >> >_Document oDoc; >> >COleVariant vOpt(DISP_E_PARAMNOTFOUND, VT_ERROR); �//For optional args >> >> >//Start Word >> >if(!(oWord.CreateDispatch("Word.Application", NULL))) >> >> >{ >> > �AfxMessageBox("Error starting Word.", MB_SETFOREGROUND); >> > �return 0; >> >} >> >> >//Open a document >> >oDocs = oWord.GetDocuments(); >> >> >//error happens on this line >> >oDoc = oDocs.Open(COleVariant("C:\\PROJECTS\\RRD_OFFICE2007\ >> >\test.rtf"), vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, >> >vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt); >> >> >Does any one have an idea? >> >> >Thanks >> >> Joseph M. Newcomer [MVP] >> email: newco...(a)flounder.com >> Web:http://www.flounder.com >> MVP Tips:http://www.flounder.com/mvp_tips.htm- Hide quoted text - >> >> - Show quoted text - > >This error is called. Run-time error '13': Type Mismatch. Here is a >link to msword.h, it contains the open method that i am using: >http://www.koders.com/cpp/fid370AD5EFB3C6A2E188159CCF3AD6900AB213B121.aspx. **** This Web site appears to be moderately useless; it is nearly 10K lines of declarations, which are said to be the automatically-generated wrapper file, so it is not clear what the purpose is in posting it. **** >I think the call is correct, i followed number of guides on the word >automation with mfc. Here is one of them on word autimation: >http://support.microsoft.com/kb/252719. > >It works correctly when running from the stand along win32 consol >application but starts complaining about "Type mismatch" when running >in the DLL called by the windows service. **** Note that a Windows service can rarely call any program that has a GUI interaction, so it would not at all surprise me that a service trying to access Word fails. You may be doing something that is impossible. But the fact that you are running in a service (another previously-unstated but absolutely critical piece of information) is probably the reason. In fact, I would be extremely surprised if it *did* work. Unfortunately, I have no way of diagnosing the problem, but I'd strong suspect that you cannot call Word from a service at all. joe **** > >Thanks for any help on this. Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
From: mxk on 26 Apr 2008 08:38
On 4ÔÂ25ÈÕ, ÉÏÎç3ʱ38·Ö, mtuzhi...(a)gmail.com wrote: > I get a Type Mismatch error when trying to openwordfile by using > automation. I am using msword.h header from Office 2007 and compiling > with VC++ 6.0. > > CoInitialize(0); > > _Application oWord ; > Documents oDocs; > _Document oDoc; > COleVariant vOpt(DISP_E_PARAMNOTFOUND, VT_ERROR); //For optional args > > //StartWord > if(!(oWord.CreateDispatch("Word.Application", NULL))) > > { > AfxMessageBox("Error startingWord.", MB_SETFOREGROUND); > return 0; > > } > > //Open a document > oDocs = oWord.GetDocuments(); > > //error happens on this line > oDoc = oDocs.Open(COleVariant("C:\\PROJECTS\\RRD_OFFICE2007\ > \test.rtf"), vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, > vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt); > > Does any one have an idea? > > Thanks Hi, There is a tool called Advanced Word Repair. I have used it to repair many corrupt Word documents on my damaged disks successfully. Its homepage is http://www.datanumen.com/awr/ Alan |