如何使用来自VS2008的c和h文件的asci c库。 [英] How to use asci c library with c and h files from VS2008.

查看:116
本文介绍了如何使用来自VS2008的c和h文件的asci c库。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名c#开发人员,想要使用在ASCI C中开发的库,它有许多带有c,h和makefile的文件夹。任何人都可以帮我指导如何使用Visual Studio 2008中的这个库

I am a c# developer, want to use the library developed in ASCI C, which is having many folders with c, h and makefile. Can any one help me guide how to use this library from Visual Studio 2008

推荐答案

使用



[ DllImport(your_functions.dll,CharSet = CharSet.Auto)]



你不能因为你不能将非托管代码(c)静态链接到托管代码(c# )。您必须编写.dll来包装C ++中的所有库函数。一旦你这样做,你可以使用C#interop功能从dll调用这些函数。
Use

[DllImport("your_functions.dll", CharSet = CharSet.Auto)]

You cannot because you can't statically link unmanaged code(c) into managed code(c#). You will have to write a .dll to wrap all your library functions in C++. Once you do, you can use C# interop functionality to call those functions from the dll.


这是一个更简单的解决方案。



创建链接到C库的C ++ / CLI项目。这完全避免了P / Invokes和DllImport。获取DllImport声明以匹配实际的C函数可能很痛苦。



使用公共函数在C ++项目中定义命名空间。你不需要编写任何C ++类 - 除非你想这样做。



C ++ / CLI语法起初有点奇怪(很多^ 帽子和智能感知在那里不起作用。



保持C ++ / CLI尽可能薄,以便大部分调试都在C#或C库中。



调试时,请务必启用混合调试,以便逐步执行.NET和本机代码。
Here's an easier solution.

Create a C++/CLI project that links to your C library. This completely avoids P/Invokes and DllImport. Getting the DllImport declarations to match actual C functions can be a pain.

Define a namespace in the C++ project with public functions. You don't need to write any C++ classes - unless you want to do so.

The C++/CLI syntax is a little strange at first (lots of "^" hats) and intellisense does not work there.

Keep the C++/CLI later as thin as possible so that most of your debugging is in C# or in the C library.

When debugging, be sure to enable Mixed debugging to you can step through .NET and native code.


这篇关于如何使用来自VS2008的c和h文件的asci c库。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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