Click here to Skip to main content
15,937,429 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have used this code before, however it does not work in VS2010 Express.
It compiles, but then on call, it gives a stack error:
{A call to PInvoke function 'WindowsApplication1!WindowsApplication1.Form1::OpenIcon' 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 crashes on openicon and setforegroundwindow.

The path I used is correct.
VB
Private Declare Function OpenIcon Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
Dim hWnd As Long
hWnd = FindWindow(vbNullString, "C:\newfolder\RFDRIVERSIMULATION.EXE")
OpenIcon (hWnd)
SetForegroundWindow (hWnd)
' SendKeys etc
Posted
Updated 1-Sep-10 11:01am
v3

1 solution

It says this because you're using a declaration (Declare statement) written for VB6. VB6's Long type is a 32-bit signed Integer, whereas in VB.NET it's a 64-bit signed Integer. This code would not have worked in any version of VB.NET, only VB6.

The correct parameter type in VB.NET is IntPtr, not Long.
 
Share this answer
 
Comments
sasho_612 5-May-12 11:40am    
Thank you very much for helpful solution. I have changed Long to IntPtr and it works fine in Visual Basic 2010.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900