Hey what's up all. I started with vB about 2 weeks ago, it's so much fun. I'm learnin quick. I have come here and other places for so much help already, never posted though, I thank all you gurus...heh. But, it seems I have a dillema. I have this short c++ code that I need ported to vB, if thats even possible. All it does is send commands to a game console with the command Console("COMMANDHERE"). I would greatly appreciate help on this. I don't know what I can give in return for your experties, I'm not skilled enough in vB yet to make anything for ya guys. We can talk if I get replies. Heh.. See ya guys later.
P.S. This is the C++ code to send commands to a game console.
**************************************************** inline void Console(char *cgCmd)
{
HWND MohCons = FindWindow(0, "Mohaa Console");
EnumChildWindows(MohCons, EnumChildSendCommandProc,(LPARAM)cgCmd);
}
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function EnumChildWindows Lib "user32" Alias "EnumChildWindows" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
'in a Form:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Sub Console ()
Dim MohCons As Long
Me.AutoRedraw = True
MohCons = FindWindow(vbNullString, "Mohaa Console")
EnumChildWindows MohCons, AddressOf EnumChildSendCommandProc, ByVal 0&
End Sub
'in a Module:
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Function EnumChildSendCommandProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim lpClassName As String
Dim L As Long
lpClassName = Space$(1024)
L = GetClassName (hwnd, lpClassName, 1024)
If (Left$(lpClassName, L) = "Edit") Then Exit Sub
If (GetWindowLong(hwnd, GWL_STYLE) And ES_READONLY) Then Exit Sub
Form1.Print Hex$(LParam)
'continue enumeration:
EnumChildProc = 1
End Function
Wow. I can't believe you guys actually wrote those huge snippets for me. You don't know how much I appreciate this. Thank you. But ok. I have a couple questions. I dont have any idea what to do in converting things from c++, so i dont know where to put the constant values and that. Once this is figured out, I will learn off of what you guys did. And it might be my last time buggin ya guys. For the second one, I tried a button:
Private Sub Command1_Click()
Console ("set name x39rox")
End Sub
And i get this error:
Wrong number of arguments or invalid property assignment.
And it points to the console part. So i assume thats not the correct command for it. Can u write a simple button for that? If this is possible, and gets complete, i'll be like a boy at a candy shop. Hah. Tty guys later. Thank you again compie and kahn.
I get the same error. Man, I'm trying everything I can come up with, which isn't alot, but I'm tryin.
Edit: I just thought of something. Shouldnt it look for the main window name first (Medal of Honor Allied Assault), then look for the other window (MOHAA Console)?
Edit2: Ok guys, well I'm going to bed now (i was up all night trying to do this). Its 11:58am now here. Sheesh. Heh, I will probably dream of this too, lol. So, I am hoping to god that someone figures a way to do this, or make this. Good Luck guys. Thanks a ton again.
O yeah, this gives me an error in the first one:
Private Sub Console(String cgCmd)
The 'string' cant be there i think. ?
Last edited by x39rox; Jul 21st, 2003 at 12:02 PM.
This is giving you an error while trying to use the second method is because the second method does not take a parameter. As you can see the delcaration of the function is just simply
Console() with no arguments. The reason you are having an error trying to use the first one is this.
VB Code:
'Data type needs to be after the variable
Private Sub Console(String cgCmd)
'such as this
Private Sub Console(cgCmd as String)
When you do that it passes by reference as default, if you want to pass the variable by value you will need this
VB Code:
Private Sub Console(ByVal cgCmd as String)
Last edited by Maldrid; Jul 21st, 2003 at 03:15 PM.
Hm, that seemed to work. I get these zero's that come up on my form now when the game is not active. When the game is active, I get nothing that prints on the form, but it doesnt do the command. So we got half of it working I guess, lol. Anyone see a problem with it? I'm still thinkin it should look for the game window (Medal of Honor Allied Assaut) first and then look for a window inside the game (MOHAA Console) then send whatever command i specify to the game. Doesn't that seem logical? Well, you guys are the experts here, I'm just throwin out ideas. I'll check back today to see if ya guys have an answer. Thanks a whole lot again. It's so nice of yall.
No, I haven't. I have no idea what your even talking about, heh. Are you saying it shouldn't work until I put some values somewhere? I wan't this thing to work so bad man. Can you explain?
Originally posted by x39rox No, I haven't. I have no idea what your even talking about, heh. Are you saying it shouldn't work until I put some values somewhere? I wan't this thing to work so bad man. Can you explain?
Sorry!!! just got so lazy.. Thanx Maldrid...
VB has not got these constants defined bydefault like how C++ does.. therefore you have to define them by yourselves.....
Ok, I put that in there now. But, the darn thing still won't work. I must be causing you guys to scream at your computer...heh. I am sorry, I'm learning everytime you guys post though, so keep postin, lol. I just double checked with the person that made the c++ code and he said he's 150% sure the c++ code is right because he uses it all the time. So, either this is not possible, or something is wrong. <-- good inference...lol.
What method are you using? The first or second? I think you should be using the first method that manikhan posted because he allows you to pass a string. Also what exactly isn't working? Do you get an error? Or no error just doesn't do anything? Do you step through the code and make sure you are getting the right handle to the window? I am not sure but I think you can use Spy++ to find out what handle the window has to make sure it is getting the correct one.
Ok. Heres the scoop so far. I used spy++ like 5 mins before you posted that, weird eh? Anyway, it says caption name is "MOHAA Console". So that's correct. I was using compies before and it just wasnt doing anything, no errors either. Now I tried kahns, and I get an error here where i highlighted the red:
Dim ClassName As String * 1024
GetClassName hwnd, ClassName, Len(ClassName)
If ClassName = "Edit" Then EnumChildSendCommandProc = True
If ES_READONLY And GetWindowLong(hwnd, GWL_STYLE) Then EnumChildSendCommandProc = True
SendMessage hwnd, WM_SETTEXT, 0, lParam
SendMessage hwnd, WM_CHAR, 13, 0
EnumChildSendCommandProc = True
I put that^ in a module. I put this in a form:
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Sub Console(ByVal cgCmd As String)
Dim MohCons As Long
MohCons = FindWindow(0, "Mohaa Console")
EnumChildWindows MohCons, AddressOf EnumChildSendCommandProc, StrPtr(cgCmd)
End Sub
Private Sub Command1_Click()
Console "set name x39rox"
End Sub
EDIT: Ok, i fixed the error. Just had the stuff in the wrong places and that. But now, when I press the button, the program hangs for a bit, then just exits, w/o asking me to save or anything. I didnt have the game open, maybe thats the problem. Ill go check now...
Well, that wasnt it. Still does the same thing. Maybe I have all of the stuff in wrong places, mods, and forms, and that. Wow, Im so confused and frustrated. Hm, what in the world can be wrong?
Last edited by x39rox; Jul 22nd, 2003 at 12:05 PM.
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Function EnumChildSendCommandProc(hwnd As Long,lParam As Long) as Boolean
Dim ClassName As String*1024
GetClassName hwnd,className,len(className)
if className="Edit" Then EnumChildSendCommandProc=True
if ES_READONLY And GetWindowLong(hwnd,GWL_STYLE) Then EnumChildSendCommandProc=True
SendMessage hwnd,WM_SETTEXT,0,lParam
SendMessage hwnd,WM_CHAR,13,0
EnumChildSendCommandProc=True
End Function
Also use <vbcode> and </vbcode> when you are placing code. But put [ ] instead of < >
Ok, thanks for the vbcode tip. Now, I have the code in right places, put when I press the button, the program hangs for maybe 2 seconds, then quits, no questions asked. I can't see anything that's conflicting, probably because I'm not too good like you guys yet. Well actually, would it make a difference if the game was in windowed mode, and not full? I have it in windowed so I can press the button in vB, ya know?
I don't think it matters about the full or windowed mode. What I would do is step through your code in run time and see at what point it hangs. Also make sure it is getting a handle for the window when it calls findwindow. I never tried do anything like this myself, I a just trying to help you with what I do know
Ok, can you tell me how exactly to see what it finds when findwindow is called?
EDIT: Ok, well I found 'step into', but I only have one button and when I press it, it just locks for 2 secs and quits.
EDIT2: Well, I don't know if this is telling me what I just pressed, or a problem, but when I 'step into', then press the button, it highlights "Private Sub Command1_Click()" which is the button.
Last edited by x39rox; Jul 22nd, 2003 at 02:03 PM.
I am pretty sure you know about breakpoints right? Since you can put breakpoints in C++. Well you can do the same thing in VB. Just put a breakpoint on that line. Then run your program. Then hit the command button and when it reaches that line the program will stop and go into debug mode where you can run the code line by line. You use F8 to run a line of code. If you hit F5 it will run the rest of the code or run to the next breakpoint. Once you are in debug mode you can hit F8 to run the FindWindow line of code and then put your mouse pointer over the MohCons variable. Soon a tooltip popup will show up giving you the value of that variable.
To insert a breakpoint you can click on the left panel of the code screen on the line of code where you want the breakpoint. Or you can move your mouse cursor where you want the breakpoint to be, then go to Debug->Toggle Breakpoint, or move your mouse cursor to the line you want the breakpoint on and hit F9.
Ok I made you a form with a module in it to show you how to do it. Maybe you can look at it and apply it to what you want. Just create a new project and add the form and module to the project. Then set Form1 as the start up form in the properties. Then when you run it, if you click the command button notice how the command button text changes. I hope this helps.
Yea, it is. The main window is "Medal of Honor Allied Assault". Mohaa Console is in there. So Mohaa COnsole is a child. I'm doing more of the breakpoint thing also, and I found out that:
classname = "all these weird characters that show up as squares".
So, I guess there has to be another command to find a child window then?
Edit: That test you made helped me to change button labels when pressed, thank you. But I think Mohaa Console id a child window, as it is in the main window "Medal of Honor Allied Assault".
Last edited by x39rox; Jul 22nd, 2003 at 04:53 PM.
Well basicially what you are gonna do is find the parent window which is "Medal of Honor Allied Assault". Then when you call EnumChildWindows, it is going to go through each child window and set your text. The only child windows it won't is if it is readonly and if it is under the "Edit" Classname. So this is what your code should look like.
Well, that looks decent. Except it does the same thing as the other one, it hangs for 2 secs, then exits. I am truely sorry for the trouble you are going through just to help me out. I appreciate it so much, and I'm learning every step of the way. But, have you tried to run this?
I have checked EnumChildProc .. it's causing error.. so i used FindWindowEx function. What following code does ..It finds a window named Medal of Honor Allied Assault then it find among its children the window named "Mohaa Console" then in this window it finds a window which is not EDIT and which is NOT readonly... (well i just cudn't understand this part why is it so??)
then sending the message. All the Finding things are working fine.. (I didn't check with your parameters though)... SendMessage i just cudn't try....
I changed your most of the code (if not entire code) But i tried to solve the problem .... not to recorrect the code...
Tell me if it did..
VB Code:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function getClassName Lib "user32" Alias "GetClassNameA" (ByVal Hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const GWL_EXSTYLE = (-20)
Public Const WM_CHAR = &H102
Public Const WM_SETTEXT = &HC
Public Const ES_READONLY = &H800&
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal Hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal Hwnd As Long) As Long
Public Sub Console(cgCmd As String)
Dim MohCons As Long
Dim ParentWindow As Long
Dim ActualConsole As Long
ParentWindow = FindWindowEx(0, 0, vbNullString, "Medal of Honor Allied Assault")
Wow. Never seen that before. Uhm, it changed all my window names to a flashing square and some weird ascii text. Like it was looping, which i seen in the code. I couldnt stop i, so i had to restart. Hm. I cant believe you wrote all that. Man i wish i could do that, heh. Well, any ideas why it froze my comp? Lol, o yeah, it still didnt do the command. I talked with the guy that made the c++ code, and he said he THINKS Mohaa Console is a parent window. See, in the game u can press ` and the console will open. And its called MOhaa Console as well, which is why i said its a child. But there is also a console hat stays open while u play, which is what i think that code that he made uses. So, a direct perfect transformation of that c++ code that i posted into vB would work, i assume. What if anything can I do for you guys that are trying so hard for me, noone ever did this for me...ever. Well, if ya can, try to see what went wrong, and thing of somehting i can do for u guys. Thanks guys, check back later.
Ooops!!!!!!!! DAmn it!!
in the statement right after Do Replace actualwindow with ActualConsole
ActualConsole = FindWindowEx(MohCons, actualwindow, vbNullString, vbNullString)
Lol, well now when I press the button, EVERY one of my windows gets its name changed to some weird ascii text. No freezing tho, just looks like someone hacked my computer, lol.
WM_SETTEXT msg behaves differently for different types of classes....If you will send this message to a window it will try to change the Caption of the window(this is what it is doing for u).. if sent to a textbox it will write the text within the textbox..What i think Mohaa Console should be an Edit Window (TextField) then when you send this message to it.... the text will be entered then you are sending WM_CHAR to mimic Enter effect....Am i Right...Can you send me That Gaming software (Mohaaa) at [email protected]??? I will check my coding with real world parameters
well.. if yes tell me so that i check my this account.....
Well, its a real game. 50 bucks if your a nice guy... If your a guy that knows some things, you can get it for cheaper, maybe even for nothing.... That would be GREAT if you could 'aquire it' and work with it. Thanks for ALL yur help so far man, i've learned alot. I might post on another forum, see if anyone can get it workin. Thanks again man.
Excuse MEeeeeee!!!! When u say "I will try another forum" you insult US (not United States.. US means US..WE)
OK!!! I don't require the game... i will mimic one and then will do whatever you want and will send that to u... Atlast this is the question of our PRESTIGE...
(JUST KIDDING)
Except for the promise that i'll look into your problem more..
Wow. Your really gung-ho about this. That's so cool. You can't even think on how much I appreciate this. I know I've said it alot, but I can't say it enough. Thank you so much. I have to get ready for work now, I'll check back when I get home.
Here you go... The Zip file below contains an Exe and a vb project. when you run that exe A parent window comes which contains Mohaa Console window which contains a textbox which contains NOthing .. Run this exe then
Run the project and click the Command1 button.. and see what happens..
Oopss.. silly me.. see next msg for the zip file
Last edited by moinkhan; Jul 25th, 2003 at 01:26 AM.
Wow. Well I found two things. This code rocks btw. Anyway, you have to start the the mohaa mimic first THEN start the button. Then it works, if u dont do it that way, it wont. Second, it works perfect in the mimic, but now in the game sadly, it doesnt. So, what I'm thinking is use the same method, just make Mohaa Console a parent, like its own window. And make the command send right to the window "Mohaa Console" instead of going through "Medal of Honor Allied Assault" first. I was told by the guy that gave me the c++ code that thats how his works. If c++ can send to it as a parent, then vB can. So, try that. Man, I wish I could like give you money or something, lol. I feel so bad for asking you for this stuff. Whats your aim or msn handle if you have one or the other. We can talk more on there and maybe arrange for me to give you something, heh. I thank you so much. Never have I ever gone to a forum and gotten this much help. Never. VERY good words go out for this one, all because of you . Well, GL man. O btw, my msn = [email protected]