【问题标题】:Add reference to older DLL in .NET Application在 .NET 应用程序中添加对旧 DLL 的引用
【发布时间】:2013-08-20 19:52:33
【问题描述】:

我正在尝试向我的 .NET 项目中添加对来自 Army.mil 的文件 corscon_v6.dll 的引用。

添加文件时提示:'corpscon_v6.dll 无法添加。请确保该文件是可访问的,并且它是一个有效的程序集或 COM 组件。接下来,我运行 Dependency Walker,发现 DLL 内部有两个问题:找不到 IESHIMS.DLL 和 WER.DLL。我已经搜索了这些 DLL,似乎不需要它们。我也害怕从其他站点下载任何类型的 DLL,因为我无法信任它们,而且许多站点都说不要这样做。

接下来,我运行 tlbimp.exe 来转换 DLL,但这也不起作用。这会返回一个错误:输入文件 'c:\temp\corpscon_v6.dll' 不是有效的类型库。我也尝试过对其进行 regsvr32 操作,但这会返回“未找到入口点错误”。考虑到我花在处理完全损坏的陆军兵团网站上的时间,我完全不知道如何让他们宏伟的 CORPSCON DLL 在我的项目中工作/

【问题讨论】:

  • 这行不通,你必须使用 pinvoke。该网站已关闭,很难为您提供帮助。有示例声明 available here 但它们是 VB6 声明,您必须将其转换为 VB.NET。长 = 整数。
  • 你拯救了这一天!在我将数据类型从 long 更改为 int 之后,它起作用了!非常感谢您的帮助,我一直很沮丧,现在结束了! :)
  • 我不知道使用 PInvoke。在您向我发送该链接后,我尝试了其中的代码,但没有成功。因此,我开始研究我从该代码中得到的错误,并发现有人在切换数据类型后说它有效。我还是不知道 PInvoke 是什么 LOL...

标签: .net vb.net dll reference


【解决方案1】:

希望这会有所帮助。在检索答案之前,这一切都对我有用。 或许你能弄清楚这位老人对 C 的东西有什么不知道的地方。 祝你好运

导入 System.Runtime.InteropServices

模块模块1

<DllImport("c:\Develop\CorpsCon\corpscon_v6.dll", EntryPoint:="SetInSystem", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)>
Public Function SetInSystem(ByVal InValue As Integer) As Integer
    ' Leave function empty - DllImport attribute forces calls   
    ' to Corpsconconfig to be forwarded to MoveFileW in KERNEL32.DLL.  
End Function


<DllImport("c:\Develop\CorpsCon\corpscon_v6.dll", EntryPoint:="SetInDatum", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)>
Public Function setindatum(ByVal InValue As Int16) As Integer
    ' Leave function empty - DllImport attribute forces calls   
    ' to Corpsconconfig to be forwarded to MoveFileW in KERNEL32.DLL.  
End Function
<DllImport("c:\Develop\CorpsCon\corpscon_v6.dll", EntryPoint:="SetOutDatum", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)>
Public Function SetOutDatum(ByVal InValue As Int32) As Integer
    ' Leave function empty - DllImport attribute forces calls   
    ' to Corpsconconfig to be forwarded to MoveFileW in KERNEL32.DLL.  
End Function

<DllImport("c:\Develop\CorpsCon\corpscon_v6.dll", EntryPoint:="SetOutSystem", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)>
Public Function SetOutSystem(ByVal InValue As Int32) As Integer
    ' Leave function empty - DllImport attribute forces calls   
    ' to Corpsconconfig to be forwarded to MoveFileW in KERNEL32.DLL.  
End Function



<DllImport("c:\Develop\CorpsCon\corpscon_v6.dll", EntryPoint:="Corpscon_initialize", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)>
Public Function Corpscon_initialize() As Double
    ' Leave function empty - DllImport attribute forces calls   
    ' to Corpsconconfig to be forwarded to MoveFileW in KERNEL32.DLL.  
End Function


<DllImport("c:\Develop\CorpsCon\corpscon_v6.dll", EntryPoint:="GetXOut", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)>
Public Function GetXOut() As Double
    ' Leave function empty - DllImport attribute forces calls   
    ' to Corpsconconfig to be forwarded to MoveFileW in KERNEL32.DLL.  
End Function


<DllImport("c:\Develop\CorpsCon\corpscon_v6.dll", EntryPoint:="SetOutZone", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)>
Public Function SetOutZone(ByVal InValue As Int32) As Integer
    ' Leave function empty - DllImport attribute forces calls   
    ' to Corpsconconfig to be forwarded to MoveFileW in KERNEL32.DLL.  
End Function

<DllImport("c:\Develop\CorpsCon\corpscon_v6.dll", EntryPoint:="SetXIn", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)>
Public Function SetXIn(ByVal InValue As Double) As Integer
    ' Leave function empty - DllImport attribute forces calls   
    ' to Corpsconconfig to be forwarded to MoveFileW in KERNEL32.DLL.  
End Function


<DllImport("c:\Develop\CorpsCon\corpscon_v6.dll", EntryPoint:="SetYIn", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)>
Public Function SetYIn(ByVal InValue As Double) As Integer
    ' Leave function empty - DllImport attribute forces calls   
    ' to Corpsconconfig to be forwarded to MoveFileW in KERNEL32.DLL.  
End Function

<DllImport("c:\Develop\CorpsCon\corpscon_v6.dll", EntryPoint:="corpscon_initialize_convert", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)>
Public Function corpscon_initialize_convert() As Integer
    ' Leave function empty - DllImport attribute forces calls   
    ' to Corpsconconfig to be forwarded to MoveFileW in KERNEL32.DLL.  
End Function

<DllImport("c:\Develop\CorpsCon\corpscon_v6.dll", EntryPoint:="SetOutUnits", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)>
Public Function SetOutUnits(ByVal InValue As Int32) As Integer
    ' Leave function empty - DllImport attribute forces calls   
    ' to Corpsconconfig to be forwarded to MoveFileW in KERNEL32.DLL.  
End Function

<DllImport("c:\Develop\CorpsCon\corpscon_v6.dll", EntryPoint:="GetYOut", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)>
Public Function GetYOut() As Double
    ' Leave function empty - DllImport attribute forces calls   
    ' to Corpsconconfig to be forwarded to MoveFileW in KERNEL32.DLL.  
End Function



Public Sub convertDegreestoMeters(ByVal inx As Double, ByVal iny As Double, ByRef outx As Double, ByRef outy As Double)
    Dim RetVal As Integer

    RetVal = SetInSystem(1)
    RetVal = setindatum(1983)
    RetVal = SetOutSystem(2)
    RetVal = SetOutDatum(1983)
    RetVal = setoutzone(2301)
    RetVal = setoutUnits(3)  '1=US Servey Foot, 2=International Foor,3=Meters

    RetVal = corpscon_initialize_convert()

    RetVal = SetYIn(iny)
    RetVal = SetXIn(inx)
    Dim script As String

    RetVal = corpscon_initialize_convert()

    Dim outdbl As Double
    outdbl = GetXOut()
    script = "<script language=JavaScript>window.alert('" & outdbl & "'); </script>"
    'ClientScript.RegisterStartupScript(Me.GetType, "tab3", script)  
    outx = outdbl

    outdbl = GetYOut()
    script = "<script language=JavaScript>window.alert('" & outdbl & "'); </script>"
    'ClientScript.RegisterStartupScript(Me.GetType, "tab4", script)  
    outy = outdbl

End Sub

Sub Main()
    Dim outx As Double = 0
    Dim outy As Double = 0
    Call convertDegreestoMeters(CDbl(88.5555), CDbl(27.5555), outx, outy)
    'Results SHOULD BE Outx=
End Sub

结束模块

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-20
    • 2020-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多