PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

GAPI Hardware buttons iPAQ C#

OK, using the code below I press button2 and this disables the standard functions of the Hardware buttons If I press button3 these functions return.

My problem is I want to catch the keydown events of the hardware buttons.

I can do this for the arrow keys without any GAPI functions. However after calling GXOpen I cannot.
I then press button1(GXGetDefaultKeys) and my app closes?:?? without any error messages?? :(

any ideas or help is greatly appreciated. Please try to keep in .NET framework (which cannot use .h files)

[DllImport("gx.dll", EntryPoint="?OpenInput@@YAHXZ")]
private static extern int GXOpenInput();

[DllImport("gx.dll", EntryPoint="?GXCloseInput@@YAHXZ")]
private static extern int GXCloseInput();

[DllImport("gx.dll", EntryPoint="GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z")]
private static extern GXKeyList GXGetDefaultKeys(int i);

struct GXKeyList
{
short vkUp;
Point ptUp;
short vkDown;
Point ptDown;
short vkLeft;
Point ptLeft;
short vkRight;
Point ptRight;
short vkA;
Point ptA;
short vkB;
Point ptB;
short vkC;
Point ptC;
short vkStart;
Point ptStart;
};

private void button1_Click(object sender, System.EventArgs e)
{
GXKeyList gx_keylist;
gx_keylist = GXGetDefaultKeys(2);
}

private void button2_Click(object sender, System.EventArgs e)
{
GXOpenInput();
}

private void button3_Click(object sender, System.EventArgs e)
{
GXCloseInput();
}
Pacomac · 28 Sep 2002, 15:52 UTC — GAPI Hardware buttons iPAQ C#
bennie wrote:
Please try to keep in .NET framework (which cannot use .h files)


What's wrong with good old C++ (C# = pants)!!
1)
I'm not yet familiar with .NET, but I think you have a typo? The first two EntryPoint declarations start with ? (the first is also missing GX), but the third doesn't.... but if the ?'s just wildcard matching it should be alright...

2)
Do you really have to use the mangled function names in .NET declarations? Shouldn't a simple:
Code:
[DllImport("gx.dll", EntryPoint="GXGetDefaultKeys")]
private static extern GXKeyList GXGetDefaultKeys(int i);


work?

3)
If that doesn't fix it, what does a sizeof(gx_keylist) return?

Cheers,

Ref.
Thank you for your suggestions.
I got the strings from gx.dll so I do not actually know what the ? stands for. The Mangled strings are nessecary as if they are anything different I recieve missing method exceptions when attempting to call them.
I cannot do a sizeof(gx_keylist) as when gx_keylist is initialised the app closes.
I am so stuck on this.
Any help from anyone would be appreciated.
Do PocketPCs even support C#?
WinCE.Net does. I somehow doubt he'd be coding his app in C# if the target platform doesn't support it though.
Ok, next thing, how is "Point" defined?
Umm I've been playing some more and I don't think the struct is the problem as GXGetDefaultKeys(int i) should return a pointer to the struct which is just an integer value. So I changed the code to

Code:

[DllImport("gx.dll", EntryPoint="?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z")]
private static extern int GXGetDefaultKeys(int iOptions);

then called this assigning it to an int and recieved the same problem. ie, app closes when GXGetDefaultKeys is called.
But for your info Point is a predefined .NET struct that contains an X and a Y value.
In the C++ header file, it's declared as:
Code:

GXKeyList GXGetDefaultKeys(int iOptions);


This isn't (unless I'm horribly mistaken, which is always possible) returning a pointer to a GXKeyList - it is actually returning a GXKeyList structure (on the stack).

The reason I wanted to know the size was because if the sizes are different you're trashing the stack by putting, say, 256 bytes on, and pulling 252 off(which will kill the process pretty quickly). Equally if the point structures are different the size of the structure is different.
ok, I thought it returned a pointer from some code I found that was using it. But your right the .h does not seem to support this theory. So heres the struct from gx.h. Where do they get there definition of POINT??

Code:
struct GXKeyList {
short vkUp; // key for up
POINT ptUp; // x,y position of key/button. Not on screen but in screen coordinates.
short vkDown;
POINT ptDown;
short vkLeft;
POINT ptLeft;
short vkRight;
POINT ptRight;
short vkA;
POINT ptA;
short vkB;
POINT ptB;
short vkC;
POINT ptC;
short vkStart;
POINT ptStart;
};

:? Thank you so much for all your help so far.
Code:
typedef struct tagPOINT
{
LONG x;
LONG y;
} POINT, *PPOINT, NEAR *NPPOINT, FAR *LPPOINT;


No problem for the help :)

Cheers,

Ref.