求救:.net中调用 一般DLL文件

wwfttelne 2003-10-18 05:48:59
这个问题,很多人提出过,也有很多人解答过,可是我还是遇到了。

#include "stdafx.h"

#define out _declspec(dllexport)

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}

int out addone(int n)
{
n++;
return n;
}

int out subone(int n)
{
n--;
return n;
}
//以上是DLL文件的源代码。出于试验目的,非常简单



using System;
using System .Runtime .InteropServices ;

namespace test
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
///


[DllImport("user32.dll")]
public static extern int MessageBox(int hwnd, string message,string caption, int type);
[DllImport("dll.dll")]
public static extern int addone(int n);
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
int result = MessageBox(0, "Hello World", "PInvoke Test", 0);
addone(15);



}
}
}
//以上是.net中的原文件

using System .Runtime .InteropServices ;
这个我加了
特别奇怪的是:
int result = MessageBox(0, "Hello World", "PInvoke Test", 0);
这条命令可用
addone(15);
这个就不可用。
出错信息为:
未处理的“System.DllNotFoundException”类型的异常出现在 test.exe 中。

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

dll.dll文件我已经放在了工程根目录下./test/
而且,我又把这个文件拷贝了好几份,放在以下目录中:
./test/bin
./test/bin/debug/
./test/obj
./test/obj/debug/
天啊,我是病急乱投医啊。
我还在解决方案资源管理里面把它们一一设为包含在项目中

到底是为什么,我的DLL文件是在VC6.0里面书写和编译的。
属于完全的Win32动态链接库,没有用到MFC类库。
同时在VC6.0中完全可用。
...全文
24 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
rqxiang 2003-10-18
  • 打赏
  • 举报
回复
除了Dll文件,好像还应该有个Lib文件的引用!
o1o 2003-10-18
  • 打赏
  • 举报
回复
是没添加引用引起的吧?
就是:工具箱->自定义工具箱->找到你的“.DLL”->“确定”->将你的“.DLL”工具拖到FORM中。
vampireal 2003-10-18
  • 打赏
  • 举报
回复
不会~~刚学C#,学习来了
极限999 2003-10-18
  • 打赏
  • 举报
回复
关注

110,499

社区成员

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

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

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