DOCUMENT:Q190523 07-AUG-1998 [vbwin] TITLE :PRB: Automation Error (-2147417843) Using the System Tray PRODUCT :Microsoft Visual Basic for Windows PROD/VER: OPER/SYS:WINDOWS KEYWORDS: ====================================================================== --------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0 --------------------------------------------------------------------- SYMPTOMS ======== When using the Shell_NotifyIcon API or the SysTray control sample from the Visual Basic CD-ROM, you may receive the following error message: Run-time error: -2147417843 (8001010d) Automation Error CAUSE ===== The run-time error occurs because you are trying to make an Automation call to an out-of-process (ActiveX) EXE from within the event notification of the system tray callback. The value -2147417843 translates to the following error message: An outgoing call cannot be made since the application is dispatching an input-synchronous call. Automation clients are required by COM to process input-synchronous calls without interruption, and therefore are prevented from making outgoing Automation calls while processing such messages. RESOLUTION ========== Avoid making outgoing Automation calls during the System Tray callback. If an Automation method needs to be called in response to a user event involving the System Tray, use a simple Timer to post yourself a message, and then let the callback function complete. When the Timer event fires, you can safely call your Automation method. STATUS ====== This behavior is by design. MORE INFORMATION ================ Steps to Reproduce Behavior --------------------------- 1. Copy the SysTray control sample from the Tools\Unsupprt directory of the Visual Basic 5.0 CD-ROM, or the Common\Tools\VB\Unsupprt directory of the Visual Basic 6.0 CD-ROM, to your hard drive. 2. Open the project and compile the control. When complete, close the project. 3. Create a new Standard EXE project. Form1 is created by default. 4. From the Project menu, click Components and check "System Tray Icon Control". Click OK. 5. Select the SysTray control in the toolbox and add an instance to Form1. 6. Add the following code into Form1's code window: Option Explicit Private oWord As Object Private Sub Form_Load() Set oWord = CreateObject("Word.Application") Set cSysTray1.TrayIcon = Me.Icon cSysTray1.InTray = True End Sub Private Sub Form_Unload(Cancel As Integer) cSysTray1.InTray = False Set oWord = Nothing End Sub Private Sub cSysTray1_MouseDblClick(Button As Integer, Id As Long) oWord.Visible = True End Sub 7. Run the application by pressing the F5 key. The error will occur when you double-click the application's icon in the System Tray. Press END to stop the debugger. 8. To avoid the error, add a Timer to Form1. 9. Replace the code in Form1 with the following: Option Explicit Private oWord As Object Private Sub Form_Load() Set oWord = CreateObject("Word.Application") Set cSysTray1.TrayIcon = Me.Icon cSysTray1.InTray = True Timer1.Enabled = False Timer1.Interval = 10 End Sub Private Sub Form_Unload(Cancel As Integer) cSysTray1.InTray = False Set oWord = Nothing End Sub Private Sub cSysTray1_MouseDblClick(Button As Integer, Id As Long) Timer1.Enabled = True End Sub Private Sub Timer1_Timer() Timer1.Enabled = False oWord.Visible = True End Sub 10. Re-run the application by pressing the F5 key. This time no error should occur. REFERENCES ========== For additional information, please see the following article in the Microsoft Knowledge Base: ARTICLE-ID: Q176085 TITLE : HOWTO: Use the System Tray Directly from Visual Basic 5.0 Additional query words: kbVBp kbdsd kbDSupport kbVBp500 kbVBp600 kbAutomation ====================================================================== Platform : WINDOWS Issue type : kbprb ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 1998.