//Dll.h
#ifdef BLOOMFILTER_API
#else
#define BLOOMFILTER_API extern "C" _declspec(dllimport)
#endif
#include<string>
using namespace std;
BLOOMFILTER_API int RSHash(string str, int nLen);
//Dll.cpp
/
#include "stdafx.h"
#define BLOOMFILTER_API extern "C"__declspec(dllexport)
#include "VDDll.h"
int RSHash(string str, int nLen)
{
int b = 378551;
int a = 63689;
int hash = 0;
for( int i = 0; i < nLen; i++)
{
hash = hash*a+str[i];
a = a*b;
}
return (hash & 0x7FFFFFFF);
}
//在C#中调用
class testadd
{
[DllImport("VDDLL.dll", EntryPoint = @"RSHash", CharSet = CharSet.Ansi)]
public static extern int RSHash(string str, int nLen);
}
static void Main(string[] args)
{
Console.WriteLine(testadd.RSHash("asd",3));
}
杨魅力
Helenr