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 


Visual C++ char array to system::string?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
DaHandy
Newbie cheater
Reputation: 0

Joined: 03 Nov 2007
Posts: 18

PostPosted: Wed Dec 01, 2010 8:18 am    Post subject: Visual C++ char array to system::string? Reply with quote

Hi!

I have just begun to use Visual Studio 2008 to create a keygen. However, I can't set textbox text because my variable is a char*. I have no idea how to convert a char* to system::string.

I have tried this:
Code:
int point1;
char* value1[5];
SIZE_T stBytes1 = 0;

//The code that gets window handle is here, stores it correctly to var phandle.

ReadProcessMemory(phandle, (LPVOID)0x005F2D2C, &point1, 4, &stBytes1);
ReadProcessMemory(phandle, (LPVOID)point1, &value1, 7, &stBytes1);

char* value1_p = (char*)value1;
String^ StrVal1 = String^(value1_p);
this->textBox1->Text = StrVal1;


The compiler tells me this:
Code:
Error   1   error C2275: 'System::String' : illegal use of this type as an expression


So what does that actually mean? What's wrong?

Thanks in advance!


EDIT: I also tried this:
Code:
String^ StrVal1;
StrVal1 = value1_p->toString();

Without success though. It gives me this error:
Code:
Error   1   error C2039: 'toString' : is not a member of 'System::SByte'
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Wed Dec 01, 2010 9:10 am    Post subject: Reply with quote

From Google:
http://stackoverflow.com/questions/56561/what-is-the-best-way-to-convert-between-char-and-systemstring-in-c-cli

Another suggestion:
Code:
char*p="test string...";
System::String *str(p);


I don't use VC++ so I can't guarantee any of these will work.

Also with your reading code, is the string(s) you are reading pointers or is it just a direct 7char string? If you are reading a 7char string your definition to value1 is incorrect. And you also didn't give enough space to read 7 bytes either.

Actually surprised to see someone using VC++ lol.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
DaHandy
Newbie cheater
Reputation: 0

Joined: 03 Nov 2007
Posts: 18

PostPosted: Wed Dec 01, 2010 9:30 am    Post subject: Reply with quote

Thanks for the reply!

Your code gives me 2 errors:
Code:
Error   1   error C3699: '*' : cannot use this indirection on type 'System::String'
Error   2   error C2440: 'initializing' : cannot convert from 'char *' to 'System::String ^'


So it's still not working.. :/
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Wed Dec 01, 2010 12:08 pm    Post subject: Reply with quote

c++/cli is barfo tbh
Back to top
View user's profile Send private message
DaHandy
Newbie cheater
Reputation: 0

Joined: 03 Nov 2007
Posts: 18

PostPosted: Wed Dec 01, 2010 1:04 pm    Post subject: Reply with quote

Yeah, seems like one...

I got an answer from another forum:
Code:
String^ StrVal1 = System::Runtime::InteropServices::Marshal::PtrToStringAnsi(IntPtr((value1));


But thanks for the help!
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