【问题标题】:Use vb.net dll in C#. How to acces the objects in C# form from vb.net dll?在 C# 中使用 vb.net dll。如何从 vb.net dll 以 C# 形式访问对象?
【发布时间】:2016-06-27 13:09:38
【问题描述】:

我无法将 vb.net 代码完全转换为 c# 代码,所以我决定制作一个 vb.net dll,然后将其添加到 c# 表单中。

但我对这个 dll 的东西很陌生,我不知道如何以 C# 形式访问对象。我将 C# 应用程序添加到 dll 中的引用,就像我为 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;  

但我不能这样做。因为不接受。怎么了?

【问题讨论】:

  • 很抱歉没有回答您的问题,只是想知道为什么您不能翻译所有内容?你试过翻译机吗?
  • 绝对没有区别。 C# 和 VB.Net 都编译为 MSIL。您只需引用 dll 并开始使用它的对象,就像使用其他任何 C# dll 一样。
  • 是的,但实际上它们效果不佳:/ 我试图自己翻译,但我无法到处翻译。我知道你可以添加 dll,但还是谢谢你。但我问了一些不同的问题。)

标签: c# vb.net dll


【解决方案1】:

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

private System.Windows.Forms.Label label1;

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

【讨论】:

  • 但是我把它们改成了公开的。或者他们的事件可能:P 所以没有办法吗??
  • 实际上我再次检查,我发现我改变了。这些是 Form1.Designer.cs private System.Windows.Forms.Button btnExit 中的代码;私有 System.Windows.Forms.Button btnBrowse;私有 System.Windows.Forms.OpenFileDialog opnPath;公共 System.Windows.Forms.Label label1;公共 System.Windows.Forms.Label label2; public System.Windows.Forms.Timer tmrBypass;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-28
  • 2012-06-24
  • 2019-02-05
  • 2014-05-28
相关资源
最近更新 更多