被调dll函数
ykt_readopencardno_local(char * pRegion, char * pDeptid, char * pDeptKey, char * pCardtype, char * pCardno, char * pWarnmsg, char * pErrmsg);C#调用代码:
[DllImport("kernel32.dll")]
private extern static IntPtr LoadLibrary(String path);
[DllImport("kernel32.dll")]
private extern static IntPtr GetProcAddress(IntPtr lib, String funcName);
[DllImport("kernel32.dll")]
private extern static bool FreeLibrary(IntPtr lib); public static IntPtr hLib; public Integrated(String DLLPath)
{ hLib = LoadLibrary(DLLPath);
} //将要执行的函数转换为委托
public Delegate Invoke(String APIName, Type t)
{
IntPtr api = GetProcAddress(hLib, APIName);
return (Delegate)Marshal.GetDelegateForFunctionPointer(api, t);
}
public delegate int ykt_readopencardno_local(byte[] pRegion, byte[] pDeptid, byte[] pDeptKey, ref char pCardtype, ref StringBuilder pCardno, ref long pWarnmsg, ref long pErrmsg);//编译 问题:输出参数pCardno用StringBuilder类型报错:试图读取或写入受保护内存,这通常是指示其他内存已损坏!
求高手指点。
ykt_readopencardno_local(char * pRegion, char * pDeptid, char * pDeptKey, char * pCardtype, char * pCardno, char * pWarnmsg, char * pErrmsg);C#调用代码:
[DllImport("kernel32.dll")]
private extern static IntPtr LoadLibrary(String path);
[DllImport("kernel32.dll")]
private extern static IntPtr GetProcAddress(IntPtr lib, String funcName);
[DllImport("kernel32.dll")]
private extern static bool FreeLibrary(IntPtr lib); public static IntPtr hLib; public Integrated(String DLLPath)
{ hLib = LoadLibrary(DLLPath);
} //将要执行的函数转换为委托
public Delegate Invoke(String APIName, Type t)
{
IntPtr api = GetProcAddress(hLib, APIName);
return (Delegate)Marshal.GetDelegateForFunctionPointer(api, t);
}
public delegate int ykt_readopencardno_local(byte[] pRegion, byte[] pDeptid, byte[] pDeptKey, ref char pCardtype, ref StringBuilder pCardno, ref long pWarnmsg, ref long pErrmsg);//编译 问题:输出参数pCardno用StringBuilder类型报错:试图读取或写入受保护内存,这通常是指示其他内存已损坏!
求高手指点。
解决方案 »
- C#调用dll里的方法问题?
- 急急!类的部分方法只能排队使用(调用者有多线程,单个此类对象)
- C#问问
- Remoting中的远程类是否必须要有默认无参构造函数?
- mdi主窗体的背景怎么设置啊,要随窗体变化填充满窗体
- 帮我解决下简单的提取字符串问题
- 如何用c#获取 服务器IP下面所有网站的网址?
- 请问如何用DataGrid显示不同颜色的记录?
- 错误:VC软件包不可用或未注册
- 还是关于socket 方面的问题,希望高手们帮忙,你回答,就给分!!
- 关于从数据库取图片二进制图片在网页上总是要刷新几次才出来怎么回事
- =========ComboBox实现类似于IE地址栏的问题,但是要跟Value绑定==========
-----------------------------------------------c++ c#
char * ====>string
我这样报错 public delegate int ykt_readopencardno_local(byte[] pRegion, byte[] pDeptid, byte[] pDeptKey, ref char pCardtype, ref [MarshalAs(UnmanagedType.LPStr)]string pCardno, ref long pWarnmsg, ref long pErrmsg);
就一个API函数而已,直接这样使用:DllImport("sqlite3.dll", EntryPoint = "ykt_readopencardno_local", CallingConvention = CallingConvention.Cdecl)]
public static extern int ykt_readopencardno_local(string pRegion, string pDeptid, string pDeptKey, string pCardtype, string pCardno, string pWarnmsg,string pErrmsg);
1、路径不正确,你可以先用绝对路径使用!
2、缺少依赖的dll,用VC6的DEPENDS.EXE工具查看,
把所有依赖的(非系统)的dll,拷贝到相同的目录下!
{
discarded = 0;
string newString = "";
char c;
// remove all none A-F, 0-9, characters
for (int i=0; i<hexString.Length; i++)
{
c = hexString[i];
if (IsHexDigit(c))
newString += c;
else
discarded++;
}
// if odd number of characters, discard last character
if (newString.Length % 2 != 0)
{
discarded++;
newString = newString.Substring(0, newString.Length-1);
} int byteLength = newString.Length / 2;
byte[] bytes = new byte[byteLength];
string hex;
int j = 0;
for (int i=0; i<bytes.Length; i++)
{
hex = new String(new Char[] {newString[j], newString[j+1]});
bytes[i] = HexToByte(hex);
j = j+2;
}
return bytes;
}