且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将.Lib文件中的函数导出到C#

更新时间:2023-02-12 16:07:25

哦,不,这是不可能的。你可以只使用PE(可移植可执行文件)文件P / Invoke一个DLL,你可以链接导出的函数。



我认为你只需要使用 WINMM.DLL 而不是。



如果LIB文件不是任何DLL的链接库,或者你不知道应该使用什么DLL, 这是一个不同的故事

为了找到答案,你可以使用我的一些二进制转储实用程序,例如 dumpbin。 exe http://msdn.microsoft。 com / en-us / library / c1h23y6c(v = vs.71).aspx [ ^ ](要使用此实用程序,***从Visual Studio命令提示符开始)。如果这是某个DLL的链接库,您可以找到要使用的DLL文件。如果不是,你没有P / Invoke。



你应该首先创建一个可以在C#项目中使用的库。以下是您在这种情况下可以做的事情:



方法#1 。使用C ++ / CLI创建混合模式项目(托管+非托管)C ++。您可以将库链接为非托管代码,将调用包装在C ++ / CLI类(类)中的非托管代码中。之后,您可以像使用常规.NET程序集一样使用结果库,并在任何C#项目中引用它。



方法#2 。另一个机会是使用P / Invoke。在这种情况下,您使用C ++创建常规非托管DLL,链接库并导出所需的功能。使用P / Invoke生成DLL。



-SA
Oh, no, this is impossible. You can only P/Invoke a DLL, more exactly, using PE (Portable Executable) file you can link the functions exported.

I think you simply need to use WINMM.DLL instead.

If the LIB file is not link library for any DLL or you don't know what DLL you should use, this is a different story.
To find out, you can use I some binary dump utility such as dumpbin.exe, http://msdn.microsoft.com/en-us/library/c1h23y6c(v=vs.71).aspx[^] (to use this utility, it's best to start from "Visual Studio Command Prompt"). If this is a link library for some DLL, you can find out what DLL file to use. If it is not, you have nothing to P/Invoke.

You should first create some library which you could use in your C# project. Here is what you can do in this case:

Method #1. Create mixed mode project (managed + unmanaged) C++ with C++/CLI. You can link the library as unmanaged code, wrap calls to unmanaged code in C++/CLI class (classes). After that, you can use resulting library like a regular .NET Assembly and reference it in any C# project.

Method #2. Another opportunity is using P/Invoke. In this case, you create a regular unmanaged DLL using C++, link the library and export the function you need. Use P/Invoke with resulting DLL.

—SA


errdggdfgdfgdfgfgdfgdgdfgdfggdfgdfgdfgdfg
errdggdfgdfgdfgfgdfgdgdfgdfggdfgdfgdfgdfg