 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Fuzz Grandmaster Cheater
Reputation: 0
Joined: 12 Nov 2006 Posts: 531
|
Posted: Fri Jul 25, 2008 2:55 pm Post subject: [C# HELP] Sendmessage FAIL. |
|
|
Ok, well, sendmessage isnt working. I get like 2 errors, which i cannot fix. So maybe someone here can help.
Here's my SendMessage code:
| Code: | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WindowsFormsApplication1
{
[DllImport("user32.dll")]
public static extern int FindWindow(
string lpClassName, // class name
string lpWindowName // window name
);
[DllImport("user32.dll")]
public static extern int SendMessage(
int hWnd, // handle to destination window
uint Msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);
} |
Now, my problem, is, it underlines "int" before FindWindow, and after Extern, sane with SendMessage. It highlights "int" and says:
Expected class, delegate, enum, interface, or struct.
I get that twice.
And i also get Another error twice:
The modifier 'extern' is not valid for this item
Anyone had this problem and solved, or can someone help -.-. Thanks.
Last edited by Fuzz on Fri Jul 25, 2008 10:48 pm; edited 1 time in total |
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Fri Jul 25, 2008 3:15 pm Post subject: |
|
|
Well first off it returns LRESULT not int, and second of its HWND hWnd, not int hWnd.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Fri Jul 25, 2008 3:53 pm Post subject: |
|
|
First, you should use the .NET variant of FindWindow() (use Process.GetProcessesByName() with the process name as the parameter, then get the hWnd from the property similar to that (I can't remember the exact name)).
I don't know if this is your problem, but it's probably going to show up later on.
Change the decl to this:
| Code: |
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr SendMessage(
IntPtr hWnd,
uint Msg,
IntPtr wParam,
IntPtr lParam);
|
After you call the method, for debugging, you should do something like
| Code: |
//... after call...
int Error = Marshal.GetLastWin32Error();
if (Error != 0)
{
MessageBox.Show ("There was an error calling the method!, error code " + Error.ToString());
return;
} |
The error code will be a number, and you can look that up on the internet (or if you have professional Visual Studio, Tools -> Error Lookup).
~~
Maybe add
| Code: |
using System.Interop.RuntimeServices;
|
to the top of your code?
_________________
|
|
| Back to top |
|
 |
Fuzz Grandmaster Cheater
Reputation: 0
Joined: 12 Nov 2006 Posts: 531
|
Posted: Fri Jul 25, 2008 5:34 pm Post subject: |
|
|
I'll give it a shot, thanks samuri.
EDIT:
Still errors. Here's SS:
If you cant see: Code:
| Code: | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Interop.RuntimeServices;
namespace WindowsFormsApplication1
{
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr SendMessage(
IntPtr hWnd,
uint Msg,
IntPtr wParam,
IntPtr lParam);
}
|
That code is in a class. Class1.cs is that the right spot for it?
Also, errors:
| Code: | Error 1 The modifier 'extern' is not valid for this item C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\WindowsFormsApplication1\Class1.cs 11 25 WindowsFormsApplication1
|
| Code: | Error 1 The modifier 'extern' is not valid for this item C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\WindowsFormsApplication1\Class1.cs 11 25 WindowsFormsApplication1
|
Error 3 Expected class, delegate, enum, interface, or struct C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\WindowsFormsApplication1\Class1.cs 12 22 WindowsFormsApplication1
|
|
| Back to top |
|
 |
Odecey Master Cheater
Reputation: 1
Joined: 19 Apr 2007 Posts: 259 Location: Scandinavia
|
Posted: Sat Jul 26, 2008 7:05 pm Post subject: |
|
|
Uhm, isnt this
| samuri25404 wrote: |
Maybe add
| Code: |
using System.Interop.RuntimeServices;
|
to the top of your code? |
supposed to be
| Code: |
using System.Runtime.InteropServices;
| ?
_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren |
|
| Back to top |
|
 |
AngelSl Cheater
Reputation: 0
Joined: 13 Jul 2007 Posts: 34
|
Posted: Sun Jul 27, 2008 8:10 am Post subject: |
|
|
I can't believe you guys didn't notice this.
| Code: | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Interop.RuntimeServices;
namespace WindowsFormsApplication1 // Namespace, OK
{
class Main
{
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr SendMessage( // Cannot have a function in namespace - must be in CLASS
IntPtr hWnd,
uint Msg,
IntPtr wParam,
IntPtr lParam);
}
} |
_________________
|
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Sun Jul 27, 2008 8:27 am Post subject: |
|
|
| It's not "System.Interop.RuntimeServices", like Odecey said, it's "System.Runtime.InteropServices".
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Tue Jul 29, 2008 12:11 pm Post subject: |
|
|
| Symbol wrote: | | It's not "System.Interop.RuntimeServices", like Odecey said, it's "System.Runtime.InteropServices". |
Right, my bad, really rusty.
Edit:
| AngelSl wrote: | I can't believe you guys didn't notice this.
| Code: | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Interop.RuntimeServices;
namespace WindowsFormsApplication1 // Namespace, OK
{
class Main
{
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr SendMessage( // Cannot have a function in namespace - must be in CLASS
IntPtr hWnd,
uint Msg,
IntPtr wParam,
IntPtr lParam);
}
} |
|
I noticed it in the picture, I was just scanning the code
_________________
|
|
| Back to top |
|
 |
|
|
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
|
|