| View previous topic :: View next topic |
| Author |
Message |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
Posted: Sun Jun 22, 2008 4:56 pm Post subject: |
|
|
| 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 |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Mon Jun 23, 2008 5:21 am Post subject: |
|
|
| 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 |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Mon Jun 23, 2008 5:35 am Post subject: |
|
|
| 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 |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
Posted: Mon Jun 23, 2008 12:38 pm Post subject: |
|
|
| 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 |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Mon Jun 23, 2008 6:46 pm Post subject: |
|
|
| 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
thing, or whatever, to wait for the user?
_________________
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Tue Jun 24, 2008 4:14 am Post subject: |
|
|
| 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
thing, or whatever, to wait for the user? |
nope, what is cin. ? a structure?
|
|
| Back to top |
|
 |
|