• Advertisement
Sign in to follow this  

DirectInput, ApiHijack, and VB.Net

This topic is 4383 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I was trying to write some kind of voice-enabled app , to interact with DirectX, when I found this topic by Muhammad Haggag in this forum: http://www.gamedev.net/community/forums/topic.asp?topic_id=371104 Now the problem is that, though the sample work fine, I can't import the library "DirectInput-Hook.dll" to my VB.Net project. Wish someone could help me. I think it must be a simple question, but Visual Studio says "This file is not valid[...]not a COM object". Thanks in advance :)

Share this post


Link to post
Share on other sites
Advertisement
You can't import the DLL because it's not a COM object (doesn't implement a COM server). Use PInvoke. For example, in C# (off the top of my head):

public class InputHook
{
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("DInputHook.dll", EntryPoint="InstallHook", CharSet=CharSet.Auto)]
public static extern void InstallHook();

[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("DInputHook.dll", EntryPoint="RemoveHook", CharSet=CharSet.Auto)]
public static extern void RemoveHook();
}

Share this post


Link to post
Share on other sites
Drat, beaten to it again :)

Anyway, if you get this to work, please post some more info on what you did exactly. I've been working on this too in C#, but somehow calling the InstallHook procedure through .NET PInvoke caused the hook to stop working (properly), even though it works just fine using the native launcher.

Share this post


Link to post
Share on other sites
Ok, now I can use the library. Thank you. :)

I used this code in VB.Net

Public Class InputHook

<System.Security.SuppressUnmanagedCodeSecurity()> Public Declare Auto Sub InstallHook Lib "DirectInput-Hook.dll" Alias "InstallHook" ()
<System.Security.SuppressUnmanagedCodeSecurity()> Public Declare Auto Sub RemoveHook Lib "DirectInput-Hook.dll" Alias "RemoveHook" ()
End Class 'InputHook

But anyway, it still not working. I have the same problem as remigius.

My basic code is something like this:

Private Sub btnIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIn.Click

H.InstallHook()

End Sub

Private Sub btnOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOut.Click

H.RemoveHook()

End Sub

Then i have a timer sending keystrokes:

keybd_event(VK_A, 0, 0, 0)
keybd_event(VK_A, 0, KEYEVENTF_KEYUP, 0)

It works with any window, but not with the sample "keyboard.exe".

I'm trying to do it this way:

1- Open my app
2- btnIn (InstallHook)
3- launch "keyboard.exe"
4- button "Create Device" in "keyboard.exe"
(at this point, keyboard.exe should be receiving the keystrokes, beacause the timer is on, but it doesn't)
5- Close "keyboard.exe"
6- btnOut (Remove Hook)

Am I doing something wrong? I've spent a lot of time trying other ways to do it, but none of them worked :(

Thank you again (and sorry for my english...i'm from spain ;) )

Share this post


Link to post
Share on other sites
Unfortunately, I didn't get time to inspect this, and I might not get a chance in the foreseeable future. A unix-style solution to this problem would be to use my launcher from your own program; launch the process when you want it to install the hook and terminate it (or send it a terminating keypress - I don't remember how the launcher worked) when you want to uninstall it.

Share this post


Link to post
Share on other sites
Muhammad, Please do spend sometime on this someday later.
I am interested in it too.
I still haven't figure out how to hook my game.

Share this post


Link to post
Share on other sites
Thank's for your answer and your time Muhammad. Anuway, I'll be aware of this topic. Maybe someone else, can find the answer.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement