Results 1 to 3 of 3

Thread: [RESOLVED] PInvokeStackImbalance was detected ??? Can someone help please?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    121

    Resolved [RESOLVED] PInvokeStackImbalance was detected ??? Can someone help please?

    Can someone tell me why Im getting this error message?


    VB Code:
    1. using System;
    2. using System.Collections.Generic;
    3. using System.ComponentModel;
    4. using System.Data;
    5. using System.Drawing;
    6. using System.Text;
    7. using System.Windows.Forms;
    8. using System.Runtime.InteropServices;
    9.  
    10. namespace Card_Test
    11. {
    12.     public partial class Form1 : Form
    13.     {
    14.  
    15.         [DllImport("cards.dll")]
    16.         private static extern bool cdtInit(ref int width, ref int height);
    17.  
    18.         [DllImport("cards.dll")]
    19.         private static extern bool cdtDraw(IntPtr hdc,
    20.                                             int x,
    21.                                             int y,
    22.                                             int card,
    23.                                             int mode,
    24.                                             long color);
    25.  
    26.         private IntPtr hdc = new IntPtr();
    27.  
    28.  
    29.         public Form1()
    30.         {
    31.             InitializeComponent();
    32.  
    33.             int iWidth = 100;
    34.             int iHeight = 300;
    35.             if (!cdtInit(ref iWidth, ref iHeight))
    36.                 throw new Exception("cards.dll did not load");
    37.         }
    38.  
    39.         private void Form1_Load(object sender, EventArgs e)
    40.         {
    41.  
    42.         }
    43.  
    44.         private void Form1_Paint(object sender, PaintEventArgs e)
    45.         {
    46.             //base.OnPaint(e);
    47.             hdc = e.Graphics.GetHdc();
    48.             Draw();
    49.             e.Graphics.ReleaseHdc(hdc);
    50.  
    51.         }
    52.  
    53.         private void Draw()
    54.         {
    55.             cdtDraw (hdc, 35, 10, 1, 0, 0);
    56.         }
    57.  
    58.  
    59.  
    60.  
    61.     }
    62. }




    VB Code:
    1. PInvokeStackImbalance was detected
    2. Message: A call to PInvoke function 'Card Test!Card_Test.Form1::cdtDraw' has unbalanced the stack.
    3. This is likely because the managed PInvoke signature does not match the unmanaged target signature.
    4. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    121

    Re: PInvokeStackImbalance was detected ??? Can someone help please?

    i figured it out. cdtDraw does not take longs...only ints

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: PInvokeStackImbalance was detected ??? Can someone help please?

    Don't forget to resolve your thread from the Thread Tools menu.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width