|
Thanks Jijo,
My concern is just I want to define a safe length so that there is no machine name longer than my defined length.
And there is no such built-in macro to represent max length?
regards,
George
|
|
|
|
|
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thanks CPallini!
My question is whether there is a macro which represents the max machine name length -- I need such macro to define buffer length to retrieve machine name using this API. Any comments?
If there is not such a built-in macro, I am not sure whether use 255? 1024 or something else is better?
regards,
George
|
|
|
|
|
George_George wrote: Any macro used to represent computer name max length
I don't know if there is a #define available for this DNS limit. But RFC-2181 Section 11. - Name syntax
[^] states that the maximum length of the entire DNS record is 255 bytes/octets with each section limited to 64 bytes including the separator which would be 63 usable characters. You should be safe declaring a buffer 64 characters which would include the NULL terminator.
George_George wrote: MAX_COMPUTERNAME_LENGTH is too small and just 15 characters.
Thats because its the NetBios name limit, a Microsoft invention which has nothing to do with the DNS hostname.
One last note.. if you want to support international domain names[^] you should declare your buffer as wchar_t. The same maximum length restrictions apply.
Best Wishes,
-David Delaune
|
|
|
|
|
Thanks for your advice, David!
Let us looking forward to finding whether someone here has good knowledge whether there is such a built-in macro?
regards,
George
|
|
|
|
|
Found them in the Platform SDK file:
#include <Windns.h>
You will find:
#define DNS_MAX_NAME_LENGTH (255)
#define DNS_MAX_LABEL_LENGTH (63)
#define DNS_MAX_NAME_BUFFER_LENGTH (256)
#define DNS_MAX_LABEL_BUFFER_LENGTH (64)
Best Wishes,
-David Delaune
|
|
|
|
|
Cool, David!
I think I should use 64.
regards,
George
|
|
|
|
|
Hi George,
the answer is no; there is no macro/constant giving max length.
However there is a Win32 function that gives you the max length, it is called GetComputerNameEx ; just give it a buffer=NULL and a size variable whose value is set to zero. Upon return, read that very same size value, then allocate a sufficiently large buffer, and call GetComputerNameEx again.
BTW: this is a common pattern in Win32: first ask for size, then allocate, then ask for data using the same function.
|
|
|
|
|
Thanks Luc,
I am just surprised there is no such macro defined on Windows as built-in macro.
regards,
George
|
|
|
|
|
Some parameters just aren't constant, e.g. they depend on installation choices, available hardware, etc. In these cases you need to actually run some code to determine maximum sizes. Not sure why it would be dynamic in this case, but that is the author's decision after all.
|
|
|
|
|
|
OK.
does it match the return value when size zero was given?
|
|
|
|
|
|
Your answer is in the link YOU provided
"The length of the name may be greater than MAX_COMPUTERNAME_LENGTH
characters because DNS allows longer names. To ensure that this buffer
is large enough, set this parameter to NULL and use the required buffer
size returned in the lpnSize parameter."
As many others have mentioned, that's the proper way to use the API.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks Mark!
You mean call this API twice? I showed my understanding of your points in the following pseudo code. Any comments? Does it what you mean?
int size;
GetComputerNameEx(
__in COMPUTER_NAME_FORMAT NameType,
NULL,
&size
);
buffer = new char[size+1];
GetComputerNameEx(
__in COMPUTER_NAME_FORMAT NameType,
buffer,
&size
);
regards,
George
|
|
|
|
|
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++
|
|
|
|
|
|
Hi,
I am using VLC plugin 2 Active X control in vc++ sample application.
I can able to see live video, using CVLCPlaylist.add() method call.
How to take snapshot?
Any help ?
|
|
|
|
|
printscreen button
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
Hi,
Thanks for your reply.
how to set the snapshot path?
is there any default path for snapshot?
I tried your suggestion for taking snapshot.
But it is not working.
Is there any possibility to use CVLCVideo::takeSnapshot() ?
|
|
|
|
|
I dont know if this is the right forum to post this query
i wanted to know if we can achieve inheritance and encapsulation in C.
|
|
|
|
|
With some effort, you can mimic inheritance.
Use of structs effectively gets you encapsulation.
|
|
|
|
|
a little more explanation will be of great help.
|
|
|
|
|
struct base<br />
{<br />
};<br />
<br />
struct derived : public base<br />
{<br />
};
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
?
struct derived : public base
that is not C
|
|
|
|