在C#中使用vb.net dll。如何从vb.net dll访问C#表单中的对象?

时间:2016-06-27 13:09:38

标签: c# vb.net dll

我无法将vb.net代码完全转换为c#代码,因此我决定创建一个vb.net dll,然后将其添加到c#表单。

但我是关于这个dll的新东西,我不知道如何以C#形式访问对象。我在dll中添加了C#应用程序,就像我为dll所做的那样。但我仍然无法访问C#应用程序中的计时器和2个标签。

这是我的vb.net dll

Public Class Class1
    Public Sub Bypass(block1 As String, block2 As String, ok1 As String, ok2 As String)
        Try
            Dim folderPath As String = Environment.GetFolderPath(SpecialFolder.Windows)
            FileSystem.FileClose(New Integer() {1})
            FileSystem.FileClose(New Integer() {2})
            If My.Computer.FileSystem.FileExists((folderPath & "\xspirit.sys")) Then
                FileSystem.FileOpen(1, (folderPath & "\xspirit.sys"), OpenMode.Append, OpenAccess.ReadWrite, OpenShare.LockReadWrite, -1)

            Else
                File.WriteAllBytes((folderPath & "\xspirit.sys"), New Byte() {0})
                FileSystem.FileOpen(1, (folderPath & "\xspirit.sys"), OpenMode.Append, OpenAccess.ReadWrite, OpenShare.LockReadWrite, -1)
                block1 = "Erişim Engellendi"
                MsgBox("Erişim Engellendi xspirit")
            End If
            If My.Computer.FileSystem.FileExists((folderPath & "\xhunter1.sys")) Then
                FileSystem.FileOpen(2, (folderPath & "\xhunter1.sys"), OpenMode.Append, OpenAccess.ReadWrite, OpenShare.LockReadWrite, -1)

            Else
                File.WriteAllBytes((folderPath & "\xhunter1.sys"), New Byte() {0})
                FileSystem.FileOpen(2, (folderPath & "\xhunter1.sys"), OpenMode.Append, OpenAccess.ReadWrite, OpenShare.LockReadWrite, -1)
                block2 = "Erişim Engellendi"
                MsgBox("Erişim Engellendi xhunter1")
            End If
        Catch exception1 As Exception
            ProjectData.SetProjectError(exception1)
            Dim ex As Exception = exception1
            ProjectData.SetProjectError(ex)
            Dim exception As Exception = ex
            ProjectData.ClearProjectError()
            ProjectData.ClearProjectError()
        End Try
        Dim p As Process()
        p = Process.GetProcessesByName("Wolfteam.bin") 'set wolfteam process
        If p.Count = 1 Then ' if wolfteam process detected
            ok1 = "XignCode Clear Başarılı"
            ok2 = "XignCode Clear Başarılı"
            MsgBox("XignCode Clear Başarılı xspirit")
            MsgBox("XignCode Clear Başarılı xhunter1")
        End If
    End Sub
End Class

我试图转换C#,但我完全不能这样做,所以我试图用这段代码从我的dll访问对象,但我不能这样做(是的,我把它添加到引用中)。

C#app.Form1(可以直到这里,但我不能继续这段代码。它不接受其余部分)

我想写下这个:

C#app.Form1.Timer1.Enabled = False or C#app.Form1.label1.Text = "test"

我也试过了:

Dim test1 As String="test" 

'then acces them from C# and then: 
vbnetdll.Class1 tt = new vbnetdll.Class1();   
label1.Text=f.vbmethod.test1;  

但我不能这样做。因为它不接受。有什么问题?

1 个答案:

答案 0 :(得分:0)

默认情况下,当您向表单添加项目时,它将在表单的类中声明为私有字段,如下所示:

private System.Windows.Forms.Label label1;

所以它不会从引用该表单的另一个程序集访问。它实际上与C#vs vb.net无关。