Hanging Process

J

Jerod Houghtelling

Hi all,

I'm creating a Kiosk program and I'm trying to hook into the start bar
left click. I think I'm really close, but I've hit a snag when control
comes back to my program. I'm not exactly sure what is happening, but
I have narrowed down the code to possibly the cause. See notes in code
below...





using System;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace StartBarTest
{
public partial class Form1 : Form
{
private static StartBarLeftClickDelegate mStartBarCallback;
private delegate void StartBarLeftClickDelegate();

public Form1()
{
InitializeComponent();
}

[DllImport( "CUMenuNative.dll" )]
private static extern void HookStartButtonLeftClick(
[MarshalAs( UnmanagedType.FunctionPtr )]
StartBarLeftClickDelegate callbackPointer );

[DllImport( "CUMenuNative.dll" )]
private static extern void UnHookStartButtonLeftClick();

protected override void OnLoad( EventArgs e )
{
base.OnLoad( e );
mStartBarCallback = new
StartBarLeftClickDelegate( _HandleStartBarClick );
HookStartButtonLeftClick( mStartBarCallback );
}

protected override void
OnClosing( System.ComponentModel.CancelEventArgs e )
{
UnHookStartButtonLeftClick();
base.OnClosing( e );
}

private void _HandleBtnLaunchCalcClick( object sender, EventArgs e )
{
Process.Start( @"\Windows\calc.exe", "" );
}

private void _HandleStartBarClick()
{
if( InvokeRequired )
{
BeginInvoke( new
StartBarLeftClickDelegate( _HandleStartBarClick ) );
return;
}

// TODO: handle how we want the start bar to work.
}

}
}


#include <windows.h>

#ifdef CUMENUNATIVE_EXPORTS
#define CUMENUNATIVE_API __declspec(dllexport)
#endif

WNDPROC mOrgWndProc;
void (*mCallback)();

LRESULT CALLBACK HookWndProc( HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam )
{
if( message == WM_LBUTTONDOWN && LOWORD(lParam) < 150 )
{
// HERE'S THE PROBLEM... IF I REMOVE THE CALL TO mCallback
if( mCallback != NULL )
{
mCallback();
}
else
{
MessageBeep(0);
}
return TRUE;
}

return CallWindowProc( mOrgWndProc, hWnd, message, wParam, lParam );
}

extern "C" CUMENUNATIVE_API void
HookStartButtonLeftClick(void(_stdcall*callback)())
{
mCallback = callback;
HWND hTbWnd = FindWindow( L"HHTaskBar", NULL );
mOrgWndProc = (WNDPROC)SetWindowLong( hTbWnd, GWL_WNDPROC,
(long)HookWndProc );
}

extern "C" CUMENUNATIVE_API void UnHookStartButtonLeftClick()
{
HWND hTbWnd = FindWindow( L"HHTaskBar", NULL );
SetWindowLong( hTbWnd, GWL_WNDPROC, (long)mOrgWndProc );
}
 
C

Chris Tacke, eMVP

So what behavior do you see? Are you getting a callback? Is your code
getting into where the callback should be called?

You also should be initializing mCallback to NULL, as it's probably going to
be non-NULL garbage in a release build.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com


Jerod Houghtelling said:
Hi all,

I'm creating a Kiosk program and I'm trying to hook into the start bar
left click. I think I'm really close, but I've hit a snag when control
comes back to my program. I'm not exactly sure what is happening, but
I have narrowed down the code to possibly the cause. See notes in code
below...





using System;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace StartBarTest
{
public partial class Form1 : Form
{
private static StartBarLeftClickDelegate mStartBarCallback;
private delegate void StartBarLeftClickDelegate();

public Form1()
{
InitializeComponent();
}

[DllImport( "CUMenuNative.dll" )]
private static extern void HookStartButtonLeftClick(
[MarshalAs( UnmanagedType.FunctionPtr )]
StartBarLeftClickDelegate callbackPointer );

[DllImport( "CUMenuNative.dll" )]
private static extern void UnHookStartButtonLeftClick();

protected override void OnLoad( EventArgs e )
{
base.OnLoad( e );
mStartBarCallback = new
StartBarLeftClickDelegate( _HandleStartBarClick );
HookStartButtonLeftClick( mStartBarCallback );
}

protected override void
OnClosing( System.ComponentModel.CancelEventArgs e )
{
UnHookStartButtonLeftClick();
base.OnClosing( e );
}

private void _HandleBtnLaunchCalcClick( object sender, EventArgs e )
{
Process.Start( @"\Windows\calc.exe", "" );
}

private void _HandleStartBarClick()
{
if( InvokeRequired )
{
BeginInvoke( new
StartBarLeftClickDelegate( _HandleStartBarClick ) );
return;
}

// TODO: handle how we want the start bar to work.
}

}
}


#include <windows.h>

#ifdef CUMENUNATIVE_EXPORTS
#define CUMENUNATIVE_API __declspec(dllexport)
#endif

WNDPROC mOrgWndProc;
void (*mCallback)();

LRESULT CALLBACK HookWndProc( HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam )
{
if( message == WM_LBUTTONDOWN && LOWORD(lParam) < 150 )
{
// HERE'S THE PROBLEM... IF I REMOVE THE CALL TO mCallback
if( mCallback != NULL )
{
mCallback();
}
else
{
MessageBeep(0);
}
return TRUE;
}

return CallWindowProc( mOrgWndProc, hWnd, message, wParam, lParam );
}

extern "C" CUMENUNATIVE_API void
HookStartButtonLeftClick(void(_stdcall*callback)())
{
mCallback = callback;
HWND hTbWnd = FindWindow( L"HHTaskBar", NULL );
mOrgWndProc = (WNDPROC)SetWindowLong( hTbWnd, GWL_WNDPROC,
(long)HookWndProc );
}

extern "C" CUMENUNATIVE_API void UnHookStartButtonLeftClick()
{
HWND hTbWnd = FindWindow( L"HHTaskBar", NULL );
SetWindowLong( hTbWnd, GWL_WNDPROC, (long)mOrgWndProc );
}
 
J

Jerod Houghtelling

Thanks Chris for your fast response. I accidentally hit tab then space
which prematurely posted my message, below is the full post.


I'm creating a Kiosk program and I'm trying to hook into the start
bar’s left click event.
The problem I'm having is that when I launch an application from this
form, with Process.Start, the kiosk program seems to lockup when the
launched application closes. This even happens when the start bar is
not clicked. If I remove the call to the passed in delegate the lockup
does not occur. That lead me to believe that maybe my delegate was
being moved. I have tried allocating memory with GCHandle as well as
using GC.KeepAlive, but neither of them seem to solve the program.

I have included all source code except from the designer. Also there
is a video showing the ‘lockup’ if you are interested.


Thanks in advance!
Jerod

using System;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace StartBarTest
{
public partial class Form1 : Form
{
private static StartBarLeftClickDelegate mStartBarCallback;
private delegate void StartBarLeftClickDelegate();

public Form1()
{
InitializeComponent();
}

[DllImport( "CUMenuNative.dll" )]
private static extern void HookStartButtonLeftClick(
[MarshalAs( UnmanagedType.FunctionPtr )]
StartBarLeftClickDelegate callbackPointer );

[DllImport( "CUMenuNative.dll" )]
private static extern void UnHookStartButtonLeftClick();

protected override void OnLoad( EventArgs e )
{
mStartBarCallback = new
StartBarLeftClickDelegate( _HandleStartBarClick );
HookStartButtonLeftClick( mStartBarCallback );
base.OnLoad( e );
}

protected override void OnClosing(
System.ComponentModel.CancelEventArgs e )
{
base.OnClosing( e );
UnHookStartButtonLeftClick();
}

private void _HandleBtnLaunchCalcClick( object sender, EventArgs e )
{
Process.Start( @"\Windows\calc.exe", "" );
}

private void _HandleStartBarClick()
{
if( InvokeRequired )
{
BeginInvoke( new StartBarLeftClickDelegate(
_HandleStartBarClick ) );
return;
}

// TODO: handheld how we want the start bar to work.
mStartMenu.Show( this, new Point( 0, 0 ) );
}
}
}

#include <windows.h>

#ifdef CUMENUNATIVE_EXPORTS
#define CUMENUNATIVE_API __declspec(dllexport)
#endif

WNDPROC mOrgWndProc;
void (*mCallback)();

LRESULT CALLBACK HookWndProc( HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam )
{
if( message == WM_LBUTTONDOWN && LOWORD(lParam) < 150 )
{
// HERE IS THE PROBLEM... IF I REMOVE THE CALL TO
// mCallback THEN THE PROBLEM DOESN'T OCCUR. I HAVE
// VERIFIED THAT THIS SECTION OF CODE IS NOT BEING
// EXECUTED WHEN THE CALC PROGRAM EXITS.
if( mCallback != NULL )
{
mCallback();
}
else
{
MessageBeep(0);
}
return TRUE;
}

return CallWindowProc( mOrgWndProc, hWnd, message, wParam, lParam );
}

extern "C" CUMENUNATIVE_API void
HookStartButtonLeftClick(void(_stdcall*callback)())
{
mCallback = callback;
HWND hTbWnd = FindWindow( L"HHTaskBar", NULL );
mOrgWndProc = (WNDPROC)SetWindowLong(
hTbWnd, GWL_WNDPROC, (long)HookWndProc );
}

extern "C" CUMENUNATIVE_API void UnHookStartButtonLeftClick()
{
HWND hTbWnd = FindWindow( L"HHTaskBar", NULL );
SetWindowLong( hTbWnd, GWL_WNDPROC, (long)mOrgWndProc );
}

So what behavior do you see?  Are you getting a callback?  Is your code
getting into where the callback should be called?

You also should be initializing mCallback to NULL, as it's probably going to
be non-NULL garbage in a release build.

--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded communityhttp://community.OpenNETCF.com


I'm creating a Kiosk program and I'm trying to hook into the start bar
left click. I think I'm really close, but I've hit a snag when control
comes back to my program. I'm not exactly sure what is happening, but
I have narrowed down the code to possibly the cause. See notes in code
below...
using System;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace StartBarTest
{
public partial class Form1 : Form
{
private static StartBarLeftClickDelegate mStartBarCallback;
private delegate void StartBarLeftClickDelegate();
public Form1()
{
InitializeComponent();
}
[DllImport( "CUMenuNative.dll" )]
private static extern void HookStartButtonLeftClick(
[MarshalAs( UnmanagedType.FunctionPtr )]
StartBarLeftClickDelegate callbackPointer );
[DllImport( "CUMenuNative.dll" )]
private static extern void UnHookStartButtonLeftClick();
protected override void OnLoad( EventArgs e )
{
base.OnLoad( e );
mStartBarCallback = new
StartBarLeftClickDelegate( _HandleStartBarClick );
HookStartButtonLeftClick( mStartBarCallback );
}
protected override void
OnClosing( System.ComponentModel.CancelEventArgs e )
{
UnHookStartButtonLeftClick();
base.OnClosing( e );
}
private void _HandleBtnLaunchCalcClick( object sender, EventArgs e )
{
Process.Start( @"\Windows\calc.exe", "" );
}
private void _HandleStartBarClick()
{
if( InvokeRequired )
{
BeginInvoke( new
StartBarLeftClickDelegate( _HandleStartBarClick ) );
return;
}
// TODO: handle how we want the start bar to work.
}

#include <windows.h>
#ifdef CUMENUNATIVE_EXPORTS
#define CUMENUNATIVE_API __declspec(dllexport)
#endif
WNDPROC mOrgWndProc;
void (*mCallback)();
LRESULT CALLBACK HookWndProc( HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam )
{
if( message == WM_LBUTTONDOWN && LOWORD(lParam) < 150 )
{
// HERE'S THE PROBLEM... IF I REMOVE THE CALL TO mCallback
if( mCallback != NULL )
{
mCallback();
}
else
{
MessageBeep(0);
}
return TRUE;
}
return CallWindowProc( mOrgWndProc, hWnd, message, wParam, lParam );
}
extern "C" CUMENUNATIVE_API void
HookStartButtonLeftClick(void(_stdcall*callback)())
{
mCallback = callback;
HWND hTbWnd = FindWindow( L"HHTaskBar", NULL );
mOrgWndProc = (WNDPROC)SetWindowLong( hTbWnd, GWL_WNDPROC,
(long)HookWndProc );
}
extern "C" CUMENUNATIVE_API void UnHookStartButtonLeftClick()
{
HWND hTbWnd = FindWindow( L"HHTaskBar", NULL );
SetWindowLong( hTbWnd, GWL_WNDPROC, (long)mOrgWndProc );
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top