[DllImport("cards.dll")]
        public static extern bool cdtInit(ref int width, ref int height);
        [DllImport("cards.dll")]
        public static extern bool cdtDraw(IntPtr hdc, int x, int y, int card, int mode, long color);
        [DllImport("cards.dll")]
        public static extern void cdtTerm();
        private void button1_Click(object sender, EventArgs e)
        {
            cdtDraw(this.CreateGraphics().GetHdc(), 20, 30, 3, 0, 3);
            cdtTerm();
        }
        private void Form3_Load(object sender, EventArgs e)
        {
            int width, height;
            width = 0; height = 0;
            cdtInit(ref width, ref height);
        }
对 PInvoke 函数“WindowsApplication1!WindowsApplication1.Form3::cdtDraw”的调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配。请各位大大指点一下吧!谢谢了

解决方案 »

  1.   

    public static extern bool cdtDraw(IntPtr hdc, int x, int y, int card, int mode, int color); 
    DWORD对应的是int(4个字节),而不是long(8个字节)。----------------------------
    随便提一下,下面代码虽然可能可以运行,但没有释放资源,多运行几次可能会出问题。
    具体参考:
    Graphics.ReleaseHdc()
    Graphics.Dispose()
      

  2.   

    是发牌的程序吗?我有个成功的案例:
    http://hi.baidu.com/sageking2/blog/item/27f9c62a9606493f5243c168.html
      

  3.   

    你的问题主要就是平台调用过程中的数据封送问题。楼上有人已经给出了正确的答案。但是如果只获得答案,不知道原理,以后遇到了此类问题还是不知道如何下手。如果你想系统学习如何进行数据封送,我推荐你阅读刚刚出版的新书:《精通.NET互操作P/Invoke,C++Interop和COM Interop》,这本书的第2章“数据封送”详细介绍了平台调用中的数据封送过程,非常详细,我就是读完后才搞清楚平台调用中的封送处理。 
    该书的官方网站: 
    www.interop123.com 豆瓣网信息: 
    http://www.douban.com/subject/3671497/ 
      

  4.   

     [DllImport("cards.dll")]
      public static extern bool cdtDraw(IntPtr hdc, int x, int y, int card, int mode, long color);
    把这个里面的long color改为int color 就行了,不妨一试,我的就这样好了,如果还有就继续把有long的地方全改为int