By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,236 Members | 1,848 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,236 IT Pros & Developers. It's quick & easy.

A Call to pinvoke function

P: n/a
Hi
i am using User32.dll in Visual stdio 2005.

[System.Runtime.InteropServices.DllImport("user32.d ll",EntryPoint =
"SetActiveWindow")]

public static extern long SetActiveWindow(long hwnd);

[System.Runtime.InteropServices.DllImport("user32.d ll", EntryPoint =
"keybd_event")]

public static extern long keybd_event(byte bVk, byte bScan, long dwFlags,
long dwExtraInfo);
it produces this error

A call to PInvoke function 'TSIPOS!TSIPOS.UserContols.KeyBoard::keybd_event'
has unbalanced the stack. 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.
it works well in Vs.net 2003
please tell me how can i use win32 api in Visual studio 2005.
thanks & regards
Rahul jain
Mar 31 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Fri, 31 Mar 2006 13:38:29 -0800, msnews.microsoft.com wrote:

[System.Runtime.InteropServices.DllImport("user32.d ll", EntryPoint =
"keybd_event")]
public static extern long keybd_event(byte bVk, byte bScan, long dwFlags,
long dwExtraInfo); A call to PInvoke function 'TSIPOS!TSIPOS.UserContols.KeyBoard::keybd_event'
has unbalanced the stack. 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.
it works well in Vs.net 2003
please tell me how can i use win32 api in Visual studio 2005.


At first sight
- you do not need to specify the entry point if you are keeping the same
function name
- keybd_event returns void not long
- the third parameter should be a DWORD, which is an unsigned long in
umanaged C++ which corresponds to uint in .NET, not to a long. Don't forget
that a long in .NET is a 64-bit integer while it's a 32-bit integer in
unmanaged C++
- the last parameter is a unsigned LONG_PTR. I'm not too sure how this
translates in .NET but i would use either an IntPtr or a uint but not a
long.
Mar 31 '06 #2

P: n/a
And the return of SetActiveWindow should be an IntPtr just like it's HWND
argument.
Note that version 2 of the CLR checks (and corrects at run-time where
possible) this kind of broken signatures and warns you about the fact when
running in the debugger, this is not done in V1, that's why you didn't get
this error when running in VS2003.

Willy.
"Mehdi" <vi****@REMOVEME.gmail.com> wrote in message
news:1m*****************************@40tude.net...
| On Fri, 31 Mar 2006 13:38:29 -0800, msnews.microsoft.com wrote:
|
|
| > [System.Runtime.InteropServices.DllImport("user32.d ll", EntryPoint =
| > "keybd_event")]
| > public static extern long keybd_event(byte bVk, byte bScan, long
dwFlags,
| > long dwExtraInfo);
|
| > A call to PInvoke function
'TSIPOS!TSIPOS.UserContols.KeyBoard::keybd_event'
| > has unbalanced the stack. 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.
| > it works well in Vs.net 2003
| > please tell me how can i use win32 api in Visual studio 2005.
|
| At first sight
| - you do not need to specify the entry point if you are keeping the same
| function name
| - keybd_event returns void not long
| - the third parameter should be a DWORD, which is an unsigned long in
| umanaged C++ which corresponds to uint in .NET, not to a long. Don't
forget
| that a long in .NET is a 64-bit integer while it's a 32-bit integer in
| unmanaged C++
| - the last parameter is a unsigned LONG_PTR. I'm not too sure how this
| translates in .NET but i would use either an IntPtr or a uint but not a
| long.
Mar 31 '06 #3

P: n/a
Hi Mehdi & willy

Thanks for reply.

I have made the changes but couldn't fine solution.

I am developing a onscreen keyboard where I found that problem.i am sending
you my whole code.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Drawing;

using System.Data;

using System.Text;

using System.Windows.Forms;

using System.IO;

using System.Diagnostics;

using System.Runtime.InteropServices;

using System.Runtime.InteropServices.ComTypes;

namespace TSIPOS.UserContols

{

public partial class KeyBoard : UserControl

{

public KeyBoard()

{

InitializeComponent();

}

#region API Function

// [DllImport("user32.dll", EntryPoint = "GetActiveWindow")]

// public static extern long GetActiveWindow();

[System.Runtime.InteropServices.DllImport("user32.d ll")]

public static extern long SetActiveWindow(long hwnd);

[System.Runtime.InteropServices.DllImport("user32.d ll", EntryPoint =
"keybd_event")]

public static extern long keybd_event(byte bVk, byte bScan, long dwFlags,
long dwExtraInfo);

[System.Runtime.InteropServices.DllImport("winmm.dl l", EntryPoint =
"mciSendStringA")]

static extern int mciSendString(string lpstrCommand, string
lpstrReturnString, int uReturnLength, int hwndCallback);
#endregion
#region "constraints"

const int KEYEVENTF_KEYUP = 2;

// Release key

const int VK_LBUTTON = 1;

// Left mouse button.

const int VK_RBUTTON = 2;

// Right mouse button.

const int VK_CANCEL = 3;

// Used for control-break processing.

const int VK_MBUTTON = 4;

// ''Middle mouse button (3-button mouse).

const int VK_BACK = 8;

const int VK_TAB = 9;

const int VK_CLEAR = 12;

const int VK_PRINT = 42;

const int VK_RETURN = 13;

// enter

const int VK_SHIFT = 16;

const int VK_CONTROL = 17;

const int VK_SCROLL = 145;

const int VK_MENU = 18;

// Alt (either one)

const int VK_PAUSE = 19;

const int VK_CAPITAL = 20;

const int VK_ESCAPE = 27;

const int VK_STARTKEY = 91;

// Start Menu key

const int VK_SPACE = 32;

const int VK_PRIOR = 33;

// Page up.

const int VK_NEXT = 34;

// Page down.

const int VK_END = 35;

const int VK_HOME = 36;

const int VK_LEFT = 37;

const int VK_UP = 38;

const int VK_RIGHT = 39;

const int VK_DOWN = 40;

const int VK_SELECT = 41;

const int VK_INSERT = 45;

const int VK_DELETE = 46;

const int VK_HELP = 47;

const int VK_OEM_COMMA = 188;

// , comma

const int VK_NUMLOCK = 144;

// Num Lock

const int KEYEVENTF_EXTENDEDKEY = 1;

const int VK_0 = 48;

const int VK_1 = 49;

const int VK_2 = 50;

const int VK_3 = 51;

const int VK_4 = 52;

const int VK_5 = 53;

const int VK_6 = 54;

const int VK_7 = 55;

const int VK_8 = 56;

const int VK_9 = 57;

const int VK_A = 65;

const int VK_B = 66;

const int VK_C = 67;

const int VK_D = 68;

const int VK_E = 69;

const int VK_F = 70;

//const int VK_G1 = 63;

const int VK_G = 71;

const int VK_H = 72;

const int VK_I = 73;

const int VK_J = 74;

const int VK_K = 75;

const int VK_L = 76;

const int VK_M = 77;

const int VK_N = 78;

const int VK_O = 79;

const int VK_P = 80;

const int VK_Q = 81;

const int VK_R = 82;

const int VK_S = 83;

const int VK_T = 84;

const int VK_U = 85;

const int VK_V = 86;

const int VK_W = 87;

const int VK_X = 88;

const int VK_Y = 89;

const int VK_Z = 90;

//const int VK_slbrace = 93;

//const int VK_srbrace = 93;

const int VK_NUMPAD0 = 96;

const int VK_NUMPAD1 = 97;

const int VK_NUMPAD2 = 98;

const int VK_NUMPAD3 = 99;

const int VK_NUMPAD4 = 100;

const int VK_NUMPAD5 = 101;

const int VK_NUMPAD6 = 102;

const int VK_NUMPAD7 = 103;

const int VK_NUMPAD8 = 104;

const int VK_NUMPAD9 = 105;

const int VK_MULTIPLY = 106;

// * (keypad)

const int VK_ADD = 107;

const int VK_SEPARATER = 108;

const int VK_SEPARATOR = 108;

const int VK_SUBTRACT = 109;

const int VK_DECIMAL = 110;

const int VK_DIVIDE = 111;

const int VK_OEM_2 = 191;

// /

const int VK_OEM_PERIOD = 190;

// .

const int VK_F1 = 112;

const int VK_F2 = 113;

const int VK_F3 = 114;

const int VK_F4 = 115;

const int VK_F5 = 116;

const int VK_F6 = 117;

const int VK_F7 = 118;

const int VK_F8 = 119;

const int VK_F9 = 120;

const int VK_F10 = 121;

const int VK_F11 = 122;

const int VK_F12 = 123;

const int VK_F13 = 124;

const int VK_F14 = 125;

const int VK_F15 = 126;

const int VK_F16 = 127;

const int VK_F17 = 128;

const int VK_F18 = 129;

const int VK_F19 = 130;

const int VK_F20 = 131;

const int VK_F21 = 132;

const int VK_F22 = 133;

const int VK_F23 = 134;

const int VK_F24 = 135;

// ****************

const int VK_CRSEL = 247;

const int VK_EREOF = 249;

const int VK_EXECUTE = 43;

const int VK_EXSEL = 248;

const int VK_NONAME = 252;

const int VK_OEM_CLEAR = 254;

const int VK_PA1 = 253;

const int VK_PROCESSKEY = 229;

const int CAPSLOCK_ON = 128;

// the capslock light is on.

// ****************

bool lockbool;

bool onoff;

bool ctrlbool;

bool numlockbool;

#endregion

#region "which button pushed function"
public string whichbuttonpushed(string _sender)

{

string warning = "";

try

{

SetActiveWindow(8975933078237479570);
// Set focus Active window

// I found this number("8975933078237479570") via getactivewindow method.

switch (_sender)

{

case "BtnA":

keybd_event(VK_A, 0, 0, 0);
keybd_event(VK_A, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnB":

keybd_event(VK_B, 0, 0, 0);

keybd_event(VK_B, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnC":

keybd_event(VK_C, 0, 0, 0);

keybd_event(VK_C, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

//case "Btn_c":

// keybd_event(VK_C, 0, 0, 0);

// keybd_event(VK_C, 0, KEYEVENTF_KEYUP, 0);

// shiftrelease();

// altrelease();

// leftaltrelease();

// break;

case "BtnD":

keybd_event(VK_D, 0, 0, 0);

keybd_event(VK_D, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnE":

keybd_event(VK_E, 0, 0, 0);

keybd_event(VK_E, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnF":

keybd_event(VK_F, 0, 0, 0);

keybd_event(VK_F, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnG":

keybd_event(VK_G, 0, 0, 0);

keybd_event(VK_G, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

//case "Btn_g":

// keybd_event(VK_A, 0, 0, 0);

// keybd_event(VK_A, 0, KEYEVENTF_KEYUP, 0);

// shiftrelease();

// altrelease();

// leftaltrelease();

// break;

case "BtnH":

keybd_event(VK_H, 0, 0, 0);

keybd_event(VK_H, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

//case "Btn_i":

// keybd_event(VK_I, 0, 0, 0);

// keybd_event(VK_I, 0, KEYEVENTF_KEYUP, 0);

// shiftrelease();

// altrelease();

// leftaltrelease();

// break;

case "BtnI":

keybd_event(VK_I, 0, 0, 0);

keybd_event(VK_I, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnJ":

keybd_event(VK_J, 0, 0, 0);

keybd_event(VK_J, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnK":

keybd_event(VK_K, 0, 0, 0);

keybd_event(VK_K, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnL":

keybd_event(VK_L, 0, 0, 0);

keybd_event(VK_L, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnM":

keybd_event(VK_M, 0, 0, 0);

keybd_event(VK_M, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnN":

keybd_event(VK_N, 0, 0, 0);

keybd_event(VK_N, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnO":

keybd_event(VK_O, 0, 0, 0);

keybd_event(VK_O, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

//case "Btn_o":

// keybd_event(VK_O, 0, 0, 0);

// keybd_event(VK_O, 0, KEYEVENTF_KEYUP, 0);

// shiftrelease();

// altrelease();

// leftaltrelease();

// break;

case "BtnP":

keybd_event(VK_P, 0, 0, 0);

keybd_event(VK_P, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnR":

keybd_event(VK_R, 0, 0, 0);

keybd_event(VK_R, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnS":

keybd_event(VK_S, 0, 0, 0);

keybd_event(VK_S, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

//case "Btn_s":

// keybd_event(VK_S, 0, 0, 0);

// keybd_event(VK_S, 0, KEYEVENTF_KEYUP, 0);

// shiftrelease();

// altrelease();

// leftaltrelease();

// break;

case "BtnT":

keybd_event(VK_T, 0, 0, 0);

keybd_event(VK_T, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnU":

keybd_event(VK_U, 0, 0, 0);

keybd_event(VK_U, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

//case "Btn_u":

// keybd_event(VK_U, 0, 0, 0);

// keybd_event(VK_U, 0, KEYEVENTF_KEYUP, 0);

// shiftrelease();

// altrelease();

// leftaltrelease();

// break;

case "BtnV":

keybd_event(VK_V, 0, 0, 0);

keybd_event(VK_V, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnY":

keybd_event(VK_Y, 0, 0, 0);

keybd_event(VK_Y, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnZ":

keybd_event(VK_Z, 0, 0, 0);

keybd_event(VK_Z, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnW":

keybd_event(VK_W, 0, 0, 0);

keybd_event(VK_W, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnQ":

keybd_event(VK_Q, 0, 0, 0);

keybd_event(VK_Q, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnX":

keybd_event(VK_X, 0, 0, 0);

keybd_event(VK_X, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

//

************************************************** **************************

***********

break;

case "BtnPeriod":

keybd_event(VK_OEM_PERIOD, 0, 0, 0);

keybd_event(VK_OEM_PERIOD, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "Btntilt":

keybd_event(VK_ESCAPE, 0, 0, 0);

keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;
case "BtnTab":

keybd_event(VK_TAB, 0, 0, 0);

keybd_event(VK_TAB, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnCapsLock":

lockbool = !lockbool;

keybd_event(VK_CAPITAL, 69, (KEYEVENTF_EXTENDEDKEY | 0), 0);

keybd_event(VK_CAPITAL, 69, (KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP), 0);

if ((lockbool == true))

{

BtnCapsLock.BackColor = Color.White;

}

else

{

BtnCapsLock.BackColor = Color.FromArgb(224, 224, 224);

}

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnShift":

keybd_event(VK_SHIFT, 0, 0, 0);

BtnShift.BackColor = Color.White;

//Btnsagshift.BackColor = Color.White;

altrelease();

leftaltrelease();

break;

case "BtnCtrl":

ctrlbool = !ctrlbool;

if ((ctrlbool == true))

{

keybd_event(VK_CONTROL, 0, 0, 0);

BtnCtrl.BackColor = Color.White;

//Btnsagctrl.BackColor = Color.White;

}

else

{

keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);

BtnCtrl.BackColor = Color.FromArgb(224, 224, 224);

//Btnsagctrl.BackColor = Color.FromArgb(224, 224, 224);

}

shiftrelease();

altrelease();

leftaltrelease();

break;
case "BtnAlt":

keybd_event(VK_MENU, 0, 0, 0);

BtnAlt.BackColor = Color.White;

shiftrelease();

altrelease();

break;

case "BtnSpaceBar":

keybd_event(VK_SPACE, 0, 0, 0);

keybd_event(VK_SPACE, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;
case "BtnEnter":

keybd_event(VK_RETURN, 0, 0, 0);

keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnComa":

keybd_event(VK_OEM_COMMA, 0, 0, 0);

keybd_event(VK_OEM_COMMA, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;
case "BtnDel":

keybd_event(VK_DELETE, 0, 0, 0);

keybd_event(VK_DELETE, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;
case "BtnUpArrow":

keybd_event(VK_UP, 0, 0, 0);

keybd_event(VK_UP, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnDownArrow":

keybd_event(VK_DOWN, 0, 0, 0);

keybd_event(VK_DOWN, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnLeft":

keybd_event(VK_LEFT, 0, 0, 0);

keybd_event(VK_LEFT, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnRight":

keybd_event(VK_RIGHT, 0, 0, 0);

keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

//

////////////////////////////////////////////////////////////////////////////

//////

break;
case "Btn0":

keybd_event(VK_0, 0, 0, 0);

keybd_event(VK_0, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "Btn1":

keybd_event(VK_1, 0, 0, 0);

keybd_event(VK_1, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "Btn2":

keybd_event(VK_2, 0, 0, 0);

keybd_event(VK_2, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "Btn3":

keybd_event(VK_3, 0, 0, 0);

keybd_event(VK_3, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "Btn4":

keybd_event(VK_4, 0, 0, 0);

keybd_event(VK_4, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "Btn5":

keybd_event(VK_5, 0, 0, 0);

keybd_event(VK_5, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "Btn6":

keybd_event(VK_6, 0, 0, 0);

keybd_event(VK_6, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "Btn7":

keybd_event(VK_7, 0, 0, 0);

keybd_event(VK_7, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "Btn8":

keybd_event(VK_8, 0, 0, 0);

keybd_event(VK_8, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "Btn9":

keybd_event(VK_9, 0, 0, 0);

keybd_event(VK_9, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnPlus":

keybd_event(VK_ADD, 0, 0, 0);

keybd_event(VK_MULTIPLY, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

case "BtnMinus":

keybd_event(VK_SUBTRACT, 0, 0, 0);

keybd_event(VK_SUBTRACT, 0, KEYEVENTF_KEYUP, 0);

shiftrelease();

altrelease();

leftaltrelease();

break;

}

// TODO: Exit Function: Warning!!! Need to return the value

return warning;

}

catch (Exception ex)

{

// TODO: Exit Function: Warning!!! Need to return the value

return warning;

}

}

#endregion

#region "buttons click"

//[DllImport("user32.dll", EntryPoint = "SetActiveWindow")]

//public static extern long SetActiveWindow(long hwnd);

//[DllImport("user32.dll", EntryPoint = "keybd_event")]

//public static extern long keybd_event(byte bVk, byte bScan, long dwFlags,
long dwExtraInfo);

private void Btntilt_Click(object sender, EventArgs e)

{

try

{

Button key = ((Button)(sender));

whichbuttonpushed(key.Name);

SetActiveWindow(8975933078237479570);
// This Line Very Impportant

}

catch (Exception ex)

{

MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK,
MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);

return;

}

finally

{

SetActiveWindow(8975933078237479570);

}

}

#endregion

#region "shift ,altgr and alt release sub"

void shiftrelease()

{

BtnShift.BackColor = Color.FromArgb(224, 224, 224);

//Btnsagshift.BackColor = Color.FromArgb(224, 224, 224);

keybd_event(VK_SHIFT, 0, 2, 0);

}

void altrelease()

{

keybd_event(VK_MENU, 0, (KEYEVENTF_EXTENDEDKEY | 2), 0);

BtnAlt.BackColor = Color.FromArgb(224, 224, 224);

}

void leftaltrelease()

{

keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);

BtnAlt.BackColor = Color.FromArgb(224, 224, 224);

}

#endregion

private void nodi_DoubleClick(object sender, EventArgs e)

{

this.Show();

nodi.Visible = false;

nodi.Text = "Screen Keyboard still runing here!";

}

private void KeyBoard_Load(object sender, EventArgs e)

{

//string a = Convert.ToString(GetActiveWindow());

//MessageBox.Show(a);
nodi.Visible = false;

}

private void button1_Click(object sender, EventArgs e)

{

}



}

}

Thanks & regards
rahul

"Mehdi" <vi****@REMOVEME.gmail.com> wrote in message
news:1m*****************************@40tude.net...
On Fri, 31 Mar 2006 13:38:29 -0800, msnews.microsoft.com wrote:

[System.Runtime.InteropServices.DllImport("user32.d ll", EntryPoint =
"keybd_event")]
public static extern long keybd_event(byte bVk, byte bScan, long dwFlags,
long dwExtraInfo);

A call to PInvoke function
'TSIPOS!TSIPOS.UserContols.KeyBoard::keybd_event'
has unbalanced the stack. 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.
it works well in Vs.net 2003
please tell me how can i use win32 api in Visual studio 2005.


At first sight
- you do not need to specify the entry point if you are keeping the same
function name
- keybd_event returns void not long
- the third parameter should be a DWORD, which is an unsigned long in
umanaged C++ which corresponds to uint in .NET, not to a long. Don't
forget
that a long in .NET is a 64-bit integer while it's a 32-bit integer in
unmanaged C++
- the last parameter is a unsigned LONG_PTR. I'm not too sure how this
translates in .NET but i would use either an IntPtr or a uint but not a
long.

Mar 31 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.