作者ireullin (raison detre)
看板C_Sharp
标题[问题] 汇入c++写的dll档
时间Mon Jul 9 10:03:50 2007
请问各位我要把c++写成的dll档在c#中使用
可是一直遇到 "找不到名称为 fnLibEncrypt 的进入点 (在 DLL LibEncrypt.dll 中)"的
问题
後来我直接开一个专 c++的专案 用最简单的方式来测试可是问题还是一样
我在本站及各大网站上看到的方法都大同小异,可是我试了以後还是不行
可以麻烦各位帮我看一下嘛
//******************* LibEncrypt.h *******************
#define LIBENCRYPT_API __declspec(dllexport)
/*
#ifdef LIBENCRYPT_EXPORTS
#define LIBENCRYPT_API __declspec(dllexport)
#else
#define LIBENCRYPT_API __declspec(dllimport)
#endif
*/
// 这个类别是从 LibEncrypt.dll 汇出的
class LIBENCRYPT_API CLibEncrypt
{
public:
CLibEncrypt(void);
};
extern LIBENCRYPT_API int nLibEncrypt;
LIBENCRYPT_API int fnLibEncrypt(void);
//******************* LibEncrypt.cpp *******************
// LibEncrypt.cpp : 定义 DLL 应用程式的进入点。
#include "stdafx.h"
#include "LibEncrypt.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
// 这是汇出变数的范例
LIBENCRYPT_API int nLibEncrypt=0;
// 这是汇出函式的范例。
LIBENCRYPT_API int fnLibEncrypt(void)
{
return 42;
}
// 这是已汇出之类别的建构函式。
// 该类别的定义请参阅 LibEncrypt.h
CLibEncrypt::CLibEncrypt()
{
return;
}
//******************* C#里头的使用 *******************
[DllImport(
"LibEncrypt.dll",EntryPoint="fnLibEncrypt",CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)]
public static extern int fnLibEncrypt();
private void BtnOK_Click(object sender, System.EventArgs e)
{
int a = fnLibEncrypt();
bCheck = true;
this.Close();
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.220.110.100