none
Using Word Interop Libraries in COM Interop DLL RRS feed

  • Question

  • Hi,

    I am working on writing a DLL which is built in Visual Studio 2005 with VC++. It's a COM Interop DLL, i.e. this DLL will be used in COM Application built in Visual Studio 6.0 with C/C++. 

    The DLL contains various functions to interact with Word Interop DLL. I am supposed to implement a Spell Checking functionality using Word Interop Libs. I have already implemented it. But, I have a scenario. For every function written in DLL that deals with Word Interop, I am supposed to Open Word Application with statement - 

    Microsoft::Office::Interop::Word::Application *app = new Microsoft::Office::Interop::Word::Application(); 
    This app stays hidden and the function uses "app" object to interact with Word.

    In my case, basically, I input the text I want to perform a spell check on, to the DLL, DLL opens a hidden Word Application, copies the text in a document and perform spell checking on it. After the objective of the function is achieved, I close the open (but hidden) application. 

    Currently, I am supposed to do this with every function involving Word interaction, which just introduces annoying delays. 

    Can anyone suggest me a way to open Word app only once throughout the whole time and close it when I don't need it anymore?

    I know it's a bit lengthy and vague description of my problem, but I'll really appreciate if anyone can give me some idea.


    Thanks,
    Jwalant
    Wednesday, August 19, 2009 7:08 PM

Answers

  • Yeah, you'll launch a hidden instance of winword.exe for every function invocation.  That's should be noticeably slow.  Create a static class member that stores a singleton instance of the Application object so you can create it only once.  Beware that now you'll have an instance running for the live of the program.  Not so great either...

    Hans Passant.
    • Marked as answer by eryang Wednesday, August 26, 2009 9:07 AM
    Wednesday, August 19, 2009 8:13 PM
    Moderator

All replies

  • Yeah, you'll launch a hidden instance of winword.exe for every function invocation.  That's should be noticeably slow.  Create a static class member that stores a singleton instance of the Application object so you can create it only once.  Beware that now you'll have an instance running for the live of the program.  Not so great either...

    Hans Passant.
    • Marked as answer by eryang Wednesday, August 26, 2009 9:07 AM
    Wednesday, August 19, 2009 8:13 PM
    Moderator
  • Hey...
    That worked for me.. I agree, not the best thing... but it reduced the delay drastically. Which is fine for me as of now.

    Thank you for your reply.

    Jwalant
    Friday, September 4, 2009 4:10 PM