0

选项 Strict 给我一个Late Binding错误,我总是将对象转换为正确的类型,但在这种特定情况下,我不知道如何转换该对象。

警告出现在指令中Shell.ToggleDesktop()

这是代码:

''' <summary>
''' "Shell" CLASSID.
''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/bb776890%28v=vs.85%29.aspx
''' </summary>
Private Shared ReadOnly CLSIDShell As New Guid("13709620-C279-11CE-A49E-444553540000")

''' <summary>
''' Gets the objects in the Shell.
''' Methods are provided to control the Shell and to execute commands within the Shell.
''' There are also methods to obtain other Shell-related objects.
''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/bb774094%28v=vs.85%29.aspx
''' </summary>
Private Shared ReadOnly Property Shell As Object
    Get
        If _Shell Is Nothing Then
            _Shell = Activator.CreateInstance(Type.GetTypeFromCLSID(CLSIDShell))
            Return _Shell
        Else
            Return _Shell
        End If
    End Get
End Property
Private Shared _Shell As Object = Nothing

''' <summary>
''' Shows or hides the desktop.
''' </summary>
Friend Shared Sub ToggleDesktop()

    Shell.ToggleDesktop()

End Sub
4

1 回答 1

1

您会收到此错误,因为该类型Object未公开名为ToggleDesktop.

您可以Option Strict Off为此代码文件进行设置,或者创建一个包装器并使用反射来调用该方法。

于 2014-09-28T08:27:46.213 回答