[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 签名的调用约定和参数与非托管的目标签名是否匹配。请各位大大指点一下吧!谢谢了
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 签名的调用约定和参数与非托管的目标签名是否匹配。请各位大大指点一下吧!谢谢了
DWORD对应的是int(4个字节),而不是long(8个字节)。----------------------------
随便提一下,下面代码虽然可能可以运行,但没有释放资源,多运行几次可能会出问题。
具体参考:
Graphics.ReleaseHdc()
Graphics.Dispose()
http://hi.baidu.com/sageking2/blog/item/27f9c62a9606493f5243c168.html
该书的官方网站:
www.interop123.com 豆瓣网信息:
http://www.douban.com/subject/3671497/
public static extern bool cdtDraw(IntPtr hdc, int x, int y, int card, int mode, long color);
把这个里面的long color改为int color 就行了,不妨一试,我的就这样好了,如果还有就继续把有long的地方全改为int