Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[Help (C#) ] PMX.dll - how to Call the function in C#
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
MyFeel
Expert Cheater
Reputation: 0

Joined: 04 Jun 2007
Posts: 143

PostPosted: Tue Dec 04, 2007 4:32 am    Post subject: Reply with quote

samuri25404 wrote:
Try this:

Code:

[System.Runtime.InteropServices.DLLImport("PMX.dll")]
private static extern void PostMessageX(IntPtr hWnd , UINT msg, IntPtr wParam, IntPtr lParam);

//Lalaa....
//Later...

System.Diagnostics.Process[] myprocs = System.Diagnostics.Process.GetByName("MyApp"); //I think that's how it is, it's been a little while
IntPtr hWnd = myprocs[0].ID; //First instance of the application

PostMessageX(hWnd,0x09,0,0); //I'm guessing that 0x09 is the message that you want to send


i have tried it but i still get errors =\
here the code what wrong


Code:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {


        [DllImport("PMX.DLL", EntryPoint = "PostMessageX")]
        public static extern IntPtr PostMessageX(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);

        System.Diagnostics.Process[] myprocs = System.Diagnostics.Process.GetByName("MyApp");
        IntPtr hWnd = myprocs[0].ID; //First instance of the application

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
 
            PostMessageX(hWnd, 0x41, 0, 0); //I'm guessing that 0x09 is the message that you want to send

        }
    }
}


Back to top
View user's profile Send private message
rump
Expert Cheater
Reputation: 0

Joined: 03 Oct 2007
Posts: 169

PostPosted: Tue Dec 04, 2007 12:30 pm    Post subject: Reply with quote

Have you tried the keybd_event function?
_________________
C# boot camp, PM me if you want a simple application made and I'll give it a try!
Back to top
View user's profile Send private message
MyFeel
Expert Cheater
Reputation: 0

Joined: 04 Jun 2007
Posts: 143

PostPosted: Tue Dec 04, 2007 12:33 pm    Post subject: Reply with quote

yes.. it already detected..
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Tue Dec 04, 2007 12:46 pm    Post subject: Reply with quote

Rolling Eyes

myprocs[0].ID is the PROCESS ID, NOT THE WINDOW HANDLE!

_________________
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Tue Dec 04, 2007 12:48 pm    Post subject: Reply with quote

shoudnt your PostMessageX look like this?

Code:

private const int WM_KEYDOWN = 0x100;
....

PostMessageX(hWnd, WM_KEYDOWN, 0x41, 0);

_________________
Back to top
View user's profile Send private message
rump
Expert Cheater
Reputation: 0

Joined: 03 Oct 2007
Posts: 169

PostPosted: Tue Dec 04, 2007 3:05 pm    Post subject: Reply with quote

ahh, dang... Keybd_event is nice :/
_________________
C# boot camp, PM me if you want a simple application made and I'll give it a try!
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Tue Dec 04, 2007 3:17 pm    Post subject: Reply with quote

appalsap wrote:
:roll:

myprocs[0].ID is the PROCESS ID, NOT THE WINDOW HANDLE!


My bad, I didn't finish it.

I haven't done this in a while;

API Calls:

Code:


        [Flags]
        public enum ProcessAccessType
        {
            PROCESS_TERMINATE = (0x0001),
            PROCESS_CREATE_THREAD = (0x0002),
            PROCESS_SET_SESSIONID = (0x0004),
            PROCESS_VM_OPERATION = (0x0008),
            PROCESS_VM_READ = (0x0010),
            PROCESS_VM_WRITE = (0x0020),
            PROCESS_DUP_HANDLE = (0x0040),
            PROCESS_CREATE_PROCESS = (0x0080),
            PROCESS_SET_QUOTA = (0x0100),
            PROCESS_SET_INFORMATION = (0x0200),
            PROCESS_QUERY_INFORMATION = (0x0400)
        }

        [DllImport("kernel32.dll")]
        public static extern IntPtr OpenProcess(UInt32 dwDesiredAccess, Int32 bInheritHandle, UInt32 dwProcessId);

         [DllImport("PMX.dll")]
         private static extern void PostMessageX(IntPtr hWnd , UINT msg, IntPtr wParam, IntPtr lParam);


Your code:

Code:

System.Diagnostics.Process[] myprocs = System.Diagnostics.Process.GetByName("MyApp"); //I think that's how it is, it's been a little while
IntPtr id= myprocs[0].ID; //First instance of the application
IntPtr hWnd = OpenProcess(ProcessAccessType.Operation, 1, id);

PostMessageX(hWnd, 0x09, 0, 0);

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Tue Dec 04, 2007 4:10 pm    Post subject: Reply with quote

samuri25404 wrote:

My bad, I didn't finish it.

I haven't done this in a while;

API Calls:


nooo, you don't open the process either, hWnd is a handle to the Window, which you get from the FindWindow API call, not by process handle!

_________________
Back to top
View user's profile Send private message
sponge
I'm a spammer
Reputation: 1

Joined: 07 Nov 2006
Posts: 6009

PostPosted: Tue Dec 04, 2007 6:13 pm    Post subject: Reply with quote

LOL ... wow... isn't this extremely basic...
_________________
Back to top
View user's profile Send private message
MyFeel
Expert Cheater
Reputation: 0

Joined: 04 Jun 2007
Posts: 143

PostPosted: Wed Dec 05, 2007 2:35 am    Post subject: Reply with quote

sponge wrote:
LOL ... wow... isn't this extremely basic...


hey spong,
can i ask for how calling the function in your dll? (hookHop)
and how to use it? can you give me an example?

thanks.
Back to top
View user's profile Send private message
jongwee
Moderator
Reputation: 0

Joined: 28 Jun 2006
Posts: 1388
Location: Singapore

PostPosted: Wed Dec 05, 2007 3:32 am    Post subject: Reply with quote

MyFeel wrote:
sponge wrote:
LOL ... wow... isn't this extremely basic...


hey spong,
can i ask for how calling the function in your dll? (hookHop)
and how to use it? can you give me an example?

thanks.

Code:
function PostMessageA(
hWnd:HWND;
MSG:UINT;
WPARAM:wParam;
LPARAM:lParam):BOOL;stdcall;
external 'HookHop.dll' name 'PostMessageA';

I think.

_________________
Back to top
View user's profile Send private message MSN Messenger
Aviram
Grandmaster Cheater
Reputation: 0

Joined: 30 Jun 2006
Posts: 633

PostPosted: Wed Dec 05, 2007 7:20 am    Post subject: Reply with quote

jongwee wrote:
MyFeel wrote:
sponge wrote:
LOL ... wow... isn't this extremely basic...


hey spong,
can i ask for how calling the function in your dll? (hookHop)
and how to use it? can you give me an example?

thanks.

Code:
function PostMessageA(
hWnd:HWND;
MSG:UINT;
WPARAM:wParam;
LPARAM:lParam):BOOL;stdcall;
external 'HookHop.dll' name 'PostMessageA';

I think.

Its Delphi, He asked for C#
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Wed Dec 05, 2007 6:05 pm    Post subject: Reply with quote

Code:

[DllImport("HookHop.dll")]
private static extern bool PostMessageA(IntPtr hWnd, uint MSG, IntPtr WPARAM, IntPtr LPARAM);

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
jongwee
Moderator
Reputation: 0

Joined: 28 Jun 2006
Posts: 1388
Location: Singapore

PostPosted: Wed Dec 05, 2007 6:29 pm    Post subject: Reply with quote

Tested hookhop on my bot, works perfectly and the size of the dll is amazingly minimised.
_________________
Back to top
View user's profile Send private message MSN Messenger
sponge
I'm a spammer
Reputation: 1

Joined: 07 Nov 2006
Posts: 6009

PostPosted: Wed Dec 05, 2007 6:56 pm    Post subject: Reply with quote

If you look in my DEF file... you will see that the exported name for my "API" is hhPostMessageA.
I do not program in C# so I cannot tell you how to import it.

_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites