求救:.net中调用 一般DLL文件
这个问题,很多人提出过,也有很多人解答过,可是我还是遇到了。
#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中完全可用。