可从.NET调用非常简单的C ++ DLL [英] Very simple C++ DLL that can be called from .net
问题描述
我试图调用从vb.net 2005年第三方供应商的C DLL和我得到的P / Invoke错误。我成功地调用其他方法,但已经创下了瓶颈就更加复杂的之一。所涉及的结构是可怕的,企图以简化故障排除我想创建一个C ++ DLL来重现问题。
有人可以提供最小的code代码段可从净被称为C ++ DLL?我得到的错误在我的C ++的dll命名XXX在DLL中找不到入口点。它应该是简单解决,但我不是一个C ++程序员。
我想使用一个.NET声明的DLL
声明功能乘库C:\ MYDLL \调试\ MYDLL.DLL别名乘法(BYVAL ParOne为整数,BYVAL byvalParTwo为整数)作为整数
尝试使用的 __ decspec(DLLEXPORT)魔仙尘在你的C ++函数声明。这个声明设置,你需要成功地从一个DLL导出函数的几件事。您可能还需要使用WINAPI或类似的东西:
__ declspec(dllexport)的WINAPI INT乘法(INT P1,P2 INT)
{
返回P1 * P2;
}
在WINAPI设置的函数调用约定,使得它适用于从语言通话,例如VB.NET。
I'm trying to call a 3rd party vendor's C DLL from vb.net 2005 and am getting P/Invoke errors. I'm successfully calling other methods but have hit a bottle-neck on one of the more complex. The structures involved are horrendous and in an attempt to simplify the troubleshooting I'd like to create a C++ DLL to replicate the problem.
Can somebody provide the smallest code snippet for a C++ DLL that can be called from .Net? I'm getting a "Unable to find entry point named XXX in DLL" error in my C++ dll. It should be simple to resolve but I'm not a C++ programmer.
I'd like to use a .net declaration for the DLL of
Declare Function Multiply Lib "C:\MyDll\Debug\MyDLL.DLL" Alias "Multiply" (ByVal ParOne As Integer, ByVal byvalParTwo As Integer) As Integer
Try using the __decspec(dllexport) magic pixie dust in your C++ function declaration. This declaration sets up several things that you need to successfully export a function from a DLL. You may also need to use WINAPI or something similar:
__declspec(dllexport) WINAPI int Multiply(int p1, int p2)
{
return p1 * p2;
}
The WINAPI sets up the function calling convention such that it's suitable for calling from a language such as VB.NET.
这篇关于可从.NET调用非常简单的C ++ DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!