vb.net 从 VB .NET 访问 DLL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15465462/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Access DLL From VB .NET
提问by Joebocop
The answer to my question may already be out there, but I am having no success synthesizing the data into a coherent solution. Your advice is appreciated.
我的问题的答案可能已经在那里了,但我没有成功地将数据综合成一个连贯的解决方案。感谢您的建议。
I am writing a "User Control" application using Visual Basic (.NET 3.5) and Visual Studio 2012. I have been given a DLL file which contains functionality that I must access. Additionally, I have been given corresponding .LIB and .H files, which I am told will be necessary to properly make use of the DLL. I believe the DLL was written in C.
我正在使用 Visual Basic (.NET 3.5) 和 Visual Studio 2012 编写“用户控制”应用程序。我得到了一个 DLL 文件,其中包含我必须访问的功能。此外,我得到了相应的 .LIB 和 .H 文件,我被告知正确使用 DLL 是必要的。我相信 DLL 是用 C 编写的。
I have also been provided with some older VB code which is said to make use of the DLL's functions one that DLL is "included" (or something) in the project. As you can probably tell, my grasp on this is tenuous at best. Here is the VB code:
我还提供了一些较旧的 VB 代码,据说这些代码利用了 DLL 的功能,即 DLL 被“包含”(或其他东西)在项目中。正如您可能会说的那样,我对此的把握充其量是微不足道的。这是VB代码:
Private Declare Function SF_AddToCommandQueue Lib "SFrmUt80.dll" Alias "_SF_AddToCommandQueue@8" _
(ByVal CmdCode As Integer, ByVal strParam As String) As Boolean
Private Declare Function SF_FlushCommandQueue Lib "SFrmUt80.dll" Alias "_SF_FlushCommandQueue@4" _
(ByVal strWindowTitle As String) As Boolean
Private Declare Function SF_GetUserName Lib "SFrmUt80.dll" Alias "_SF_GetUserName@8" _
(ByVal strBuffer As String, ByVal BufferSize As Integer) As Integer
Private Declare Function SF_GetUserID Lib "SFrmUt80.dll" Alias "_SF_GetUserID@0" _
() As Integer
Private Declare Function SF_GetCmdType Lib "SFrmUt80.dll" Alias "_SF_GetCmdType@0" _
() As Integer
Private Declare Function SF_GetCmdFilename Lib "SFrmUt80.dll" Alias "_SF_GetCmdFilename@8" _
(ByVal strBuffer As String, ByVal BufferSize As Integer) As Integer
Private Declare Function SF_GetRegisteredMsg Lib "SFrmUt80.dll" Alias "_SF_GetRegisteredMsg@0" _
() As Integer
Hoping this is not too vague, I am wondering how I go about integrating this DLL file into my solution, so that I may make use of its functionality in VB .NET.
希望这不是太模糊,我想知道如何将这个 DLL 文件集成到我的解决方案中,以便我可以在 VB .NET 中使用它的功能。
Your wisdom is very much appreciated. Thank you!
非常感谢您的智慧。谢谢!
采纳答案by bash.d
The .H-files won't be of much use to you, as you don't use them in the managed environment. You would actually just include the DLLs into your solution (i.e. add them to the project in the Solution-Explorer).
VS does the rest for you, all you need to do is, as you already did, declare the functions from the library in your source-code and call the functions.
该.H-files将没有多大用处给你的,因为你不会在托管环境中使用它们。您实际上只需将DLLs包含到您的解决方案中(即,将它们添加到 中的项目中Solution-Explorer)。
VS 为您完成剩下的工作,您需要做的就是像您已经做过的那样,在源代码中声明库中的函数并调用这些函数。
On MSDNthere is an article on this.
在MSDN 上有一篇关于此的文章。

