编写一个可从 VS 2003 VC++ 访问的 dll代码
我需要能够用 C# 或 VC++ 编写一个 DLL,并且可以通过 Visual Studio 2003 VC++ 编写的代码访问该 DLL。看起来该代码是非托管的(使用 * 表示指针)VC++,并且该 DLL 需要能够直接放入当前代码并由当前代码访问。
DLL 是一个 RS232 驱动程序,需要能够返回一个 int 类型的错误代码,并通过引用将一些测量值传回调用程序。
我能用 C# 写这个吗?如果没有,我只能访问 Visual Studio 2005 或 2008。我是否能够在其中任一版本中编写代码,并且能够从当前代码库调用该 DLL 吗?或者我必须去 eBay 上寻找 VS 2003 的副本吗?
I need to be able to write a DLL in either C# or VC++ that is accessible from code that is written in Visual Studio 2003 VC++. It looks like the code is unmanaged (uses * for pointers) VC++ and this DLL needs to be able to drop right in and be accessed by the current code.
The DLL is an RS232 driver that needs to be able to return an int for an error code and pass back, by reference, some measured values, to the calling program.
Will I even be able to write this in C#? If not, I only have access to Visual Studio 2005 or 2008. Will I be able to write my code in either, and will that DLL be able to be called from the current code base? Or do I have to go looking on ebay for a copy of VS 2003?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 VS2008/2005 中用 C/C++ 编写的非托管 DLL 应该可以很好地调用 VS2003 C/C++ 项目中的代码。这也可能是阻力最小的路径。如果您的 DLL 引用了 VS2003 中不可能提供的其他 DLL,请确保在可以的情况下重新分发它们,否则以静态方式链接。
托管 DLL 也是可能的,但需要一点粘合代码来桥接托管/未管理的差距。确保以 VS2003 支持的 .NET 运行时版本 (1.1) 为目标。
An unmanaged DLL authored in C/C++ in VS2008/2005 should work just fine with invoking code in a VS2003 C/C++ project. It's also likely the path of least resistance. If your DLL references other DLL's that aren't likely to be available with VS2003, make sure to either re-distribute them if you can, or link statically otherwise.
A managed DLL is also possible, but will require a little bit of glue code to bridge the managed/unmanaged gap. Make sure to target the .NET runtime version that VS2003 supports (1.1).