c++ 代码:
char szParam[1024];
char szPwd[32];
char client_id[32];
char fund_account[32];
char user_token[64];
char branch_no[8];
char asset_prop[4];
char sysnode_id[4];
strcpy(szPwd, "22");
strcpy(fund_account, "11");
iFunc = 331100;
strcat(szParam, "password:");
strcat(szParam, szPwd);
printf(szParam);
szParam 这个参数在c#中应该转换成什么类型啊。
char szParam[1024];
char szPwd[32];
char client_id[32];
char fund_account[32];
char user_token[64];
char branch_no[8];
char asset_prop[4];
char sysnode_id[4];
strcpy(szPwd, "22");
strcpy(fund_account, "11");
iFunc = 331100;
strcat(szParam, "password:");
strcat(szParam, szPwd);
printf(szParam);
szParam 这个参数在c#中应该转换成什么类型啊。
解决方案 »
- 怎样让表单提交不刷新?刷新页面不重复提交?
- 安装VS2010失败
- 多线程读取Array问题
- 请教一个关于字节数据的问题!
- C# SendMessage 或 PostMessage 怎麽發送一個鍵啊,如F1键 谁能以 windows的 計算器为例 给一个提示啊.只要成功就行
- 请教一个关于会员卡机器与应用程序结合的问题
- 用DLLImport和Reference导入一个dll到工程里有什么不同吗?
- 多维数据的遍历方法求问。。
- 非常菜的问题,怎么判断一个窗体变量所指向的窗体还没有关闭?
- 请教C# datagridview 添加数据后刷新问题
- 【学习】控制台程序模拟计算器功能,希望通过代码大家能指导我进步。
- chart报表柱状图,怎么设置成2D显示的,每根柱子上还有相对的值?
char数组对应到C#中应该用byte数组,或者string 类型来实现,因为c++中char是一个字节8位,c#中只有byte是一个字节8位与他对应。
然后再转换string
char[] array2 = new char[] { 's', 'a', 'm' };
char[] array3 = new char[3];
array3[0] = 's';
array3[1] = 'a';
array3[2] = 'm';
str = System.Text.Encoding.ASCII.GetBytes("identity_type:2,op_branch_no: ,df=4");还是不行。
byte[] bytes = new byte[1024];
string str = "identity_type:2,op_branch_no: ,df=4";
Encoding.ASCII.GetBytes(str, 0, str.Length, bytes, 0);
{
[DllImport("CITICs_HsT2Hlp.dll", EntryPoint = "_CITICs_HsHlp_BizCallAndCommit@20")]
public static extern int CITICs_HsHlp_BizCallAndCommit(IntPtr hlpHandle, int iFunc, byte szParam);
}
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
LoadConfig();
}
public void LoadConfig()
{ try
{
IntPtr hconfig = new IntPtr();
IntPtr hlpHandle = new IntPtr();
byte[] szParam = new byte[1024]; Encoding.ASCII.GetBytes(str, 0, str.Length, szParam, 0); string str = "identity_type:2,op_branch_no: ,op_entrust_way:5,";
int rst = CITICs.CITICs_HsHlp_BizCallAndCommit(hlpHandle, iFunc, szParam);
int dss = rst;
}
catch (Exception ex)
{ }
}
class CITICs
{
[DllImport("CITICs_HsT2Hlp.dll", EntryPoint = "_CITICs_HsHlp_BizCallAndCommit@20")]
public static extern int CITICs_HsHlp_BizCallAndCommit(IntPtr hlpHandle, int iFunc, byte szParam);
}
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
LoadConfig();
}
public void LoadConfig()
{ try
{
IntPtr hconfig = new IntPtr();
IntPtr hlpHandle = new IntPtr();
byte[] szParam = new byte[1024]; string str = "identity_type:2,op_branch_no: ,op_entrust_way:5,";
Encoding.ASCII.GetBytes(str, 0, str.Length, szParam, 0);
int iFunc=33301;
int rst = CITICs.CITICs_HsHlp_BizCallAndCommit(hlpHandle, iFunc, szParam);
int dss = rst;
}
catch (Exception ex)
{ }
}
int iFunc;
char szParam[1024];
char sz[32];
char client_id[32];
char fund[32];
char user_token[64];
char branch_no[8];
char asset_prop[4];
char sysnode_id[4];
strcpy(sz, "33");
strcpy(fund, "33");
iFunc = 331100;
sprintf(szParam, "identity_type:2,op_branch_no: ,op_entrust_way:5,op_station:10.62.1.75 8C89A52116E7,input_content:1,account_content:200246900,password_type:2,");
strcat(szParam, "sz:");
strcat(szParam, sz);
printf(szParam);
CITICs_HsHlp_BizCallAndCommit(HlpHandle, iFunc, szParam);
// 函数声明
[DllImport("CITICs_HsT2Hlp.dll", EntryPoint = "_CITICs_HsHlp_BizCallAndCommit@20")]
public static extern int CITICs_HsHlp_BizCallAndCommit(IntPtr hlpHandle, int iFunc, byte[] szParam);// 调用
IntPtr hconfig = new IntPtr();
IntPtr hlpHandle = new IntPtr();
byte[] szParam = new byte[1024];
string str = "identity_type:2,op_branch_no: ,op_entrust_way:5,";
Encoding.ASCII.GetBytes(str, 0, str.Length, szParam, 0);
int rst = CITICs.CITICs_HsHlp_BizCallAndCommit(hlpHandle, iFunc, szParam);
[DllImport("CITICs_HsT2Hlp.dll", EntryPoint = "_CITICs_HsHlp_BizCallAndCommit@20", CharSet = CharSet.Ansi)]
public static extern int CITICs_HsHlp_BizCallAndCommit(IntPtr hlpHandle, int iFunc, string szParam);// 调用
string szParam = "identity_type:2,op_branch_no: ,op_entrust_way:5,op_station:10.62.1.75 8C89A52116E7,input_content:1,account_content:200246900,password_type:2,sz:33";
int rst = CITICs.CITICs_HsHlp_BizCallAndCommit(hlpHandle, 331100, szParam);
[DllImport("CITICs_HsT2Hlp.dll", EntryPoint = "_CITICs_HsHlp_BizCallAndCommit@20", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.ThisCall)]
public static extern int CITICs_HsHlp_BizCallAndCommit(IntPtr hlpHandle, int iFunc, string szParam);
int CITICSSTDCALL CITICs_HsHlp_BizCallAndCommit(HSHLPHANDLE HlpHandle, int iFuncID, const char* szParam=NULL, int nBizCallType=BIZCALL_SYNC, LPMSG_CTRL lpMsgCtrl=NULL);
static extern int rf_M1_write(short icdev, byte adr, IntPtr pData);对比int WINAPI rf_M1_write (unsigned short icdev,
unsigned char block,
unsigned char *pData)
[DllImport("CITICs_HsT2Hlp.dll", EntryPoint = "CITICs_HsHlp_BizCallAndCommit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern int CITICs_HsHlp_BizCallAndCommit(IntPtr HlpHandle, int iFuncID, string szParam);
至于为啥看起来那么奇怪,应该是它没用C格式导出造成的吧,那个EntryPoint 最终可以用一个工具查出来的。
Byte[] data=new BYTE[1024];CITICs_HsHlp_BizCallAndCommit(HlpHandle,iFunc, byte [] szParam);
这样就可以了。
但你要确定你的dll是标准的。
byte[] szParams = System.Text.Encoding.ASCII.GetBytes(szParam1);
rst = CITICs.CITICs_HsHlp_BizCallAndCommit(hlpHandle, iFunc, szParams);ERROR:
This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.