| View previous topic :: View next topic |
| Author |
Message |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Jun 22, 2008 10:20 am Post subject: GetCompuerName error |
|
|
Solved...new problem time =)
| oib111 wrote: | Got it working, just had to change the structure, guess MSDN was wrong. Anyway, I have a different problem, I cant get my computer name. It says:
| VC++ wrote: |
lpBuffer is being used without being initialized.
|
Then when I initialize it(=NULL or ="") I get this error:
| VC++ wrote: |
First-chance exception at 0x7c8216b7 in COMPINFO.exe: 0xC0000005: Access violation reading location 0x00000013.
Unhandled exception at 0x7c8216b7 in COMPINFO.exe: 0xC0000005: Access violation reading location 0x00000013.
|
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
Last edited by oib111 on Sun Jun 22, 2008 10:47 am; edited 1 time in total |
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Sun Jun 22, 2008 10:37 am Post subject: |
|
|
Try
| Code: | | GetVersionEx(&osverinfo); |
_________________
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Jun 22, 2008 10:40 am Post subject: |
|
|
Got it working, just had to change the structure, guess MSDN was wrong. Anyway, I have a different problem, I cant get my computer name. It says:
| VC++ wrote: |
lpBuffer is being used without being initialized.
|
Then when I initialize it(=NULL or ="") I get this error:
| VC++ wrote: |
First-chance exception at 0x7c8216b7 in COMPINFO.exe: 0xC0000005: Access violation reading location 0x00000013.
Unhandled exception at 0x7c8216b7 in COMPINFO.exe: 0xC0000005: Access violation reading location 0x00000013.
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Sun Jun 22, 2008 10:55 am Post subject: |
|
|
is buffer big enough and is size the size of the buffer?
It should be something like
| Code: | TCHAR buffer[64];
GetComputerName(buffer, 64/sizeof(TCHAR)); |
_________________
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Jun 22, 2008 11:04 am Post subject: |
|
|
I did this:
| Code: |
LPSTR lpBuffer = NULL;
GetComputerName(lpBuffer, (PDWORD)MAX_COMPUTERNAME_LENGTH+1);
cout<<"Computer Name: "<<lpBuffer<<"\n\n";
|
What if I did this:
| Code: |
char lpBuffer[MAX_COMPUTERNAME_LENGTH];
GetComputerName(lpBuffer, MAX_COMPUTERNAME_LENGTH/sizeof(char));
cout<<"Computer Name: "<<lpBuffer<<"\n\n";
|
EDIT:
The second code doesn't work Btw, isn't TCHARs for Unicode (I do everything MBCS)
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Jun 22, 2008 11:27 am Post subject: |
|
|
MSDN does everything in Unicode while I do everything in MBCS, and I don't know the equivalent to INFO_BUFFER_SIZE.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Sun Jun 22, 2008 11:27 am Post subject: |
|
|
| Talking about GetComputerName, i need help with GetUserName API, any ideas ? -.-" (C)
|
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Sun Jun 22, 2008 12:03 pm Post subject: |
|
|
If the API uses unicode, you're forced to use unicode, too. If you really don't want to do that, you can try grabbing the name from the registry yourself.
Or try GetComputerNameA(). It takes the sameparameters as GetComputerName().
_________________
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Sun Jun 22, 2008 12:24 pm Post subject: |
|
|
| Rot1 wrote: | | Talking about GetComputerName, i need help with GetUserName API, any ideas ? -.-" (C) |
I already told you.
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Sun Jun 22, 2008 12:46 pm Post subject: |
|
|
| noz3001 wrote: | | Rot1 wrote: | | Talking about GetComputerName, i need help with GetUserName API, any ideas ? -.-" (C) |
I already told you. |
Didn't compile well, any ideas lol ?
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Jun 22, 2008 12:50 pm Post subject: |
|
|
Hehe. I got it working. Here's a snipped Rot:
| Code: |
LPSTR *lpBuffer = new LPSTR;
DWORD size = 32767;
GetWindowsDirectory((LPSTR)lpBuffer, MAX_PATH);
cout<<"Windows Directory: "<<lpBuffer<<"\n";
*lpBuffer = NULL;
GetSystemDirectory((LPSTR)lpBuffer, MAX_PATH);
cout<<"System Directory: "<<lpBuffer<<"\n";
*lpBuffer = NULL;
GetUserName((LPSTR)lpBuffer, &size);
cout<<"User Currently Logged In: "<<lpBuffer<<"\n\n";
lpBuffer = NULL;
delete lpBuffer;
|
Reason I'm using dynamic memory is because this is in a switch case statement and I didn't want it to declare a new variable in memory each time someone chose this option.
_________________
| 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: 8587 Location: 127.0.0.1
|
Posted: Sun Jun 22, 2008 1:03 pm Post subject: |
|
|
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.
_________________
- Retired. |
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Jun 22, 2008 1:45 pm Post subject: |
|
|
When I try outputting the value I get an error. Here's my code:
| Code: |
cout<<"User Currently Logged In: "<<*lpBuffer<<"\n\n";
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
|