CharSet=CharSet.Unicode如果是ansi的话,直接用string试试

解决方案 »

  1.   

    应该在Unicode,因为我在vs2010直接就能用,
    但我在vs2010 的C#里这样写 运行时会出现以下错误, 求修正
            [DllImport("LaserTool.dll", EntryPoint = "SAM_LoadTemplate", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
            public static extern Int32 SAM_LoadTemplate(StringBuilder str); StringBuilder sbd = new StringBuilder("C:\\demo1.sjf");
    Laser.SAM_LoadTemplate(sbd);//运行到这里就会停下来提示以下错误 但实际上这个函数已经执行(我已经盾到效果)SAM_LoadTemplate has unbalanced stack
    because the managed PInvoke signature  not match unmanagegd target signature
      

  2.   

    应该是unicode的,因为我在vs2010 的mfc直接就能用
    但我在c#里如下调用
          [DllImport("LaserTool.dll", EntryPoint = "SAM_LoadTemplate", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
            public static extern Int32 SAM_LoadTemplate(StringBuilder str);
              StringBuilder sbd = new StringBuilder("C:\\demo1.sjf");
                StringBuilder mbder2 = new StringBuilder("");
                Laser.SAM_LoadTemplate(sbd);//执行到这程序就会出错 提示签名不匹配pip
      

  3.   

    #define AFX_SAM_IMPORT extern "C" __declspec(dllimport)
    加多个说明 
      

  4.   

    stringbuilder或者string 都不行的话 ,试试intptr吧!还是不行的话就unsafe吧,直接用想通格式的指针非安全模式调试下,看看有没错。