Disappearing Window in Word Addin

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am developing an addin for Word using C#. When the addin is activated, an
always-on-top window is created with which the user interacts while editing a
document. Sometimes, this window disappears. That is, you can no longer see
the window, but it still exists. I have checked this through the debugger.
The Visible property is still set to true, the size does not change, etc, but
you can no longer see/interact with the window. The window disappears after
closing a MessageBox that was created by the addin, but not always in the
same place. This behavior occurs on Windows 2000 or Windows 2000 Server
systems with Office 2000 installed. It does not occur on Windows 2000 or
Windows XP systems with Office 2003 installed. Does this behavior sound
familiar to anyone? Any help would be greatly appreciated.
 
Hi

What develop environment do you develop your word addin?
Since office 2000 has no PIA(primary interop assembly), when you run the
word addin on the test machine, which interop assembly do you use?(I mean
if you are using the interop assembly which is generated by IDE when you
add a reference to the word10 library)

Also it seems that the problem is randomly, have you tried to simplify the
addin with just the a winform and set it topmost?
If you still can reproduce the problem, please post the simple reproduce
code and steps so that we can do further troubleshooting?


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
I was developing using WinXP and the Office 11 PIAs. Since I first posted, I
have attempted to refference the DLLs from Office 2000. I copied the
mso9.dll and
msword9.olb libraries to my development machine for access to the Microsoft
Office 9.0 Object Library and Microsoft Word 9.0 Object Library,
respectively. Unfortunately, this version does not install correctly. The
installer runs without errors, but the addin is not recognised by Word. That
is, the addin does not appear in the list of available addins under the COM
Addins menu in Word. Am I not using the correct libraries? If not, which
libraries should I use to support Word 2000?
 
Hi,

I think we do not need to specified to the concrete file, we can add com
reference to the com library by right click on the reference in the
solution explorer.
In the Add reference dialog, select the COM tab, and located the two
libraries below.
1. Microsoft Office 9.0 Object Library
2. Microsoft Word 9.0 Object Library.

So that the IDE will generate the according interop assembly in the same
place where you place your .net assembly.

You may have a try and let me know the result.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
I'm sorry, I think I was unclear. I meant that I copied the libraries to my
development machine so that they would be available to reference. Since I do
not have Office 2000 installed on my development machine, the libraries were
not available on the Add References dialog. Once I had copied them, I added
references as you suggest. Although the project compiled and the installer
appeared to run properly, Word did not recognize the addin, as I explained
previously. I have now also compiled the project on a Windows 2000 system
with Office 2000 installed with the same results. I will create a dummy
project and see if I can reproduce the problem.
 
Hi
previously. I have now also compiled the project on a Windows 2000 system
with Office 2000 installed with the same results. I will create a dummy

Since you can compile the project with office 2000 installed machine, have
you tried to regenerate the interop assembly with IDE, please refer to my
last post.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thank you very much for your patience, Peter. I think that I have discovered
one of my problems, but not its cause. I would like to run through the
current situation one more time; perhaps you will see where I have made a
mistake.

I have created two projects within the same solution, one for Office 9 and
one for Office 11. Both projects use the same source files linked from a
common source. I have used preprocessor directives in the common code in the
few places that the code must be different for Office 9 vs Office 11 (e.g.
Assigning the GuidAttribute and ProgId of the addin).

The references for the Office 9 project are:
- Extensibility
- Interop.Office (Microsoft Office 9.0 Object Library)
- System
- System.Data
- System.Drawing
- System.Windows.Forms
- System.XML
- Microsoft.Vbe.Interop
- Interop.Word (Microsoft Word 9.0 Object Library)

The references for the Office 11 project are:
- Extensibility
- Microsoft.Office.Core (Microsoft Office 11.0 Object Library)
- System
- System.Data
- System.Drawing
- System.Windows.Forms
- System.XML
- Microsoft.Vbe.Interop
- Microsoft.Office.Interop.Word (Microsoft Word 11.0 Object Library)

There is also a Setup project for each version. All projects compile with
no errors. Both Setup MSIs install with no errors. The Office 11 addin
works fine. The Office 9 addin, however, does not show up in the list of
available addins in Word. Further investigation shows that the required
registry entries do not exist. Although the entry exists for
HKEY_CURRENT_USER\Software\Microsoft\Office\Word\Addins\MyOffice9Addin, the
entry for HKEY_CLASSES_ROOT\CLSID\{guid} does not exist, nor do any of the
entries for the custom classes used by the addin.

What could cause this behavior? Why would the Office 11 setup project work
but the Office 9 not? All of the files are copied to the correct location,
but there are no registry entries to point to them.

Thanks again for your continued assistance and patience.
TIA
 
Hi

Yes, it seems to be somewhat strange, did the problem persist on the dev
machine, I mean if you build the office 9 addin, did the addin appears in
the addin dialog?

Also have you tried use the regasm tool to register the managed addin
assembly, usually it should be done by setup project.
[NOTE] please use the regasm with the /codebase switch so that word can
locate it correctly.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi,

If you have any more concerns on it, please feel free to post here.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks for all your help, Peter. I have (sort of) solved my problem. After
numerous changes, I have discovered something very strange. Even though the
project compiled fine, I found that the addin failed to run if certain
classes were included. After much tedious detective work, I narrowed down
the problem to two issues. All the classes that caused problems took either
Word.Document or Word.Range as parameters in their constructors. I found
that by changing these types to Object and later casting them into their
proper types that everything worked. Below is an example of a fixed class.
I don't understand why the constructors don't work under Windows 2000, but
this seems to do the trick. Is it a bug?

public class TermHit
{
protected Term m_term;
protected Word.Range m_range;

#region Public Instance Constructors

#if OFFICE_09
// HACK: Why must Object be used instead of Word.Range? If Word.Range is
// used, the addin fails under Word 2000.
public TermHit( Term term, object range )
{
m_term = term;
m_range = range as Word.Range;
}
#elif OFFICE_11
public TermHit( Term term, Word.Range range )
{
m_term = term;
m_range = range;
}
#else
#error No office version selected.
#endif

public TermHit()
{
m_term = null;
m_range = null;
}

public Term Term
{
get
{
return m_term;
}

set
{
m_term = value;
}
}

public Word.Range Range
{
get
{
return m_range;
}

set
{
m_range = value;
}
}
}
 
Hi

Firstly Thank you for your sharing the experience in the community and I am
glad that you have found a solution.

Anyway can you provide a simple reproduce sample and detailed reproduce
steps so that we can do further troubleshooting since I have tried your
code with office 2000 but I can not reproduce the problem.

Thanks for you understanding.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
I am a little pressed for time right now, but I will try to post as soon as I
can. Thanks again for all your help.
 
Hi

Ok!

I look forward to hearing from you.
:)

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top