Click here to Skip to main content
15,915,319 members
Home / Discussions / COM
   

COM

 
GeneralRe: thumbnail using IExtractImage Pin
loket21-Jul-02 7:41
loket21-Jul-02 7:41 
QuestionAnyone with experience in out-of-proc COM servers? Pin
jfugate18-Jul-02 9:31
jfugate18-Jul-02 9:31 
AnswerRe: Anyone with experience in out-of-proc COM servers? Pin
soptest18-Jul-02 9:48
soptest18-Jul-02 9:48 
GeneralRe: Anyone with experience in out-of-proc COM servers? Pin
jfugate18-Jul-02 10:04
jfugate18-Jul-02 10:04 
GeneralRe: Anyone with experience in out-of-proc COM servers? Pin
soptest18-Jul-02 13:17
soptest18-Jul-02 13:17 
AnswerRe: Anyone with experience in out-of-proc COM servers? Pin
Vi222-Jul-02 4:14
Vi222-Jul-02 4:14 
GeneralRe: Anyone with experience in out-of-proc COM servers? Pin
jfugate22-Jul-02 6:30
jfugate22-Jul-02 6:30 
Generalwhy do have to restart to get excel/ word application. every time Pin
pnpfriend18-Jul-02 5:29
pnpfriend18-Jul-02 5:29 
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
<br />
app.CreateDispatch("Word.Application");<br />

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
<br />
// PrintMSWord.cpp : Defines the entry point for the console application.<br />
//<br />
<br />
#include "stdafx.h"<br />
#include "PrintMSWord.h"<br />
#include <ole2.h> // OLE2 Definitions<br />
#include <stdio.h><br />
#include "msword9.h"<br />
<br />
#ifdef _DEBUG<br />
#define new DEBUG_NEW<br />
#undef THIS_FILE<br />
static char THIS_FILE[] = __FILE__;<br />
#endif<br />
<br />
/////////////////////////////////////////////////////////////////////////////<br />
// The one and only application object<br />
<br />
CWinApp theApp;<br />
<br />
using namespace std;<br />
<br />
<br />
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])<br />
{<br />
	int nRetCode = 0;<br />
<br />
	// initialize MFC and print and error on failure<br />
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))<br />
	{<br />
		// TODO: change error code to suit your needs<br />
		cerr << _T("Fatal Error: MFC initialization failed") << endl;<br />
		nRetCode = 1;<br />
	}<br />
	else<br />
	{<br />
		// TODO: code your application's behavior here.<br />
     // getting the file name <br />
     CString fileName;<br />
     for (int i = 1; i < argc; i++)<br />
     {   <br />
        fileName += argv[i]; <br />
        fileName += " ";<br />
     }<br />
     //fileName = "e:\\apqad.doc";<br />
     cout<<"Opening "<<(const char*)fileName<<" ..."<<endl;<br />
<br />
     // Initialize COM for this thread...<br />
     CoInitialize(NULL);<br />
<br />
       _Application app;   // get msword object.<br />
      //app.AttachDispatch(pXlApp);<br />
      if(!app.CreateDispatch("Word.Application"))<br />
      {<br />
       AfxMessageBox("Could not create MS Word Application Object.");<br />
       return 1;<br />
      }<br />
      LPDISPATCH lpDisp; //often reused variable.<br />
      //common OLE variants. Easy variants to use for calling arguments.<br />
      COleVariant covTrue((short)TRUE),covFalse((short)FALSE),covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);<br />
  <br />
      lpDisp = app.GetDocuments(); // ms word documents <br />
      Documents documents;<br />
      documents.AttachDispatch(lpDisp);<br />
      COleVariant vOpt(DISP_E_PARAMNOTFOUND, VT_ERROR);  //For optional args<br />
   <br />
      _Document document = documents.Open(COleVariant((CString)fileName), vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt);<br />
      app.SetVisible(TRUE);   // setting application visiable.<br />
    <br />
      cout<<"Formatting documents..."<<endl;<br />
      PageSetup pagesetup = document.GetPageSetup();<br />
      float bottomMargin = pagesetup.GetBottomMargin(); // get bottom margin<br />
      if(bottomMargin < 70 )  <br />
        pagesetup.SetBottomMargin(bottomMargin+20);  // set bottom margin <br />
    <br />
      float leftMargin = pagesetup.GetLeftMargin();<br />
      if(leftMargin< 70)<br />
        pagesetup.SetLeftMargin(leftMargin+20);<br />
      float rightMargin = pagesetup.GetRightMargin();<br />
      if(rightMargin < 70)<br />
        pagesetup.SetRightMargin(rightMargin+20);<br />
<br />
      float headerMargin = pagesetup.GetHeaderDistance();<br />
      if(headerMargin < 60 )<br />
        pagesetup.SetHeaderDistance(headerMargin+10);<br />
      float topMargin = pagesetup.GetTopMargin();<br />
      if(topMargin <60)<br />
        pagesetup.SetTopMargin(topMargin +20);<br />
<br />
      float footerDistance = pagesetup.GetFooterDistance();<br />
      pagesetup.SetFooterDistance(footerDistance + 10);<br />
      documents.ReleaseDispatch();<br />
      cout<<"Printting document...";<br />
      document.PrintOut(COleVariant((short)false), vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt);<br />
    <br />
      //Close the document without saving changes<br />
      document.Close(COleVariant((short)false), vOpt, vOpt);<br />
      <br />
      //exiting MSWord application.<br />
      VARIANT x;<br />
      x.vt = VT_I4;<br />
      x.lVal = 1;<br />
      //AutoWrap(DISPATCH_PROPERTYPUT, NULL, documents,L"Saved",1,x);<br />
      app.Quit(covFalse,covOptional,covOptional);<br />
      //AutoWrap(DISPATCH_METHOD, NULL, pXlApp,L"Quit",0);   <br />
      CoUninitialize();<br />
<br />
	}<br />
<br />
	return nRetCode;<br />
}<br />
<br />
<br />

Thank you
GeneralRe: why do have to restart to get excel/ word application. every time Pin
SHaroz18-Jul-02 5:43
SHaroz18-Jul-02 5:43 
GeneralRe: why do have to restart to get excel/ word application. every time Pin
pnpfriend18-Jul-02 6:04
pnpfriend18-Jul-02 6:04 
GeneralRe: why do have to restart to get excel/ word application. every time Pin
SHaroz18-Jul-02 6:16
SHaroz18-Jul-02 6:16 
GeneralRe: why do have to restart to get excel/ word application. every time Pin
pnpfriend18-Jul-02 6:52
pnpfriend18-Jul-02 6:52 
GeneralRe: why do have to restart to get excel/ word application. every time Pin
SHaroz18-Jul-02 7:14
SHaroz18-Jul-02 7:14 
GeneralRe: why do have to restart to get excel/ word application. every time Pin
pnpfriend18-Jul-02 8:26
pnpfriend18-Jul-02 8:26 
GeneralRe: why do have to restart to get excel/ word application. every time Pin
soptest18-Jul-02 9:57
soptest18-Jul-02 9:57 
GeneralHELP ME TO FIND AN ERROR Pin
Alex Cramer17-Jul-02 23:59
Alex Cramer17-Jul-02 23:59 
GeneralRe: HELP ME TO FIND AN ERROR Pin
soptest18-Jul-02 8:06
soptest18-Jul-02 8:06 
GeneralRe: HELP ME TO FIND AN ERROR Pin
soptest18-Jul-02 9:38
soptest18-Jul-02 9:38 
GeneralRe: HELP ME TO FIND AN ERROR Pin
Alex Cramer18-Jul-02 15:26
Alex Cramer18-Jul-02 15:26 
GeneralRe: HELP ME TO FIND AN ERROR Pin
Jörgen Sigvardsson21-Jul-02 8:21
Jörgen Sigvardsson21-Jul-02 8:21 
GeneralOdd bug causes my app to hang Pin
MS le Roux16-Jul-02 23:46
MS le Roux16-Jul-02 23:46 
GeneralCustomDraw of a CListCtrl within a Composite Control. Pin
Brian van der Beek16-Jul-02 22:56
Brian van der Beek16-Jul-02 22:56 
GeneralDeskband Pin
Anonymous15-Jul-02 22:49
Anonymous15-Jul-02 22:49 
GeneralRe: Deskband Pin
Shaun Harrington11-Oct-06 4:14
Shaun Harrington11-Oct-06 4:14 
Generalmsword automation Pin
pnpfriend15-Jul-02 11:27
pnpfriend15-Jul-02 11:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.