将.Lib文件中的函数导出到C# [英] export functions from a .Lib file to C#

查看:103
本文介绍了将.Lib文件中的函数导出到C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我想从 winmm.lib 库中导出一些函数...我试过用

[DllImport] 但它只适用于像kernel32.dll这样的动态库,

wininet32.dll

Hi guys!
I want to export some functions from winmm.lib library ...I tried to use
[DllImport] but it only works for dynamic libraries like kernel32.dll,
wininet32.dll

推荐答案

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



我认为你只需要使用< b> 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


这篇关于将.Lib文件中的函数导出到C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆