且构网

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

在C#中使用c lib文件

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

1)可以通过使用DllImport在c#中调用C库. 2)无法调用您不了解的东西.

通常不建议新手程序员从事这种互操作性,因为这非常困难并且需要对调用双方(C和C#)都具有广泛的了解.

您需要解决的事情是参数打包,字符串转换,内存分配和释放等.

检查以下链接:
http://en.allexperts.com/q/C-3307/2008/2/Using-C-class-C.htm?rd = 1 [ http://social.msdn.microsoft.com /forums/zh-CN/vcgeneral/thread/299da822-5539-4e5b-9ba7-b614e564c9f4/ [
1) It is possible to call C libraries in c# through the use of DllImport.
2) It is not possible to call something which you have no knowledge of.

Generally it is not advised for novice programmers to embark in this kind of interoperability as it is very hard and requires extensive knowledge of both sides of the call (C and C#).

Things you have to work around are parameter packing, string conversions, memory allocation and freeing etc.

Check the following links :
http://en.allexperts.com/q/C-3307/2008/2/Using-C-class-C.htm?rd=1[^]

http://social.msdn.microsoft.com/forums/en-US/vcgeneral/thread/299da822-5539-4e5b-9ba7-b614e564c9f4/[^]