LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Interesting Word save document behavior

I am using the Word feature in Labwindows to create test report
documents at the end of a functional test cycle. At the end of the
function that I call to create the report, just before it returns to
the calling routine, Labwindows stops in the "WordRpt_DocumentSaveAs"
function that I called, very similar to a breakpoint (which I didnt
set). I can hit the continue button and it finishes creating and
saving the Word report. I found that if I comment out the following
line in the "WordRpt_DocumentSaveAs" function, it doesnt stop (see
below), but I
have trouble opening the newly created Word document unless I wait a
while or exit the Labwindows program. This only occurs when I run the
program by clicking on the green debug project arrow in the GUI
toolbar. This issue doensnt occur when I create a debug or release
executable! So it is not really a problem, as the document gets
created in either case. I was just wondering if anyone else has run
across this behavior and if so, have they found a way to resolve it?

My code snippet of the call to save the Word document:
// save the report and close the application
WordRpt_DocumentSaveAs (gDocHandle, fileName); // save the
document
WordRpt_ApplicationQuit (gAppHandle,
WRConst_DoNotSaveChanges); //
close the application
return 0;

Code snippet of the "WordRpt_DocumentSaveAs" function (located in the
WordReport.c module) showing the "CA_VariantClear (&vtfileName)" line
of code, where Labwindows stops, very similar to setting a
breakpoint. :

HRESULT CVIFUNC WordRpt_DocumentSaveAs(CAObjHandle docHandle,
char
fileName[MAX_PATHNAME_LEN])
{
HRESULT error = S_OK;
VARIANT vtfileName;

CA_VariantSetEmpty (&vtfileName);

errChk (CA_VariantSetCString (&vtfileName, fileName));
errChk(Word_DocumentSaveAs (docHandle, NULL, vtfileName,
CA_DEFAULT_VAL,
CA_DEFAULT_VAL, CA_DEFAULT_VAL,
CA_DEFAULT_VAL,
CA_DEFAULT_VAL, CA_DEFAULT_VAL,
CA_DEFAULT_VAL,
CA_DEFAULT_VAL, CA_DEFAULT_VAL,
CA_DEFAULT_VAL));
Error:
// CA_VariantClear (&vtfileName); (THIS IS WHERE THE PROGRAM
STOPS, BUT DOESNT STOP WITH
THIS LINE
COMMENTED OUT)
return error;
}

Thanks for any comments regarding this behavior.

0 Kudos
Message 1 of 4
(3,762 Views)
Hi Mike,

Could you post a working project that can reproduce this behavior so I can try it on my machine?

Regards,
0 Kudos
Message 2 of 4
(3,744 Views)

Hi Mike,

I experience the same proplem what you have explained. But I could not see any suggestion or work around to handle this problem in this thread. Were you able to rectify it. I badly need a work around since I have an additional problem, when I open the same word report after generation using below CVI codes,

WordRpt_ApplicationNew (VTRUE, &appHandleTemp);                                                                   
WordRpt_DocumentOpen (appHandleTemp, fileNameTemp_buff, &docHandleTemp); 

It opens a word document with few funny ASCII characters. I believe, this has caused due to the other problem we encounter when the file is saved.

Any work around please?

BR,

Muralee.

 

 

 

0 Kudos
Message 3 of 4
(3,565 Views)
Hi Mike,
First of all,some of this "Bugs" is fixed by patch-update for office-word applicatin.

The problem is in "reallocation" of memory in VARIANT for string Variable in word ActiveX.

mine English isn't much good,, but this description perhaps show the heart of the problem:

 in function WordRpt_DocumentSaveAs()
 {
   CA_VariantSetCString (&vtfileName, fileName);//memory for string is allocated in VARIANT,and fileName is copied to this
   in function
Word_DocumentSaveAs(...,vtfileName,...)
      {
        command is send to the application
        __result = CA_MethodInvokeEx (...,
vtfileName,...);
            //int this call
vtfileName is chanded, string is the same as before call, but adress is new.(old adress is not valid yet)
            //becouse vtFileName is "passed by Value"
variable, to this function/Word_DocumentSaveAs/,
            //  this new adress is available only in this function.
        but in this function, is not released->memory leak.
        return ..;
      }
 
CA_VariantClear(vtfileName);//try to release memory from  pointer with older/invalid adress.

return;
}

{This problem is also in WordRpt_GoToBookmark an sometimes Word_DocumentOpen, in some of Word version}

0 Kudos
Message 4 of 4
(3,558 Views)