"System.ArgumentException occurred in mscorlib.dll. Field passed in is not a
marshaled member of the type A10CSS.A10+MSG".
in the following code snippet where I am servicing a hooks callback. Any
suggestions? Thanks!
...
namespace A10CSS
{
public class A10 : System.Windows.Forms.Form
{
...
private LocalWindowsHook m_lwh;
...
public A10() : base()
{
m_lwh = new LocalWindowsHook(HookType.WH_GETMESSAGE);
m_lwh.HookInvoked += new
LocalWindowsHook.HookEventHandler(m_lwh_HookInvoked);
}
...
protected override void WndProc(ref Message m)
{
Debug.WriteLine(m.Msg);
const int WM_CREATE = 0x0001;
const int WM_DESTROY = 0x0002;
if (m.Msg == WM_CREATE)
{
m_lwh.Install();
Debug.WriteLine ("Hook Installed");
}
if (m.Msg == WM_DESTROY)
{
m_lwh.Uninstall();
Debug.WriteLine ("Hook Uninstalled");
}
base.WndProc (ref m);
}
private void m_lwh_HookInvoked(object sender, HookEventArgs e)
{
const int WM_NULL = 0;
const int PM_REMOVE = 0x0001;
const int WM_KEYFIRST = 0x0100;
const int WM_KEYLAST = 0x0109;
if (e.HookCode >= 0 && new IntPtr(PM_REMOVE) == e.wParam)
{
// following line is where I get the "System.ArgumentException
// occurred in mscorlib.dll Field passed in is not a marshaled member of the
type A10CSS.A10+MSG".
uint msg = (uint)Marshal.ReadInt32(e.lParam,
Marshal.OffsetOf(typeof(MSG), "Msg").ToInt32());
if(msg >= WM_KEYFIRST && msg <= WM_KEYLAST)
{
if(IsDialogMessage(this.Handle, e.lParam) != 0)
{
Marshal.WriteInt32(e.lParam, Marshal.OffsetOf(typeof(MSG),
"Msg").ToInt32(), WM_NULL);
Marshal.WriteInt32(e.lParam, Marshal.OffsetOf(typeof(MSG),
"wParam").ToInt32(), 0);
Marshal.WriteInt32(e.lParam, Marshal.OffsetOf(typeof(MSG),
"lParam").ToInt32(), 0);
}
}
}
}
[ StructLayout(LayoutKind.Sequential) ]
struct MSG
{
IntPtr hwnd;
uint Msg;
IntPtr wParam;
IntPtr lParam;
int time;
//POINT pt
int x;
int y;
}
[DllImport("user32.dll")]
private static extern int IsDialogMessage(IntPtr hDlg, IntPtr lpMsg);
}
}
--
<_/\_> RapidFireBill
--
<_/\_>
Since it marshals to the .NET message structure, you don't even need to
declare your own message structure.
Hope this helps,
--Saurabh
"RapidFireBill" <RapidF...@discussions.microsoft.com> wrote in message
news:6F02BB5A-6EF2-4CA7...@microsoft.com...
public int YourHookProc(int nCode, IntPtr wParam, IntPtr lParam)
{
Message msg =
(Message)System.Runtime.InteropServices.Marshal.PtrToStructure(lParam,
typeof(Message));
if (nCode >= 0 && PM_REMOVE == wParam.ToInt32())
{
if ((msg.Msg >= WM_KEYFIRST) &&(msg.Msg <= WM_KEYLAST))
{
long i = IsDialogMessage(this.Handle, ref msg);
if (i != 0)
{
msg.Msg = 0;
msg.LParam = IntPtr.Zero;
msg.WParam = IntPtr.Zero;
System.Runtime.InteropServices.Marshal.StructureToPtr(msg, lParam,
true);
}
}
}
return CallNextHookEx(hTabHook, nCode, wParam, lParam);
}
HTH,
--Saurabh
"RapidFireBill" <RapidF...@discussions.microsoft.com> wrote in message
news:6F02BB5A-6EF2-4CA7...@microsoft.com...
My tab keys are working, but SHIFT-TAB does not reverse the tabbing
direction. Also my arrow keys work, but on RadioButtons, they do not traverse
the RadioButtons in a circular pattern.
I would like them to work like when I launched my dialog 'Modal' with
A10.ShowDialog in a separate thread (my parent app stayed open in TaskManager
after I closed the parent app). But the IsDialogMessage method tabbing &
arrowing behaviour is different than Modal in a thread.
Do you know why this behaviour is different?
I'm having the same issue, and hopefully you're still watching this thread.
Anyways, I was able to get it to work by making all the struct members public
from the original example, and everything seemed okay, however I have another
problem and could really use your feedback.
When someone presses the 'TAB' key, it's going through the tab stops in
reverse order. I would greatly appreciate some help on this issue.
Thanks,
Jon
The tabs are working for me. But they are not following in the order set, They are doing randon tabs, though I have set the tab order correctly.
Any puts will be great.
Saleem
Posted via DevelopmentNow.com Groups
http://www.developmentnow.com/g/