Visual Studio - VB - Windows窗体项目 - 未声明“变量”。它可能无法访问

时间:2015-04-13 16:13:51

标签: vb.net visual-studio-2012 lync-2010

我试图为简单的Lync" bot"编译此代码。如找到HERE

我正在使用Visual Studio 2013并安装了Lync 2010 SDK(和Lync 2010客户端)。我知道该SDK中所需的DLL已正确导入,因为我已在PowerShell项目的其他地方成功使用它。

在尝试构建解决方案时,我遇到的问题是该网站上的第一个评论者得到了但没有得到解决方案。我在" Extensions"下添加了对任何内容的引用。以" Microsoft.Lync开头。" (其中有4个)。我的具体错误:

------ Build started: Project: WindowsApplication1, Configuration: Debug Any CPU ------
C:\Users\MyUser\WindowsApplication1\WindowsApplication1\Form1.vb(31) : error BC30451: '_InitializeFlag' is not declared. It may be inaccessible due to its protection level.
C:\Users\MyUser\WindowsApplication1\WindowsApplication1\Form1.vb(46) : error BC30451: 'LycConversation' is not declared. It may be inaccessible due to its protection level.
C:\Users\MyUser\WindowsApplication1\WindowsApplication1\Form1.vb(46) : error BC30451: 'Lyc' is not declared. It may be inaccessible due to its protection level.
C:\Users\MyUser\WindowsApplication1\WindowsApplication1\Form1.vb(47) : error BC30581: 'AddressOf' expression cannot be converted to 'Object' because 'Object' is not a delegate type.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我的具体代码:

Imports Microsoft.Lync.Model
Imports Microsoft.Lync.Model.Conversation
Public Class Form1
    Public WithEvents _Client As LyncClient
    Public WithEvents _ConversationMgr As Microsoft.Lync.Model.Conversation.ConversationManager
    Private WithEvents _LocalIMModality As InstantMessageModality
    Public _LycConversation As Microsoft.Lync.Model.Conversation.Conversation

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            _Client = LyncClient.GetClient()
            _ConversationMgr = _Client.ConversationManager
            Select Case _Client.State
                Case ClientState.Uninitialized
                    _Client.BeginInitialize(AddressOf InitializeCallback, Nothing)
                Case ClientState.SignedIn

                Case ClientState.SignedOut
                    _Client.EndSignIn(_Client.BeginSignIn(Nothing, Nothing, Nothing, Nothing, Nothing))
            End Select
        Catch ex As AlreadyInitializedException
            MessageBox.Show("Another process has initialized Lync")
        Catch ex As Exception

        End Try

    End Sub

    Private Sub InitializeCallback(ByVal ar As IAsyncResult)
        _Client.EndInitialize(ar)
        _InitializeFlag = True
        _Client.EndSignIn(_Client.BeginSignIn(Nothing, Nothing, Nothing, Nothing, Nothing))
    End Sub

    Private Sub _ConversationMgr_ConversationAdded(ByVal sender As Object, ByVal e As Microsoft.Lync.Model.Conversation.ConversationManagerEventArgs) Handles _ConversationMgr.ConversationAdded
        _LocalIMModality = TryCast(e.conversation.Participants(1).Modalities(ModalityTypes.InstantMessage), InstantMessageModality)

    End Sub

    Private Sub _LocalIMModality_InstantMessageReceived(ByVal sender As Object, ByVal e As Microsoft.Lync.Model.Conversation.MessageSentEventArgs) Handles _LocalIMModality.InstantMessageReceived
        Dim strRec As String
        strRec = e.Text.Replace(vbCr, "").Replace(vbLf, "").Replace("'", "''")
    End Sub

    Public Sub SendIM(ByVal strMessage As String)
        Dim modal = DirectCast(LycConversation.Modalities(Lyc.ModalityTypes.InstantMessage), InstantMessageModality)
        modal.BeginSendMessage(strMessage, AddressOf SendMessageCallback, Nothing)
    End Sub

    Private Sub SendMessageCallback(ByVal r As IAsyncResult)

    End Sub

End Class

非常感谢任何帮助。感谢。

1 个答案:

答案 0 :(得分:2)

这是原始代码中的错误。在this site我发现某人使用Lyc变量用于类似目的。我将Imports有效负载复制到我的函数中,如下所示:

Public Sub SendIM(ByVal strMessage As String)
        Dim modal = DirectCast(_LycConversation.Modalities(Microsoft.Lync.Model.Conversation.ModalityTypes.InstantMessage), InstantMessageModality)
        modal.BeginSendMessage(strMessage, AddressOf SendMessageCallback, Nothing)
    End Sub

另一部分是拼写错误:{1}}应该是Form1类的第四个语句LycConversation

_LycConversation

我无法测试代码是否按照预期的方式工作,但它现在可以编译并执行。