LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

wordreport.c error

I think this is an old can of worms I'm dealing with:
 
We have an app that uses WordReport and it's worked for a long time.  Recently, it quit working on several different systems.
 
I'm getting an error in wordreport.c at a function that is trying to go to the top of a newly created document.
 
WordRpt_GoToDocumentTop(docHandle);
 
Inside WordRpt_GoToDocumentTop(), it looks like it's getting an error when it tries to do this:
 
 
 
HRESULT CVIFUNC WordRpt_GoToDocumentTop (CAObjHandle docHandle)
{
    HRESULT error = S_OK;
    CAObjHandle lineHandleL;
    VARIANT vtGoToLine, vtGoToFirst;
   
    vtGoToLine = CA_VariantInt (WordConst_wdGoToLine);
   
    vtGoToFirst = CA_VariantInt (WordConst_wdGoToFirst);
    errChk (Word_DocumentGoTo (docHandle, NULL, vtGoToLine,
                       vtGoToFirst, CA_DEFAULT_VAL,
                       CA_DEFAULT_VAL, &lineHandleL));
    errChk (Word_SelectionSelect (lineHandleL, NULL));
   
Error:
   
    if (lineHandleL)

====>  error here:  LIbrary function error (return value == -2147024890 (0x80070006)).  The handle is invalid.
 
        CA_DiscardObjHandle(lineHandleL);
   
    return error;
}  
 
So what's causing this perfectly functioning app to suddenly fail on multiple systems?
 
Our systems are on a LAN and may have had an update to office pushed onto them but I don't know this for sure.
 
We're running Win XP SP2.  I believe the targets use Word 2003 SP2.
 
Is there some newer version of wordreport.c that we should be using?
 
Can I develop an app that uses wordreport.c on a development system using, say, word 2000 and then expect that app to work on a target that uses word 2003?
 
I have a sick feeling of deja vu all over again - I've been through this before ...
 
Menchar
 
 
0 Kudos
Message 1 of 17
(4,523 Views)

Well, sure as heck, I look at wordreport.c in CVI 8.1 and they've changed the error handling in this exact spot !!!!!

linHandleL is a local and not initialized, so trying to close it breaks if it happens to be non-zero but not a valid handle. 

CVI 8.1 :

HRESULT CVIFUNC WordRpt_GoToDocumentTop (CAObjHandle docHandle)
{
    HRESULT error = S_OK;
    CAObjHandle lineHandleL = 0;
    VARIANT vtGoToLine, vtGoToFirst;

    vtGoToLine = CA_VariantInt (WordConst_wdGoToLine);

    vtGoToFirst = CA_VariantInt (WordConst_wdGoToFirst);

    errChk (Word_DocumentGoTo (docHandle, NULL, vtGoToLine,
                       vtGoToFirst, CA_DEFAULT_VAL,
                       CA_DEFAULT_VAL, &lineHandleL));
    errChk (Word_RangeSelect (lineHandleL, NULL));

Error:
    CA_DiscardObjHandle(lineHandleL);

    return error;
}

 

 

Previous version (CVI 8.0 or 7.1 I don't know which):

HRESULT CVIFUNC WordRpt_GoToDocumentTop (CAObjHandle docHandle)
{
    HRESULT error = S_OK;
    CAObjHandle lineHandleL;
    VARIANT vtGoToLine, vtGoToFirst;
   
    vtGoToLine = CA_VariantInt (WordConst_wdGoToLine);
   
    vtGoToFirst = CA_VariantInt (WordConst_wdGoToFirst);

    errChk (Word_DocumentGoTo (docHandle, NULL, vtGoToLine,
                       vtGoToFirst, CA_DEFAULT_VAL,
                       CA_DEFAULT_VAL, &lineHandleL));
    errChk (Word_SelectionSelect (lineHandleL, NULL));
   
Error:
   
    if (lineHandleL)
        CA_DiscardObjHandle(lineHandleL);
   
    return error;
}  

So my questions are:

 

Is this a "real" error, or is the actual error somewhere upstream of this (i.e bad document handle), or is this just a case of a non-initialized local variable getting referenced when it happens to be non-zero?

If it's a bad document handle (some upstream error), and I'm running in debug mode, why wouldn't I get an error popup prior to this function?

Can I rebuild the application using just this newer, CVI 8.1 version of wordreport.c in CVI 8.0 ?  I don't want to build the app in 8.1 because of an issue with the serial library.

Should I change just this function in my (previously working fine) version of wordreport.c?

Menchar


 

 

Message Edited by menchar on 10-18-2007 10:24 PM

0 Kudos
Message 2 of 17
(4,524 Views)

Here's the top level code.  We ran the debug build by itself (not using the IDE) just to get a popup at any library errors.  The first error to show up is in the WordRpt_GoToDocumentTop() call.  I'd have thought if the doc handle was bad we'd see the error prior to that.

newDocument is true (nonzero) and fillInCoverSheet is true also.

// Open the document.
   if(newDocument) {
      WordRpt_DocumentNew(appHandle, &docHandle);     

    
      WordRpt_PageOrientation(docHandle, 1); // landscape
     
      // Set the default formatting attributes.
      // Set the margins.
      // WordRpt_SetMargins(CAObjHandle docHandle, float top, float bottom, float left, float right)
         WordRpt_SetMargins(docHandle, 0.3, 0.5, 1.2, 1.2); 

       // Add page numbering.
         // WordRpt_AddPageNumbers(CAObjHandle docHandle, int headerfooter, int alignment, int firstPage)
       WordRpt_AddPageNumbers(docHandle, WRConst_Footer, WRConst_AlignPageNumberCenter, WRConst_TRUE);

      if(!fillInCoverSheet) {
         // Reserve the first page for the cover sheet.
         WordRpt_NewPage(docHandle);
      }
   } else {
      WordRpt_DocumentOpen(appHandle, dataPackFileName, &docHandle);
   } 

   // Position the cursor at the correct location inside the document.
   if(fillInCoverSheet) {
      WordRpt_GoToDocumentTop(docHandle);    <=========  error popup here.
   } else {
      WordRpt_GoToDocumentEnd(docHandle);
      if(!newDocument)
         WordRpt_NewPage(docHandle);
   }

 

Thanks for any help / insight, yup I'm over the top a bit with this but it's getting my goat.

Menchar

Message Edited by menchar on 10-18-2007 10:34 PM

Message Edited by menchar on 10-18-2007 10:36 PM

0 Kudos
Message 3 of 17
(4,524 Views)
Menchar,

I looked through old versions of CVI to see when that code change, and it looks like it happened between CVI 5.5 and 6.0. I'm not sure how it would be possible for you to still have the old code in version 7.1 or 8.0, unless there was some kind of installation mishap. I can't explain that.

I'm assuming that the original error you saw (with the old code) was in the CA_DiscardObjHandle function, because of the uninitialized value of lineHandleL. The way that would have happened would have been if Word_DocumentGoTo had failed for some other reason, either because docHandle was bad, or because for some reason the Word server didn't like those instructions for this particular file (I don't know, for example, if it considers a new document to have 0 lines, in which case it might not let you go to the first line. It doesn't seem likely, but I didn't test this, so I don't know).

You're right in wondering why, if docHandle was bad, an earlier function call would not have complained. I don't know either. Did you try debugging this? If it's reproducible, it should be fairly easy to step through the code and find out what is going on.

To answer your question, you should be able to replace your wordreport.c with the 8.1 version of it. I don't think it has any dependencies on features that are only in 8.1, so it should work okay. But keep a copy of your old one, just in case.

Luis
0 Kudos
Message 4 of 17
(4,501 Views)

Luis -

Yup, my thoughts exactly, if uptream call failed why no popup.

We're going to debug through it to see what's happening.

Thanks.

Menchar

0 Kudos
Message 5 of 17
(4,497 Views)
Luis -

Our bad - we were carrying the old versions of word2000.*  wordreport.*  forward in our CVI projects and were building the apps in CVI 8.0.    So that's how the old versions were persisting despite a couple years of updates to CVI.

I see 8.0 now offers word2003.* files as well as word2000.* files.

We have some targets with Word 2000 and some with Word 2003. 

Which version of word200x.* should we be using?

And it looks like we need to be picking these up from the CVI/toolslib/activex/word folder directly, and not from a copy the way we had been.  We configure all our source files, and the *.c files are source, but it looks like this is really just a "source level" dependency with CVI, in the same general nature that we have binary dependencies on CVI stuff that we don't configure.

Menchar
0 Kudos
Message 6 of 17
(4,490 Views)
Now I see word2003.* was there only in CVI 8.0, it's missing in CVI 8.1.

The versions of word2000.c in 8.0 and 8.1 are the same.

So it looks to me as if we should be using word2000.*, not word2003.* ?

Comparing word2000.c with word2003.c shows them to be quite different.

Menchar
0 Kudos
Message 7 of 17
(4,486 Views)
More weirdness -

The prototype for WordRpt_SetMargins() is missing out of wordreport.h as included with CVI 8.0 and CVI 8.1

Yet the function is included in wordreport.c.  It's not static and it's not referenced from within wordreport.c.

Is this all as flaky as it seems or am I missing something ...

Menchar


0 Kudos
Message 8 of 17
(4,484 Views)
Menchar,

CVI never installed word2003.c. If you have this file in your CVI 8.0 installation, could it be because you generated it (using Tools>>Create ActiveX Controller)?

The version of the word wrapper that you use in your project does not have to match the version of Word that you have installed,so you shouldn't need word2003.c. The wrapper is a compile-time dependency, not run-time. You need only use a version of the wrapper that has all the functions that the calling code requires, so that it can link. In your case (I'm assuming), the calling code is the WordReport interface. This interface (Wordreport.fp) has a fixed dependency on word2000.c, and you should probably not change this.

About WordRpt_SetMargins... I checked and it looks like you are absolutely right. This function is incorrectly missing from the header file. I'm really sorry. I don't know how it happened, but it's pretty inexcusable.
You can work around it by adding an extern statement to your .c file (this way, you won't have to modify the header file in each version of CVI that you use).

Luis


0 Kudos
Message 9 of 17
(4,480 Views)
Luis -
 
Yup, I probably tried regenerating the automation controller at some point, and I had Word 2003 on the machine.
 
Yes, we're using word report.
 
Do you know what the wordreport.sub and word2000.sub files are?  
 
We need to load the wordreport.fp and word2000.fp, and the wordreport.c and word2000.c files and the wordreport.h and word2000.h files, but what are the .sub files and do they need to be in the project?
 
Thanks for your support Luis.
 
Menchar 

Message Edited by menchar on 10-22-2007 09:48 AM

0 Kudos
Message 10 of 17
(4,446 Views)