Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Error codes for SendMessage.

9 views
Skip to first unread message

Ulises Vega.

unread,
Nov 6, 2009, 11:53:43 AM11/6/09
to
I'm using the following code to override the default GREEN KEY
behavior:

/
*******************************************************************************************************************/
BEGIN OF SAMPLE CODE
/
*******************************************************************************************************************/
// needed constants
private const Int16 SHMBOF_NODEFAULT = 0x00000001;
private const Int16 SHMBOF_NOTIFY = 0x00000002;
private const Int32 flags = 0x00030003;
private const int WM_USER = 0x0400;
private const int SHCMBM_OVERRIDEKEY = WM_USER + 403;

const int VK_TTALK = 7 * 16 + 2;
const int VK_TEND = 7 * 16 + 3;
const int VK_TBACK = 0x08;

//inside form load.

if(null == this.Handle )
{
throw new SystemException(String.Format("Handle to the
window is null"));
}

IntPtr i = SHFindMenuBar(this.Handle);
if(null == i)
{
code = Marshal.GetLastWin32Error();
serr = Marshal.GetLastWin32Error().ToString();

throw new SystemException( String.Format("Failed
SendMessage, Error string " + serr + " Error code: {0} ", code));
}
long res = (long)SendMessage(i, SHCMBM_OVERRIDEKEY, VK_TBACK,flags);

if (res == 0)
{
code = Marshal.GetLastWin32Error();
serr = Marshal.GetLastWin32Error().ToString();

throw new SystemException(String.Format("Failed
SendMessage, SHCMBM_OVERRIDEKEY Error string" + serr + " Error code:
{0} ", code));
}

[DllImport("coredll.dll", CharSet = CharSet.Auto, SetLastError =
true)]
private static extern int SendMessage(IntPtr hWnd, int wMsg,
int wParam, int lParam);
/
*******************************************************************************************************************/
END OF SAMPLE CODE
/
*******************************************************************************************************************/

However the value oF res, return value of SendMessage, is 0 and the
error is either 6, or 1400.

Could anyone shed some ligth on what I-m doing wrong?
Point me to the error return codes for SendMessage?

Thanks for your help.

Ulises Vega

Peter Foot

unread,
Nov 8, 2009, 1:39:44 PM11/8/09
to

Both error codes indicate the same problem - the window handle is invalid.
You can use the Error Lookup tool in Visual Studio to search for common
error values. You'll either find it on your Tools menu or you can add it
there from its location in the file system:-
C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools

Peter

--
Peter Foot
Microsoft Device Application Development MVP
peterfoot.net | appamundi.com | inthehand.com
APPA Mundi Ltd - software solutions for a mobile world
In The Hand Ltd - .NET Components for Mobility

"Ulises Vega." <usva.t...@gmail.com> wrote in message
news:103be47d-f076-40e6...@z4g2000prh.googlegroups.com...

Ulises Vega.

unread,
Nov 9, 2009, 12:26:11 PM11/9/09
to
Hi Pete,

The previous error was sent due to the fact that I was acquiring the
IntPtr i = SHFindMenuBar(this.Handle); in a place where the MenuBar
still didn't exist. That-s why the invalid handle. I've move it
temporarilly to a button click method, it has a valid handle.

The following code is sending me a error type 87, invalid_parameter,

int res = (int)SendMessage(i, SHCMBM_OVERRIDEKEY, VK_TBACK, t);


if (res == 0)
{
code = Marshal.GetLastWin32Error();
serr = Marshal.GetLastWin32Error().ToString();

throw new SystemException(String.Format
("FailedSendMessage, SHCMBM_OVERRIDEKEY Error string" + serr + " Error
code:{0} ", code));
}

i is not zero, it is 0x7c078730
SHCMBM_OVERRIDEKEY =0x593
VK_TTALK 0x72,
t=0x00030003

the constants for t are:
private const Int32 SHMBOF_NODEFAULT = 0x00000001;
private const Int32 SHMBOF_NOTIFY = 0x00000002;


private const Int32 flags = 0x00030003;

the calculus behind t:
Int32 t = ( ( SHMBOF_NODEFAULT | SHMBOF_NOTIFY ) |
( ( SHMBOF_NODEFAULT | SHMBOF_NOTIFY ) << 16 ) );

I have seen in other threads like this one

http://groups.google.com/group/microsoft.public.smartphone.developer/browse_thread/thread/669d270d93dbc94d/c402702f70adc30d?lnk=gst&q=SHCMBM_OVERRIDEKEY#c402702f70adc30d

They use the same API Sendmessage in C++ but with a MAKELPARAM macro.

any idea on which could be the wrong/invalid parameter in SendMessage?
Do you know how does this MAKELPARAM macro work?

Any help is welcome.

Thanks.

Ulises Vega

Ulises Vega.

unread,
Nov 9, 2009, 12:26:33 PM11/9/09
to
Hi Pete,

The previous error was sent due to the fact that I was acquiring the
IntPtr i = SHFindMenuBar(this.Handle); in a place where the MenuBar
still didn't exist. That-s why the invalid handle. I've move it
temporarilly to a button click method, it has a valid handle.

The following code is sending me a error type 87, invalid_parameter,

int res = (int)SendMessage(i, SHCMBM_OVERRIDEKEY, VK_TBACK, t);

if (res == 0)
{
code = Marshal.GetLastWin32Error();
serr = Marshal.GetLastWin32Error().ToString();

throw new SystemException(String.Format
("FailedSendMessage, SHCMBM_OVERRIDEKEY Error string" + serr + " Error
code:{0} ", code));
}

i is not zero, it is 0x7c078730


SHCMBM_OVERRIDEKEY =0x593
VK_TTALK 0x72,
t=0x00030003

the constants for t are:

private const Int32 SHMBOF_NODEFAULT = 0x00000001;
private const Int32 SHMBOF_NOTIFY = 0x00000002;


private const Int32 flags = 0x00030003;

the calculus behind t:

r_z_...@pen_fact.com

unread,
Nov 9, 2009, 2:11:14 PM11/9/09
to
On Mon, 9 Nov 2009 09:26:33 -0800 (PST), "Ulises Vega."
<usva.t...@gmail.com> wrote:

>Hi Pete,
>
>The previous error was sent due to the fact that I was acquiring the
>IntPtr i = SHFindMenuBar(this.Handle); in a place where the MenuBar
>still didn't exist. That-s why the invalid handle. I've move it
>temporarilly to a button click method, it has a valid handle.
>
>The following code is sending me a error type 87, invalid_parameter,
>
> int res = (int)SendMessage(i, SHCMBM_OVERRIDEKEY, VK_TBACK, t);

SHFindMenuBar returns, and SendMessage wants, and HWND. Why are you
using an int? HWND is a sort of structure, so I'm not at all convinced
an int will work.

Are you sure you have the right value for VK_TBACK? I think I saw a
definition for it in _your_ code, rather than an #include to get it
from the appropriate header.


clip

>SHCMBM_OVERRIDEKEY =0x593

Are you defining this, or using the definition in the appropriate
header?

>VK_TTALK 0x72,

Why do you mention VK_TTALK, when your code uses VK_TBACK?. If you
really want to override VK_TTALK, you should make sure you can; my
(old) copy of help suggests it is supported on Pocket PC but not
Smartphone.


>the calculus behind t:
>Int32 t = ( ( SHMBOF_NODEFAULT | SHMBOF_NOTIFY ) |
>( ( SHMBOF_NODEFAULT | SHMBOF_NOTIFY ) << 16 ) );
>
>I have seen in other threads like this one
>
>http://groups.google.com/group/microsoft.public.smartphone.developer/browse_thread/thread/669d270d93dbc94d/c402702f70adc30d?lnk=gst&q=SHCMBM_OVERRIDEKEY#c402702f70adc30d
>
>They use the same API Sendmessage in C++ but with a MAKELPARAM macro.
>
>any idea on which could be the wrong/invalid parameter in SendMessage?
>Do you know how does this MAKELPARAM macro work?

If you enable browsing in your IDE (may take two locations), you can
right click on the macro and then choose to see its definition. I
believe the macro puts each of two arguments in the correct word of
the output. I won't say the macro is pretty, but using it sure seems
safer and easier than trying to do the work yourself.


>
>Any help is welcome.
>
>Thanks.
>
>Ulises Vega

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 400
Boston, MA 02116
www.penfact.com

Ulises Vega.

unread,
Dec 8, 2009, 2:06:46 PM12/8/09
to
Hi,

Sorry that I didn't answer to your kind reply to my questions. But I
was under time pressure and i found an alternative answer in another
forum that worked.

I just wanted to say so. and post the link to the solution of the
problem.

http://social.msdn.microsoft.com/Forums/en-US/windowsmobiledev/thread/bbeff648-a880-463a-84ab-da5b83e3bf80

Thanks for your help.

Ulises

On Nov 9, 1:11 pm, r_z_aret@pen_fact.com wrote:
> On Mon, 9 Nov 2009 09:26:33 -0800 (PST), "Ulises Vega."
>

> >http://groups.google.com/group/microsoft.public.smartphone.developer/...

0 new messages