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#中应该转换成什么类型啊。

解决方案 »

  1.   

    看看这个,你肯定会了http://wenku.baidu.com/view/5126f84b2b160b4e767fcf85.html?st=1
    char数组对应到C#中应该用byte数组,或者string 类型来实现,因为c++中char是一个字节8位,c#中只有byte是一个字节8位与他对应。
      

  2.   

    最可靠的用byte[]
    然后再转换string
      

  3.   

    char[] array1 = { 's', 'a', 'm' };
    char[] array2 = new char[] { 's', 'a', 'm' };
    char[] array3 = new char[3];
    array3[0] = 's';
    array3[1] = 'a';
    array3[2] = 'm';
      

  4.   

     byte[] str = new byte[1024];
                    str = System.Text.Encoding.ASCII.GetBytes("identity_type:2,op_branch_no: ,df=4");还是不行。
      

  5.   

    如果是要翻译代码,不用这样,这么多行,一句话就能完事,如果一定要模拟
    byte[] bytes = new byte[1024];
    string str = "identity_type:2,op_branch_no: ,df=4";
    Encoding.ASCII.GetBytes(str, 0, str.Length, bytes, 0);
      

  6.   

    byte  传进去 还是提示 错误
      

  7.   

     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];                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)
                {            }
            }
      

  8.   

    c#代码 
    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)
      {  }
      }
      

  9.   

    c++ 代码
    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);
      

  10.   

    这样编译都通不过吧
    // 函数声明
    [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);
      

  11.   

    // 定义
    [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);
      

  12.   

    还是一样的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.谢谢你啊
      

  13.   

    这是一个 C++ 类里的函数吧,函数原型是怎样的,函数声明改下试试
    [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);
      

  14.   

    函数原型:
    int CITICSSTDCALL CITICs_HsHlp_BizCallAndCommit(HSHLPHANDLE HlpHandle, int iFuncID, const char* szParam=NULL, int nBizCallType=BIZCALL_SYNC, LPMSG_CTRL lpMsgCtrl=NULL);
      

  15.   

    你加上 @20 干什么,CITICSSTDCALL 这个宏是什么,HSHLPHANDLE 这又是什么类型
      

  16.   

            [DllImport("MasterRD.dll")]
            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)
      

  17.   

    暂且可以这样试试
    [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);
      

  18.   

    楼上,EntryPoint 不能随便更换,如果那个错了,就直接提示找不到入口点了,而不是那个参数错误的提示,既然是参数错误,多半是参数个数问题啦(猜测)。
    至于为啥看起来那么奇怪,应该是它没用C格式导出造成的吧,那个EntryPoint 最终可以用一个工具查出来的。
      

  19.   

    CITICs_HsHlp_BizCallAndCommit(Intptr HlpHandle,int iFunc, byte [] szParam);使用时
    Byte[] data=new BYTE[1024];CITICs_HsHlp_BizCallAndCommit(HlpHandle,iFunc, byte [] szParam);
    这样就可以了。
      

  20.   

    c++里的char[]使用byte[]谅可以。
    但你要确定你的dll是标准的。
      

  21.   

    String szParam1 = "identity_type:2,op_branch_no: ,op_entrust_way:5,op_station:10.62.1.75 8C89A52116E7,input_content:1";
                    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.