Click here to Skip to main content
15,908,172 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: computer name length issue Pin
George_George17-Dec-08 1:55
George_George17-Dec-08 1:55 
GeneralRe: computer name length issue Pin
Luc Pattyn17-Dec-08 2:27
sitebuilderLuc Pattyn17-Dec-08 2:27 
GeneralRe: computer name length issue Pin
George_George17-Dec-08 2:30
George_George17-Dec-08 2:30 
GeneralRe: computer name length issue Pin
Luc Pattyn17-Dec-08 2:34
sitebuilderLuc Pattyn17-Dec-08 2:34 
GeneralRe: computer name length issue Pin
George_George17-Dec-08 2:43
George_George17-Dec-08 2:43 
AnswerRe: computer name length issue Pin
Mark Salsbery16-Dec-08 5:37
Mark Salsbery16-Dec-08 5:37 
GeneralRe: computer name length issue Pin
George_George17-Dec-08 1:59
George_George17-Dec-08 1:59 
GeneralRe: computer name length issue Pin
Mark Salsbery17-Dec-08 5:00
Mark Salsbery17-Dec-08 5:00 
George_George wrote:
You mean call this API twice?


Yes.

You may want to increment the size variable before the second call...
int size = 0;

GetComputerNameEx(
  __in     COMPUTER_NAME_FORMAT NameType,
   NULL,
  &size
);

size++;
buffer = new char[size];

GetComputerNameEx(
  __in     COMPUTER_NAME_FORMAT NameType,
   buffer,
  &size
);

Many APIs were designed to be called that way.

If you absolutely must use a static buffer length, in my experience,
a buffer size of 260 (MAX_PATH) has always been large enough.
Doing it as shown above is the safe, correct way, however.

Mark

Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

GeneralRe: computer name length issue Pin
George_George17-Dec-08 19:36
George_George17-Dec-08 19:36 
QuestionVLCPlugin2 - Snapshot Pin
kutti16-Dec-08 0:44
kutti16-Dec-08 0:44 
JokeRe: VLCPlugin2 - Snapshot Pin
Eytukan16-Dec-08 6:29
Eytukan16-Dec-08 6:29 
GeneralRe: VLCPlugin2 - Snapshot Pin
kutti16-Dec-08 17:27
kutti16-Dec-08 17:27 
QuestionInheritance in C Pin
Chandrasekharan P15-Dec-08 23:39
Chandrasekharan P15-Dec-08 23:39 
AnswerRe: Inheritance in C Pin
Stuart Dootson15-Dec-08 23:50
professionalStuart Dootson15-Dec-08 23:50 
GeneralRe: Inheritance in C Pin
Chandrasekharan P15-Dec-08 23:54
Chandrasekharan P15-Dec-08 23:54 
GeneralRe: Inheritance in C Pin
David Crow16-Dec-08 2:40
David Crow16-Dec-08 2:40 
GeneralRe: Inheritance in C Pin
Chris Losinger16-Dec-08 6:37
professionalChris Losinger16-Dec-08 6:37 
GeneralRe: Inheritance in C Pin
David Crow16-Dec-08 8:25
David Crow16-Dec-08 8:25 
QuestionRe: Inheritance in C Pin
CPallini16-Dec-08 0:03
mveCPallini16-Dec-08 0:03 
AnswerRe: Inheritance in C Pin
Chandrasekharan P16-Dec-08 0:20
Chandrasekharan P16-Dec-08 0:20 
AnswerRe: Inheritance in C Pin
Jijo.Raj16-Dec-08 0:16
Jijo.Raj16-Dec-08 0:16 
QuestionCMenu -> GetMenuString -> Get text and shortcut key seperate Pin
karhong15-Dec-08 22:57
karhong15-Dec-08 22:57 
AnswerRe: CMenu -> GetMenuString -> Get text and shortcut key seperate Pin
L. Madhavan15-Dec-08 23:01
L. Madhavan15-Dec-08 23:01 
GeneralRe: CMenu -> GetMenuString -> Get text and shortcut key seperate Pin
karhong15-Dec-08 23:04
karhong15-Dec-08 23:04 
GeneralRe: CMenu -> GetMenuString -> Get text and shortcut key seperate Pin
L. Madhavan15-Dec-08 23:10
L. Madhavan15-Dec-08 23:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.