BUG: ??? ????? ??????? ????? ?????? Office ?? Visual Studio .NET 2003

?????? ????????? ?????? ?????????
???? ???????: 830519 - ??? ???????? ???? ????? ????? ??? ???????.
??? ????? ??? ???????. ????? "??? ??" ??? ??? ??????? ??? ????.
????? ???? | ?? ????

?? ??? ??????

??????

??? ????? ?? Microsoft Visual Studio .NET 2003 ?? ????? ?????? ??? ??????? ??????? ????? ?? ??? COM ???? ??? Microsoft Word ?? ???? Microsoft Excel ?? ?? ???? Microsoft Outlook. ??? ????? ?? ?? ????? ????? ????? COM ? ????????? ???????? ???? ????? ??????? ????? ????, COM ?? ??? ????? ?????. ???? ??? ??????? ??? ??????? Interop COM ?? ???? ???? ??? ??????? (??? Microsoft Visual C# ?? Microsoft Visual Basic .NET) ????? ??????? ??????? 1.1 ?? Microsoft .NET Framework.

?????

????? ??? .NET Framework 1.1 ????? ??????? ?????? ?????? ???? ??? ??? ??????? ?? ???? COM. ???? .NET Framework 1.1 ???? ??? ???????? ??????? ????? ????? ??? ??????. ??? ????? Word ?? Excel ?? Outlook ?? ???? ????? ??????? Interop COM (IA) ?? ????? Interop ???????? (PIA) ?? Microsoft Office XP ?????? ??????? ??? ??????? ?? ?????? ??????? Microsoft Office ??????? ???????. ???? ???????? ??????? Word ????? ?????? Outlook ??? ??????? ????? ?????? ??????? Excel ????????? ?????? [??]. ?? ??? ????? ??????? ????? ?????? [??] ???? ??? ????? ????? ?????? ???? ??? ??????? ????? ??? ??????? ??? ??????? ?????? ?????? ?????? ?????? ?? ??? ??????? ??? ????????. ????? ?? ???? ????? ????? ?? ??????? ?????? ??? ??????? IA (?? PIA).

????

?? ????? ??? ??????? ?? Microsoft Office 2003.

???? ??????

??? ??? ?????? ????? ???? ?? Word ?? ????? ???? ?? Excel ?? ????? ???? ?? Outlook? ??? ???? ????? ???? ???? ??????? ?????? ?? ?? ????????? ???????? ???????. ????? ???? ????? ???? ??????? ????? ????? ???????? ??? ??? ???? ??? ??????? ?????. ????? ???? ????? ??????? ??? ????????.

???? Microsoft ??????? ???????? ??? ??? ?? ???? ??????? ?? ?? ?????. ??? ????? ???? ?? ????? ??? ???????? ??????? ?????? ???????? ?? ???????? ???? ????. ????? ??? ??????? ???? ?????? ?? ??? ??????? ???? ??? ????? ?? ??????? ???? ??? ????????? ?????? ?????? ?????????. ???? ??????? ????? ??? Microsoft ??? ????? ????? ???? ???? ?? ?????? ?????? ??? ??????? ?????? ????? ?????? ?? ????? ??????? ?????? ??????? ?????.

????? ??? ???????

?????? ????? ?? ????? ?? "Visual C" # ? ??? ????? dispinterface definition ?? ??? ???? ????? ????? ??? ????? ?????? ??? ?????. ??? ?? ????? ????? dispinterface ?????? ???? (DISPIDs) ???? ????? ???? ??????? ?? ??? ???? Office ???? ???? ??? ???? ????? "?" ???? ???? ????? (GUID). ?????? ?? ??? ??? ????? ??????? ???? ????? ???????:
  • ????? ??????? "???? ????" OLE/COM ??????? ?? ??????? Visual Studio .NET 2003 Professional Edition
  • ????? ??????? Platform SDK. ?????? ??? ??????? ?????? ??? Platform SDK ?? ?????? ???? Microsoft ?????? ??? ?????:

    http://www.microsoft.com/msdownload/platformsdk/sdkupdate
??? ????? GUID DISPIDs ????? ????? ????? ?????? ?? ?? ????? dispinterface ?? Visual Basic .NET ?? ?? Visual C#.

???? ??? ??????? ???????? ???? ????? ????? ??????? ????? ????? ??????? ??? ?????? ??? ??? ???????. ???? ?????? ????? ????? ??? ???? ????? ?????? ????? Word 2000 ?? ????? ??? DocumentBeforeClose ???? ????? ??? ???????? ????? ???????. ?????? ?????? ???????? ??????? ItemSend ??????? Outlook 2002 ???? ????? ????? ????? ??????? ?? ??????? ????? ??.

?????? 1: ??? ????? DocumentBeforeClose

  1. ??? ????? Visual Studio .NET 2003. ??? ????? ????. ??? Visual C# ???? ???????. ??? Windows ????? ?????. ??? ??????? MyWordEventTest ? ?? ???? ??? ?????.

    ?????????? ??? ????? Form1.
  2. ?? ??????? ??????? ???? ??? ????? ????. ?? ???? ?????? ? ??? ????? ?????? Microsoft Word 9.0 ??? ????? ??????? COM ???? ??? "?????" ?????? ???? ??? ?? ???? ??? ????? ?????? ???? ??????.

    ?? ????? IA ????? ?? ????????.
  3. ?? ??????? ??????? ???? ??? ????? ???. ??? ??? ??? ?? ?? ?????? ????? Word9EventHelper.cs. ???? ??? ????? ?????? ?????.
  4. ????? ????????? ???????? ??????? ??? ???? ????????? ???????? ????? Word9EventHelper.cs:
    using System;
    using System.Runtime.InteropServices;
    using Word; // The default name for a custom Word IA.
    // If you use Office XP and you have the PIAs
    // referenced in your project, you must change the previous line to read:
    // using Word = Microsoft.Office.Interop.Word;
    
    namespace WordAppEvents9
    {
    	[InterfaceType(ComInterfaceType.InterfaceIsIDispatch),
    	GuidAttribute("000209FE-0000-0000-C000-000000000046")]
    	public interface DWordApplicationEvents9
    	{
    		[DispId(0x00000001)] void Startup();
    		[DispId(0x00000002)] void Quit();
    		[DispId(0x00000003)] void DocumentChange();
    		[DispId(0x00000004)] void DocumentOpen(Word.Document doc);
    		[DispId(0x00000006)] void DocumentBeforeClose(Word.Document doc, ref bool Cancel);	
    		[DispId(0x00000007)] void DocumentBeforePrint(Word.Document doc, ref bool Cancel);
    		[DispId(0x00000008)] void DocumentBeforeSave(Word.Document doc, ref bool SaveAsUI, ref bool Cancel);
    		[DispId(0x00000009)] void NewDocument(Word.Document doc);
    		[DispId(0x0000000a)] void WindowActivate(Word.Document doc, Word.Window wn);
    		[DispId(0x0000000b)] void WindowDeactivate(Word.Document doc, Word.Window wn);
    		[DispId(0x0000000c)] void WindowSelectionChange(Word.Selection sel);
    		[DispId(0x0000000d)] void WindowBeforeRightClick(Word.Selection sel, ref bool Cancel);
    		[DispId(0x0000000e)] void WindowBeforeDoubleClick(Word.Selection sel, ref bool Cancel);
    	}
    
    
    	public class WordAppEventHelper : DWordApplicationEvents9, IDisposable
    	{
    		public WordAppEventHelper()
    		{
    			m_oConnectionPoint = null;
    			m_Cookie = 0;
    		}
    
    		public void Startup()
    		{System.Diagnostics.Debug.WriteLine("Startup");}
    
    		public void Quit()
    		{System.Diagnostics.Debug.WriteLine("Quit");}
    
    		public void DocumentChange()
    		{System.Diagnostics.Debug.WriteLine("DocumentChange");}
    
    		public void DocumentOpen(Word.Document doc)
    		{System.Diagnostics.Debug.WriteLine("DocumentOpen");}
    
    		public void DocumentBeforeClose(Word.Document doc, ref bool Cancel)
    		{
    			System.Diagnostics.Debug.WriteLine("DocumentBeforeClose");
    			Cancel = true; // Cancel the close!
    		}
    
    		public void DocumentBeforePrint(Word.Document doc, ref bool Cancel)
    		{System.Diagnostics.Debug.WriteLine("DocumentBeforePrint");}
    
    		public void DocumentBeforeSave(Word.Document doc, ref bool SaveAsUI, ref bool Cancel)
    		{System.Diagnostics.Debug.WriteLine("DocumentBeforeSave");}
    
    		public void NewDocument(Word.Document doc)
    		{System.Diagnostics.Debug.WriteLine("NewDocument");}
    
    		public void WindowActivate(Word.Document doc, Word.Window wn)
    		{System.Diagnostics.Debug.WriteLine("WindowActivate");}
    
    		public void WindowDeactivate(Word.Document doc, Word.Window wn)
    		{System.Diagnostics.Debug.WriteLine("WindowDeactivate");}
    
    		public void WindowSelectionChange(Word.Selection sel)
    		{System.Diagnostics.Debug.WriteLine("WindowSelectionChange");}
    
    		public void WindowBeforeRightClick(Word.Selection sel, ref bool Cancel)
    		{System.Diagnostics.Debug.WriteLine("WindowBeforeRightClick");}
    
    		public void WindowBeforeDoubleClick(Word.Selection sel, ref bool Cancel)
    		{System.Diagnostics.Debug.WriteLine("WindowBeforeDoubleClick");}
    
    		private UCOMIConnectionPoint m_oConnectionPoint;
    		private int m_Cookie;
    
    		public void SetupConnection(Word.Application app)
    		{
    			if (m_Cookie != 0) return;
    
    			// GUID of the DIID_ApplicationEvents dispinterface.
    			Guid guid = new Guid("{000209FE-0000-0000-C000-000000000046}");
    
    			// QI for IConnectionPointContainer.
    			UCOMIConnectionPointContainer oConnPointContainer = (UCOMIConnectionPointContainer)app;
    
    			// Find the connection point and then advise.
    			oConnPointContainer.FindConnectionPoint(ref guid, out m_oConnectionPoint);
    			m_oConnectionPoint.Advise(this, out m_Cookie);
    		}
    
    		public void RemoveConnection()
    		{
    			if (m_Cookie != 0)
    			{
    				m_oConnectionPoint.Unadvise(m_Cookie);
    				m_oConnectionPoint = null;
    				m_Cookie = 0;
    			}
    		}
    
    		public void Dispose(){RemoveConnection();}
    	}
    }
  5. ?????? ??? Form1 ?? ?? ?????? ?? ???. ???? ????? ??????? ??? ?? ????? ??? ???? ????????? ???????? ?? Form1.cs ????. ?? ?? ??????? ???? ???? ??? ????? ??? ??? ???? ????????? ???????? ?? Form1.cs ????. ?? ?????? ???????? ???????? ??????? ??? ????? ?? doc event:
    Word.Document doc;
    Object missing = System.Reflection.Missing.Value;
    
    // Create a new instance of Word and then set up the event handler.
    m_oApp = new Word.ApplicationClass();
    m_oAppEvents = new WordAppEvents9.WordAppEventHelper();
    m_oAppEvents.SetupConnection(m_oApp);
    
    // Make Word visible and then display a new document to test close.
    m_oApp.Visible = true;
    doc = m_oApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
    doc.UserControl = true;
    doc.Content.Text = "Try to close the document";
    
    // You only have to do this one time in this sample.
    button1.Enabled = false;
    
  6. ?? ?????? ????????? ???????? ??????? ??? ??? Form1 ??? ????? ??:
    Word.Application m_oApp;
    WordAppEvents9.WordAppEventHelper m_oAppEvents;
    
  7. ?? ??????? ????? ? ???? ??? ???? ???? ???? ???????. ???? ??? ????? ?? ???? ??? "????" ?????? ???????.

    ??? ??? ????? ??????? ????? ????? ??? ?? ????? ????? ?? Word. ?? ????? ????? ???? Word ??? ???? ?????? ??????? ????? ??.

    ????? ??????? ?????? ?????? ?????? ??????? ??????? ?? Excel.

?????? 2: ??? ????? ItemSend

  1. ??? ????? Visual Studio .NET 2003. ??? ????? ????. ??? Visual C# ???? ???????. ??? Windows ????? ?????. ??? ??????? MyOutlookEventTest ? ?? ???? ??? ?????.

    ?????????? ??? ????? Form1.
  2. ?? ??????? ??????? ???? ??? ????? ????. ?? ???? ?????? ? ??? ????? ?????? Microsoft Outlook 10.0 ??? ????? ??????? COM ???? ??? "?????" ?????? ???? ??? ?? ???? ??? ????? ?????? ???? ??????.

    ?? ????? IA ????? ?? ????????.
  3. ?? ??????? ??????? ???? ??? ????? ???. ??? ??? ??? ?? ?? ?????? ????? Outlook10EventHelper.cs. ???? ??? ????? ?????? ?????.
  4. ????? ????????? ???????? ??????? ??? ???? ????????? ???????? ????? Outlook10EventHelper.cs:
    using System;
    using System.Runtime.InteropServices;
    //using Outlook; // The default name for a custom Word IA.
    // If you use Office XP and you have the PIAs
    // referenced in your project, you must change the previous line to read:
    using Outlook = Microsoft.Office.Interop.Outlook;
    using System.Windows.Forms;
    
    namespace OutlookAppEvents10
    {
    	[InterfaceType(ComInterfaceType.InterfaceIsIDispatch),
    	GuidAttribute("0006300E-0000-0000-C000-000000000046")]
    	public interface DOutlookApplicationEvents_10
    	{
    		void ItemSend(object Item, ref bool Cancel);
    		void NewMail();
    		void Reminder(object Item);
    		void OptionsPagesAdd(Outlook.PropertyPages Pages);
    		void Startup();
    		void Quit();
    		void AdvancedSearchComplete(Outlook.Search SearchObject);
    		void AdvancedSearchStopped(Outlook.Search SearchObject);
    		void MAPILogonComplete();
    	}
    
    	public class OutlookAppEventHelper : IDisposable
    	{
    		public OutlookAppEventHelper()
    		{
    			m_oConnectionPoint = null;
    			m_Cookie = 0;
    		}
    
    		private UCOMIConnectionPoint m_oConnectionPoint;
    		private int m_Cookie;
    
    		public void SetupConnection(Outlook.Application app)
    		{
    			if (m_Cookie != 0) return;
    			// GUID of the DIID_ApplicationEvents dispinterface.
    			Guid guid = new Guid("{0006300E-0000-0000-C000-000000000046}");
    
    			// QI for IConnectionPointContainer.
    			UCOMIConnectionPointContainer oConnectionPointContainer = (UCOMIConnectionPointContainer)app;
    
    			// Find the connection point and then advise.
    			oConnectionPointContainer.FindConnectionPoint(ref guid, out m_oConnectionPoint);
    			m_oConnectionPoint.Advise(this, out m_Cookie);
    		}
    
    		public void RemoveConnection()
    		{
    			if (m_Cookie != 0)
    			{
    				m_oConnectionPoint.Unadvise(m_Cookie);
    				m_oConnectionPoint = null;
    				m_Cookie = 0;
    			}
    		}
    
    		#region IDisposable Members
    
    		public void Dispose()
    		{
    			RemoveConnection();
    		}
    
    		#endregion
    
    		//#region DOutlookApplicationEvents_10 Members
    
    		[DispId(0x0000F002)]
    		public void ItemSend(object Item, ref bool Cancel)
    		{
    			DialogResult result;
    			result = MessageBox.Show("Do you want to cancel the ItemSend event?","",MessageBoxButtons.YesNo);
    			if(result == DialogResult.Yes)
    			{
    				System.Diagnostics.Debug.WriteLine("Cancelling Message");
    				Cancel = true;	
    			}
    			else
    			{
    				System.Diagnostics.Debug.WriteLine("Passing Message");
    				Cancel = false;
    			}
    		}
    
    		[DispId(0x0000F003)]
    		public void NewMail()
    		{
    			MessageBox.Show("NewMail");
    		}
    
    		[DispId(0x0000F004)]
    		public void Reminder(object Item)
    		{
    			MessageBox.Show("Reminder");
    		}
    
    		[DispId(0x0000F005)]
    		public void OptionsPagesAdd(Microsoft.Office.Interop.Outlook.PropertyPages Pages)
    		{
    			MessageBox.Show("OptionsPagesAdd");
    		}
    
    		[DispId(0x0000F006)]
    		public void Startup()
    		{
    			MessageBox.Show("Startup");
    		}
    
    		[DispId(0x0000F007)]
    		public void Quit()
    		{
    			MessageBox.Show("Quit");
    		}
    
    		[DispId(0x0000FA6A)]
    		public void AdvancedSearchComplete(Microsoft.Office.Interop.Outlook.Search SearchObject)
    		{
    			MessageBox.Show("AdvancedSearchComplete");
    		}
    
    		[DispId(0x0000FA6B)]
    		public void AdvancedSearchStopped(Microsoft.Office.Interop.Outlook.Search SearchObject)
    		{
    			MessageBox.Show("AdvancedSearchStopped");
    		}
    
    		[DispId(0x0000FA90)]
    		public void MAPILogonComplete()
    		{
    			MessageBox.Show("MAPILogonComplete");
    		}
    		//#endregion
    	}
    }
    Note You need to place the [DispId(#)] attribute on the methods. ???? ???? ?? ???? ????? ?????.
  5. ?????? ??? Form1 ?? ?? ?????? ?? ???. ???? ????? ??????? ??? ?? ????? ??? ???? ????????? ???????? ?? Form1.cs ????. ?? ?? ??????? ???? ???? ??? ????? ??? ??? ???? ????????? ???????? ?? Form1.cs ????. ????? ????????? ???????? ??????? ??? ????? ?? ???? event:
    Outlook.MailItem item;
    
    if (m_oApp == null)
    {
    	// Create a new instance of Outlook and then set up the event handler.
    	m_oApp = new Outlook.ApplicationClass();
    	m_oAppEvents = new OutlookAppEvents10.OutlookAppEventHelper();
    	m_oAppEvents.SetupConnection(m_oApp);
    } 
    
    // Make Outlook visible and then display a new message to test send.
    item = (Outlook.MailItem)m_oApp.CreateItem(Outlook.OlItemType.olMailItem);
    item.Subject = "The Subject!";
    item.Body = "Try sending the message.";
    item.Display(m_oApp);
  6. ?? ?????? ????????? ???????? ??????? ??? ??? Form1 ??? ????? ??:
    Outlook.Application m_oApp;
    OutlookAppEvents10.OutlookAppEventHelper m_oAppEvents;
    
  7. ?? ??????? ????? ? ???? ??? ???? ???? ???? ???????. ???? ??? ????? ?? ???? ??? "????" ?????? ???????.

    ??? ??? ????? ??????? ????? ????? ??? ?? ????? ????? ?? Outlook. ??? ????? ????? ???? ???????? ???? ????????. ????? ??? ????????? ?? ????? ??? ?? ???? ??? ?????. ??? ???? ??? ???????? ???????? ???? ????? ??? ??? ??? ???? ?? ????? ??? ItemSend. ???? ??? ??? ????????.

    ????? ??????? ?????? ?????? ?????? ??????? ??????? ?? Excel.

?????

???? Microsoft ?? ??? ????? ?? ?????? Microsoft ??????? ?? ??? "????? ???" ?? ??? ???????.

?????

?????? ??? ??????? ?????? ??? ????? Office ?? Visual Studio .NET ? ???? ??? ??? ??????? ?????? ?????? ?? "????? ??????? ?? Microsoft:
311452????? Microsoft Office ???? ?? Visual Studio .NET
317109?? ????? ??????? Office ??? ??????? ???????? ?? ???? Visual Studio .NET

???????

???? ???????: 830519 - ????? ??? ??????: 28/???? ??????/1435 - ??????: 3.5
????? ???
  • Microsoft Excel 2002 Standard Edition
  • Microsoft Word 2002 Standard Edition
  • Microsoft Outlook 2002 Standard Edition
  • Microsoft Excel 2000 Standard Edition
  • Microsoft Word 2000 Standard Edition
  • Microsoft Outlook 2000
  • Microsoft .NET Framework 1.1
  • Microsoft Visual Studio .NET 2003 Professional Edition
  • Microsoft Visual Studio .NET 2003 Enterprise Architect
  • Microsoft Visual Studio .NET 2003 Academic Edition
????? ??????: 
kbnosurvey kbarchive kbmt kbnofix kbbug KB830519 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????830519

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com