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 


[C# HELP] Sendmessage FAIL.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Fuzz
Grandmaster Cheater
Reputation: 0

Joined: 12 Nov 2006
Posts: 531

PostPosted: Fri Jul 25, 2008 2:55 pm    Post subject: [C# HELP] Sendmessage FAIL. Reply with quote

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
View user's profile Send private message AIM Address
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Fri Jul 25, 2008 3:15 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
samuri25404
Grandmaster Cheater
Reputation: 7

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

PostPosted: Fri Jul 25, 2008 3:53 pm    Post subject: Reply with quote

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?

_________________
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
Fuzz
Grandmaster Cheater
Reputation: 0

Joined: 12 Nov 2006
Posts: 531

PostPosted: Fri Jul 25, 2008 5:34 pm    Post subject: Reply with quote

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
Code:
Back to top
View user's profile Send private message AIM Address
Odecey
Master Cheater
Reputation: 1

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Sat Jul 26, 2008 7:05 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
AngelSl
Cheater
Reputation: 0

Joined: 13 Jul 2007
Posts: 34

PostPosted: Sun Jul 27, 2008 8:10 am    Post subject: Reply with quote

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
View user's profile Send private message
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Sun Jul 27, 2008 8:27 am    Post subject: Reply with quote

It's not "System.Interop.RuntimeServices", like Odecey said, it's "System.Runtime.InteropServices".
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 Jul 29, 2008 12:11 pm    Post subject: Reply with quote

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

_________________
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
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
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