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 


convert from delphi to C++

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

Joined: 20 Apr 2007
Posts: 668

PostPosted: Mon Apr 21, 2008 2:37 pm    Post subject: convert from delphi to C++ Reply with quote

How would you convert this code, from Delphi to C++?, ive got the postmessage function to work (well... it took me some time to find out i had to change "Postmessage" to "PostMessage".. forgot C++ was case sensitive...), but i dont know how to do the "for i:= 1 to Length(g) do" and the "integer(pChar(G[i]))" parts... could any1 please help me?

Code:
var
  i: integer;
  g: string;
begin
  g:= 'asd';
  for i:= 1 to Length(g) do
  Postmessage(FindWindowex(FindWindow('Notepad', nil),0,nil,nil),WM_Char,integer(pChar(G[i])),1);
end;
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Mon Apr 21, 2008 2:40 pm    Post subject: Reply with quote

int i;
char *g;
HWND l;

void main()
{
l = FindWindow(NULL,"Notepad");
g = "asd";
for (i = 1; strlen(g))
PostMessage(l,WM_CHAR,(int)PCHAR(g[i]),0);
}

try it
Back to top
View user's profile Send private message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Mon Apr 21, 2008 2:46 pm    Post subject: Reply with quote

It just freezes Notepad..., well, i gtg now Sad, sorry, but ty anyways, atleast i succeded building it this time Very Happy
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Mon Apr 21, 2008 3:26 pm    Post subject: Reply with quote

Code:
#include <windows.h>
int i;
char g[] = "butts";
HWND handle;

int main()
{
   handle = FindWindow("Notepad", NULL);
   handle = FindWindowEx(handle, NULL, "Edit", NULL);
   for(i = 0; i < sizeof(g); i++){
      PostMessage(handle, WM_CHAR, (WPARAM)g[i], 0);
   }
   return 0;
}
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Mon Apr 21, 2008 3:50 pm    Post subject: Reply with quote

I made something that is exactly what you want for a friend of mine.

Ive attached the binary and source.



The Extension 'rar' was deactivated by an board admin, therefore this Attachment is not displayed.


The Extension 'rar' was deactivated by an board admin, therefore this Attachment is not displayed.


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

Joined: 20 Apr 2007
Posts: 668

PostPosted: Tue Apr 22, 2008 12:02 am    Post subject: Reply with quote

lurc wrote:
I made something that is exactly what you want for a friend of mine.

Ive attached the binary and source.


Gives me an error...:

Code:
1>main.cpp
1>Linking...
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Documents and Settings\*****\My Documents\Visual Studio 2008\Projects\hkajd\Debug\hkajd.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Documents and Settings\*****\My Documents\Visual Studio 2008\Projects\hkajd\hkajd\Debug\BuildLog.htm"
1>hkajd - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Last edited by Anden100 on Tue Apr 22, 2008 11:52 am; edited 1 time in total
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Tue Apr 22, 2008 3:53 am    Post subject: Reply with quote

You are trying to compile it in .NET?

PS, Anders, You censored out 1 of 2 instances of your name..
Back to top
View user's profile Send private message MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8586
Location: 127.0.0.1

PostPosted: Tue Apr 22, 2008 6:41 am    Post subject: Reply with quote

Start Visual Studio, choose New Project, Choose Win32 Project.
At the Win32 Application Wizard window, click on Application Settings, and choose:
- Console Application
- Check Blank Project
Then click finish.

Once Visual Studio loads, goto:
Project -> Add New Item... -> Visual C++ -> C++ File (.cpp)
Name it anything you want, preferably 'main.cpp' since its the main project file.

Example code using TCHAR:

Code:
#include <windows.h>
#include <tchar.h>

int main( int argc, TCHAR* argcv[] )
{
   UNREFERENCED_PARAMETER( argc );

   HWND hWndNotepadEdit = NULL;
   hWndNotepadEdit = FindWindowEx( FindWindow( _T("Notepad"), NULL ), NULL, _T("Edit"), NULL );
   if( INVALID_HANDLE_VALUE != hWndNotepadEdit )
      for( int x=0; x<static_cast<int>(_tcslen(argcv[0])); x++ )
         PostMessage( hWndNotepadEdit, WM_CHAR, (WPARAM)(char)argcv[0][x], (LPARAM)NULL );
   return 0;
}


This code will not work for Unicode character set because of how Notepad is compiled. WM_CHAR is designed to send only the given character set to a window of the same character set.

To change the character set you compile in, goto:
Project -> Properties (Hit ALT+F7 if you want) -> Configuration Properties -> General
On the right, you should see 'Character set', change the value to the right of that to 'Use Multi-byte Character Set'.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Tue Apr 22, 2008 7:27 am    Post subject: Reply with quote

Hmm, wic, you didnt need to write a whole actual tutorial O.o, do you think i would like to know about this, without ANY knowledge in C++??, ive done those booring tutorials with calculators and so...
-----------------------

edit:
how do i change the text, that is send to Notepad?, it sends this:
"c:\Documents and Settings\ill cencor this time Razz\My Documents\Visual Studio 2008\Projects\hkajd\Debug\hkajd.exe lolz...


Last edited by Anden100 on Tue Apr 22, 2008 11:58 am; edited 1 time in total
Back to top
View user's profile Send private message
--Pillboi--
Grandmaster Cheater Supreme
Reputation: 0

Joined: 06 Mar 2007
Posts: 1383
Location: I don't understand the question. Is this a 1 to 10 thing?

PostPosted: Tue Apr 22, 2008 11:38 am    Post subject: Reply with quote

Anden100 wrote:
Code:
1>C:\Documents and Settings\A*****\My Documents\Visual Studio 2008\Projects\hkajd\Debug\hkajd.exe

Change your post before to get rid of your name!

_________________

Enter darkness, leave the light, Here be nightmare, here be fright...
Earth and Water, Fire and Air. Prepare to meet a creature rare.
Enter now if you dare, Enter now the dragon's lair.
Back to top
View user's profile Send private message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Tue Apr 22, 2008 11:53 am    Post subject: Reply with quote

--Pillboi-- wrote:
Anden100 wrote:
Code:
1>C:\Documents and Settings\A*****\My Documents\Visual Studio 2008\Projects\hkajd\Debug\hkajd.exe

Change your post before to get rid of your name!


I dont really care, its my parents who wants me to..., well however, i dont think any1 would track me down and kill me, and steal all of my money, using my first name O.o
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8586
Location: 127.0.0.1

PostPosted: Tue Apr 22, 2008 5:21 pm    Post subject: Reply with quote

Anden100 wrote:
Hmm, wic, you didnt need to write a whole actual tutorial O.o, do you think i would like to know about this, without ANY knowledge in C++??, ive done those booring tutorials with calculators and so...
-----------------------

edit:
how do i change the text, that is send to Notepad?, it sends this:
"c:\Documents and Settings\ill cencor this time Razz\My Documents\Visual Studio 2008\Projects\hkajd\Debug\hkajd.exe lolz...


It uses the default first argument in a console application, which is the executables path. The lines:

Code:
      for( int x=0; x<static_cast<int>(_tcslen(argcv[0])); x++ )
         PostMessage( hWndNotepadEdit, WM_CHAR, (WPARAM)(char)argcv[0][x], (LPARAM)NULL );


This is what you want to edit.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
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