有关C#调用vc生成的dll时的问题

daizf 2003-03-27 04:22:21
我在vc中定义了两个导出函数,在别的vc工程中可以使用,但是在c#中却出现下面的错误,请问如何解决,谢谢
未处理的“System.DllNotFoundException”类型的异常出现在 WindowsApplication2.exe 中

其他信息:无法加载 DLL (dlltest1.dll)。


下面是部分代码:
class dlltemp
{
[DllImport("dlltest1.dll", EntryPoint="Add", SetLastError=true,CharSet=CharSet.Ansi,CallingConvention=CallingConvention.StdCall)]
public static extern int Add(int a,int b);
[DllImport("dlltest1.DLL", EntryPoint="ShowString", SetLastError=true,CharSet=CharSet.Ansi,CallingConvention=CallingConvention.StdCall)]
public static extern void ShowString();
}

执行时如下:
InitializeComponent();
MessageBox.Show(dlltemp.Add(1,2).ToString());
dlltemp.ShowString();
...全文
49 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
herofyf 2003-04-01
  • 打赏
  • 举报
回复
关于非.net中的dll导出的有两个方面:
一是用tlbimp转换
二是将其转换过的dll文件复制到相应的\debug\bin下去
daizf 2003-04-01
  • 打赏
  • 举报
回复
c#导出的是名字空间,而vc.net里没有这个啊?怎么处理?
Knight94 2003-03-31
  • 打赏
  • 举报
回复
》请问现在用已经用C#做成了一个dll,那么怎么才能在vc.net里用呢?
直接引用就行了
daizf 2003-03-30
  • 打赏
  • 举报
回复
请问现在用已经用C#做成了一个dll,那么怎么才能在vc.net里用呢?
如果有实例的话,麻烦可不可以提供一下,谢谢!
kingzai 2003-03-28
  • 打赏
  • 举报
回复
These rules might help you call C# from C++ code (even MFC code !):

Rules
1. "#undef new" in the C++ code before the "#pragma managed"
2. Turn on the managed extensions option in the VS.NET generated
project for an MFC app
3. The C# dll MUST be in the same directory as the C++ MFC exe
consult
http://msdn.microsoft.com/msdnmag/issues/01/07/vsnet/default.aspx

fkfhhfh 2003-03-28
  • 打赏
  • 举报
回复
你的com客户机程序为不可管理代码(即VC++,VB6等),则需要regasm.exe 工具来注册。
其后和普通的组件一样使用。
daizf 2003-03-28
  • 打赏
  • 举报
回复
搞定,谢谢!!再问一个问题,怎么用vc使用c#编写的dll文件,如何关联?谢谢指导一下。
qingren 2003-03-27
  • 打赏
  • 举报
回复
把dlltest1.dll copy到应用目录\bin\debug\
或者先注册一下

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧