最近我要调一个C语言的DLL 调用时总是报错“外部组件发生异常” SEHException类型的错误C语言的.h文件里这样定义的extern "C" _declspec(dllexport) int VerifyLicense(
const char* publicKey,
const char* dat,
const char* lic);我C#里是这么写的
[DllImport("licverif.dll", EntryPoint = "VerifyLicense", CharSet = CharSet.Ansi)]
public static extern int VerifyLicense(string publicKey, string dat, string lic);dll名字我肯定没写错,否则会报“找不到指定模块”的异常我上网搜了一遍,char*这个参数对于C#来说比较麻烦,我还试过StringBuilder,char[],IntPtr,byte[]都不行,悲剧求大家帮助
const char* publicKey,
const char* dat,
const char* lic);我C#里是这么写的
[DllImport("licverif.dll", EntryPoint = "VerifyLicense", CharSet = CharSet.Ansi)]
public static extern int VerifyLicense(string publicKey, string dat, string lic);dll名字我肯定没写错,否则会报“找不到指定模块”的异常我上网搜了一遍,char*这个参数对于C#来说比较麻烦,我还试过StringBuilder,char[],IntPtr,byte[]都不行,悲剧求大家帮助
publicKey += "\0";
dat+= "\0";
lic+= "\0";
我现在无法排除 是我调用方法的问题 还是那个dll有问题谁给我来一个带char*参数的dll 我试试
我还特意做了一个string转byte[]的方法 private byte[] GetCharArray(string str)
{
byte[] array = new byte[str.Length + 1]; for (int i = 0; i < str.Length; i++)
{
array[i] = (byte)str[i];
} array[str.Length] = 0; return array;
}还是不行啊
/// <summary>
/// 添加IP,端口
/// </summary>
/// <param name="strIP"></param>
/// <param name="lPort"></param>
[DllImport("ClientSDK.dll", CharSet = CharSet.Ansi, EntryPoint = "_AddLoginAgent@8")]
public static extern void AddLoginAgent(byte[] IP, int Port);
#endregion
EntryPoint 的值由depends打开C++dll看看具体是什么,就写什么
[DllImport("licverif.dll", EntryPoint = "VerifyLicense")]
public static extern int VerifyLicense(byte[] publicKey, byte[] dat, byte[] lic);是改定义接口这里吧,我改完这个,我调用的时候也得是byte[],要不编译通不过
位于目录“C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC90.DebugCRT”你让你同事拷给你放在应用程序目录下
然后depends还是问号的 然后我把msvcr90.dll从硬盘里搜出来了 放到了我那个dll旁边 再次用depends打开没问号了
但是我程序还是报那个错