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 


GetCompuerName error
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Sun Jun 22, 2008 4:56 pm    Post subject: Reply with quote

oib111 wrote:
When I try outputting the value I get an error. Here's my code:

Code:

cout<<"User Currently Logged In: "<<*lpBuffer<<"\n\n";


Use the following instead:

Code:
cout << "User currently logged in: " << (LPSTR)lpBuffer << "\n\n";

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Mon Jun 23, 2008 5:21 am    Post subject: Reply with quote

Wiccaan wrote:
GetUserName:
http://msdn.microsoft.com/en-us/library/ms724432(VS.85).aspx

Using TCHAR:
Code:
#include <windows.h>
#include <lmcons.h> // For UNLEN (As described on MSDN.)
#include <tchar.h>
#include <stdio.h>

int main( int argc, TCHAR* argcv[] )
{
   TCHAR tszUser[ UNLEN+1 ];
   DWORD dwSize = UNLEN+1;
   GetUserName( tszUser, &dwSize );
   _tprintf( tszUser );
   return 0;
}


Edit: Oib your code wont work as you are trying to output to the pointer not the actual contents. All yours will do is output the pointer to the string.


I did Excalty (almost) like that, but when i ran it it didn't show me anything -.-" i'll try this later thanks.
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

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

PostPosted: Mon Jun 23, 2008 5:35 am    Post subject: Reply with quote

Code:

char lpBuffer[32767];
DWORD size = 32767;
GetUserName(lpBuffer, &size);
printf(lpBuffer);

_________________


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
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Mon Jun 23, 2008 12:38 pm    Post subject: Reply with quote

oib111 wrote:
Code:

char lpBuffer[32767];
DWORD size = 32767;
GetUserName(lpBuffer, &size);
printf(lpBuffer);


It is better to use the defined macros given to you by the system includes for variable sizes for such things as on different versions of Windows, the sizes can change. Different compilers also have different predefined variables such as _WIN32_WINNT. While the default for this is 0x501 on VS2005, the default for it in VS2008 is 0x600.

For this specific API, the param size cannot exceed 32767, but in other cases that could lead to non-working code.

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

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

PostPosted: Mon Jun 23, 2008 6:46 pm    Post subject: Reply with quote

Rot1 wrote:
Wiccaan wrote:
GetUserName:
http://msdn.microsoft.com/en-us/library/ms724432(VS.85).aspx

Using TCHAR:
Code:
#include <windows.h>
#include <lmcons.h> // For UNLEN (As described on MSDN.)
#include <tchar.h>
#include <stdio.h>

int main( int argc, TCHAR* argcv[] )
{
   TCHAR tszUser[ UNLEN+1 ];
   DWORD dwSize = UNLEN+1;
   GetUserName( tszUser, &dwSize );
   _tprintf( tszUser );
   return 0;
}


Edit: Oib your code wont work as you are trying to output to the pointer not the actual contents. All yours will do is output the pointer to the string.


I did Excalty (almost) like that, but when i ran it it didn't show me anything -.-" i'll try this later thanks.


Did you try doing the little

Code:

cin.get();


thing, or whatever, to wait for the user?

_________________
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
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Tue Jun 24, 2008 4:14 am    Post subject: Reply with quote

samuri25404 wrote:
Rot1 wrote:
Wiccaan wrote:
GetUserName:
http://msdn.microsoft.com/en-us/library/ms724432(VS.85).aspx

Using TCHAR:
Code:
#include <windows.h>
#include <lmcons.h> // For UNLEN (As described on MSDN.)
#include <tchar.h>
#include <stdio.h>

int main( int argc, TCHAR* argcv[] )
{
   TCHAR tszUser[ UNLEN+1 ];
   DWORD dwSize = UNLEN+1;
   GetUserName( tszUser, &dwSize );
   _tprintf( tszUser );
   return 0;
}


Edit: Oib your code wont work as you are trying to output to the pointer not the actual contents. All yours will do is output the pointer to the string.


I did Excalty (almost) like that, but when i ran it it didn't show me anything -.-" i'll try this later thanks.


Did you try doing the little

Code:

cin.get();


thing, or whatever, to wait for the user?


nope, what is cin. ? a structure?
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
Goto page Previous  1, 2
Page 2 of 2

 
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