Machsupport Forum

Mach Discussion => Mach SDK plugin questions and answers. => Topic started by: iceblu3710 on January 02, 2010, 03:59:39 AM

Title: My First Plugin - Function, Forms And General Troubbles
Post by: iceblu3710 on January 02, 2010, 03:59:39 AM
Im trying to integrate my keyboard hook program into a form in my mach 3 plugin.

I have included my project (created as 'CustomPlugin' and compiles and works great) as well as my stand alone KeyboardHook project that also works by itself

Here are my questions:
1) To use my keyboard hook it should be as simple as adding the Kennedy.ManagedHooks.dll to the references and then initilize the component as:
Code: [Select]
private Kennedy.ManagedHooks.KeyboardHook keyboardHook = null;
keyboardHook = new Kennedy.ManagedHooks.KeyboardHook();
keyboardHook.KeyboardEvent += new Kennedy.ManagedHooks.KeyboardHook.KeyboardEventHandler(Hook_KeyboardEvent);

then call install in a button:
Code: [Select]
void CPluginTestDlg::OnBnClickedHookInstall()
{
//  Install Keyboard Hook
DbgMsg(("keyboardHook Installed"));

//keyboardHook.InstallHook();
}

void CPluginTestDlg::OnBnClickedHookRemove()
{
//  Remove Keyboard Hook
DbgMsg(("keyboardHook Removed"));

//keyboardHook.UninstallHook();
//keyboardHook = NULL;
}

But I have no idea where to initialize my object! I have tried it in my CustomPluginInit.cpp's header, in myPostInitControl() and all no luck compiler throws errors. Where should I initialize this object?

2) General issue I don't understand. If I use project wizard and make a blank document then add a forum I can add things like textboxes. In my plugin project I cannot add test boxes.

3) General issue is that for some reason in all my other project having variable = null; is correct, 'null' is blued as normal but in my plugin project compuler says 'null' is not defined but I can use 'NULL' and the error clears but NULL does not blue.

Anyone know if I have some random setting messed up that is causing my issues?

Thanks!
Title: Re: My First Plugin - Function, Forms And General Troubbles
Post by: rcrabb on January 02, 2010, 11:10:01 AM
I've been working with the plugin wizard. My project is created in VS 2008.NET. I just added your hooks DLL to my project with no problem. Im not sure how to do it with 2003.
Title: Re: My First Plugin - Function, Forms And General Troubbles
Post by: rcrabb on January 02, 2010, 11:16:46 AM
I'm no expert. I just have hundreds of hours learning c++ 2008.NET. I've run into many problems getting the wiiuse dll working with my plugin. I climbed that hill so hopefully I can help you.
Title: Re: My First Plugin - Function, Forms And General Troubbles
Post by: iceblu3710 on January 02, 2010, 02:31:28 PM
Thanks for the response.

I was using VS 2008 myself but I was running into unicode compatibility issues, the same project 2008 would not compile works perfectly in 2003. I followed jemmyell's 'Mach3 Plugin Tutorial Document and Prototype File Set' and had no issues at all besides needing to add the off include to resolve a dependency. My customplugin is a perfect working version of that tutorial that I tried to add the hooks dll to.

I see in your object browser you can actually view the function blocks, in my other projects by adding them to the references they add to the object browser but I have had to manually add system,design,forms,hooks to the object browser manually. This might be normal but usually its automatic for me.

Can you offer any insight to why my null assignments don't work or to why I cannot create a text box?

Also since you can add the dll easily have you been able to initialize the hook object successfully by chance?? (the block of code in pic two)
Title: Re: My First Plugin - Function, Forms And General Troubbles
Post by: rcrabb on January 02, 2010, 03:24:26 PM
I put this line.

Kennedy::ManagedHooks::KeyboardHook^ keyboardHook = gcnew Kennedy::ManagedHooks::KeyboardHook;

Compiled with no errors

Title: Re: My First Plugin - Function, Forms And General Troubbles
Post by: iceblu3710 on January 02, 2010, 04:52:10 PM
Quote
I put this line.

Kennedy::ManagedHooks::KeyboardHook^ keyboardHook = gcnew Kennedy::ManagedHooks::KeyboardHook;

Compiled with no errors

Where did you put that line?? I have tried it in my form initilization, as well as my postinit and customplugininit.cpp header and be it using ::/./-> referencing the compiler does not acknowledge Kennedy as a valad class or namespace at all.

Could you put the line in my project and see if it compile then send the project back? Maybe it works with 2008 but not 2003 but that would suck...

What I don't understand is why in my hook example app does my object work with direct (.) member access and not work in my plugins. I included the Kennedy.ManagedHooks.dll in the same with with both projects and the compile time options are the same (Besides my plugin being a dll that is)
Title: Re: My First Plugin - Function, Forms And General Troubbles
Post by: rcrabb on January 02, 2010, 06:15:44 PM
Its different in 2008. I also tried it several ways in 2003 and no luck. Try the plugin wizard in 2008.NET
Title: Re: My First Plugin - Function, Forms And General Troubbles
Post by: rcrabb on January 02, 2010, 06:27:20 PM
I put the line several places in my code to test
Title: Re: My First Plugin - Function, Forms And General Troubbles
Post by: iceblu3710 on January 02, 2010, 07:13:57 PM
Hey,

I did a VS2008 test with the wizard and i can initialize now buy why on earth is the syntax so different? The documentation states things a bit oversimplified:

Code: [Select]
mouseHook = new MouseHook(); // mouseHook is a member variable

mouseHook.MouseEvent += new MouseHook.MouseEventHandler(mouseHook_MouseEvent);


private void mouseHook_MouseEvent(MouseEvents mEvent, int x, int y)
{
    string msg = string.Format("Mouse event: {0}: ({1},{2}).",
                                           mEvent.ToString(), x, y);
    AddText(msg); // Adds the message to the text box.

}

mouseHook.InstallHook();

mouseHook.UninstallHook();

and says its a pretty standard c++ implementation but its assumed you know how to add all the required files which I don't know how to do.

This is the project I I am basing all this off of (http://www.codeproject.com/KB/system/globalsystemhook.aspx)

In VS2008 I did what I thought was right, added the Kennedy dll as a resource and with :: member referencing even auto complete works yet in VS2003 it wont. The example projects open in VS2003 without any problems and compile fine yet in VS2008 they need to be converted so its not like im using a compiler older than the examples.
Title: Re: My First Plugin - Function, Forms And General Troubbles
Post by: rcrabb on January 02, 2010, 07:32:28 PM
Hopefully one of the experts can explain. My knowledge is very limited. I've been having great luck with the wizard.
Title: Re: My First Plugin - Function, Forms And General Troubbles
Post by: iceblu3710 on January 02, 2010, 08:26:24 PM
Bahaha I got sick of that hook library and used something else.

Here is a working project that detects key events globally and displays a msgbox with the key data. Put the compiled dll and KeyHook.dll in the plugins folder and check it out.

its a great little library, add the KeyHook.lib to your project and include KeyHook.h (very well documented) and away you go.

Title: Re: My First Plugin - Function, Forms And General Troubbles
Post by: rcrabb on January 02, 2010, 08:53:06 PM
Nice. I took a look and it seem easier than the other. Keep posting your progress. Im interested to see what you do with it.
Title: Re: My First Plugin - Function, Forms And General Troubbles
Post by: iceblu3710 on January 04, 2010, 04:18:02 PM
So im playing with the Trajectory Planner and bloody hell its confusing how you access member variables... For example here is an encoder counter that is in both the Engine and in MAchPlanner:

Engine->Encoders[4].Count[0] = MPG1_Count;
MainPlanner->MPG.Encoders[4]->Count[0] = MPG1_Count;

What is the rhyme & reason for member addressing?

I know you access class/struct/union members directly (.) and access objects with pointers (->) but in the 2nd example how is there a pointer to Count when thats a member of the encoder structure?? Then in later compilers I need to use (::). Anyone care to explain to me this setup or have a good tutorial or web explanation on all this??

NOTE: BSOD = Funny memories