레이블이 System Programming인 게시물을 표시합니다. 모든 게시물 표시
레이블이 System Programming인 게시물을 표시합니다. 모든 게시물 표시

2010년 1월 4일 월요일

[Scrap] Struct SYSTEM_INFO (System Programming)


It's from MSDN, and here is the link:
http://msdn.microsoft.com/en-us/library/ms724958(VS.85).aspx



SYSTEM_INFO Structure

Contains information about the current computer system. This includes the architecture and type of the processor, the number of processors in the system, the page size, and other such information.

Syntax

C++
typedef struct _SYSTEM_INFO {
  union {
    DWORD dwOemId;
    struct {
      WORD wProcessorArchitecture;
      WORD wReserved;
    } ;
  } ;
  DWORD     dwPageSize;
  LPVOID    lpMinimumApplicationAddress;
  LPVOID    lpMaximumApplicationAddress;
  DWORD_PTR dwActiveProcessorMask;
  DWORD     dwNumberOfProcessors;
  DWORD     dwProcessorType;
  DWORD     dwAllocationGranularity;
  WORD      wProcessorLevel;
  WORD      wProcessorRevision;
}SYSTEM_INFO;

Members

dwOemId

An obsolete member that is retained for compatibility. Applications should use the wProcessorArchitecture branch of the union.

wProcessorArchitecture

The processor architecture of the installed operating system. This member can be one of the following values.

Value Meaning
PROCESSOR_ARCHITECTURE_AMD64
9

x64 (AMD or Intel)

PROCESSOR_ARCHITECTURE_IA64
6

Intel Itanium Processor Family (IPF)

PROCESSOR_ARCHITECTURE_INTEL
0

x86

PROCESSOR_ARCHITECTURE_UNKNOWN
0xffff

Unknown architecture.

 

wReserved

This member is reserved for future use.

dwPageSize

The page size and the granularity of page protection and commitment. This is the page size used by the VirtualAlloc function.

lpMinimumApplicationAddress

A pointer to the lowest memory address accessible to applications and dynamic-link libraries (DLLs).

lpMaximumApplicationAddress

A pointer to the highest memory address accessible to applications and DLLs.

dwActiveProcessorMask

A mask representing the set of processors configured into the system. Bit 0 is processor 0; bit 31 is processor 31.

dwNumberOfProcessors

The number of physical processors in the system. To retrieve the number of logical processors, use the GetLogicalProcessorInformation function.

dwProcessorType

An obsolete member that is retained for compatibility. Use the wProcessorArchitecture, wProcessorLevel, and wProcessorRevision members to determine the type of processor.

Name Value

PROCESSOR_INTEL_386

386

PROCESSOR_INTEL_486

486

PROCESSOR_INTEL_PENTIUM

586

PROCESSOR_INTEL_IA64

2200

PROCESSOR_AMD_X8664

8664

 

dwAllocationGranularity

The granularity for the starting address at which virtual memory can be allocated. For more information, see VirtualAlloc.

wProcessorLevel

The architecture-dependent processor level. It should be used only for display purposes. To determine the feature set of a processor, use the IsProcessorFeaturePresent function.

If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_INTEL, wProcessorLevel is defined by the CPU vendor.

If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_IA64, wProcessorLevel is set to 1.

wProcessorRevision

The architecture-dependent processor revision. The following table shows how the revision value is assembled for each type of processor architecture.

Processor Value
Intel Pentium, Cyrix, or NextGen 586 The high byte is the model and the low byte is the stepping. For example, if the value is xxyy, the model number and stepping can be displayed as follows:

Model xx, Stepping yy

Intel 80386 or 80486 A value of the form xxyz.

If xx is equal to 0xFF, y - 0xA is the model number, and z is the stepping identifier.

If xx is not equal to 0xFF, xx + 'A' is the stepping letter and yz is the minor stepping.

 

Examples

For an example, see Getting Hardware Information.

Requirements

Minimum supported client Windows 2000 Professional
Minimum supported server Windows 2000 Server
Header Winbase.h (include Windows.h)

2009년 12월 25일 금요일

[Scrap] length of characters (I/O Function)



strlen, strlen_l, wcslen, wcslen_l, _mbslen, _mbslen_l, _mbstrlen, _mbstrlen_l



 prototype
size_t strlen( const char *str );
size_t strlen_l( const char *str, _locale_t locale );

size_t wcslen( const wchar_t *str );
size_t wcslen_l( const wchar_t *str, _locale_t locale );

size_t _mbslen( const unsigned char *str );
size_t _mbslen_l( const unsigned char *str, _locale_t locale );

 size_t _mbstrlen( const char *str );
 size_t _mbstrlen_l( const char *str, _locale_t locale );




Each of these functions returns the number of characters in str, excluding the terminal NULL. No return value is reserved to indicate an error, except for _mbstrlen, which returns -1 if the string contains an invalid multibyte character.



 Example from MSDN
// crt_strlen.c
// Determine the length of a string. For the multi-byte character
// example to work correctly, the Japanese language support for
// non-Unicode programs must be enabled by the operating system.

#include <string.h>
#include <locale.h>

int main()
{
   char* str1 = "Count.";
   wchar_t* wstr1 = L"Count.";
   char * mbstr1;
   char * locale_string;

   // strlen gives the length of single-byte character string
   printf("Length of '%s' : %d\n", str1, strlen(str1) );

   // wstrlen gives the length of a wide character string
   wprintf(L"Length of '%s' : %d\n", wstr1, wcslen(wstr1) );

   // A multibyte string: [A] [B] [C] [katakana A] [D] [\0]
   // in Code Page 932. For this example to work correctly,
   // the Japanese language support must be enabled by the
   // operating system.
   mbstr1 = "ABC" "\x83\x40" "D";

   locale_string = setlocale(LC_CTYPE, "Japanese_Japan");

   if (locale_string == NULL)
   {
      printf("Japanese locale not enabled. Exiting.\n");
      exit(1);
   }
   else
   {
      printf("Locale set to %s\n", locale_string);
   }

   // _mbslen will recognize the Japanese multibyte character if the
   // current locale used by the operating system is Japanese
   printf("Length of '%s' : %d\n", mbstr1, _mbslen(mbstr1) );

   // _mbstrlen will recognize the Japanese multibyte character
   // since the CRT locale is set to Japanese even if the OS locale
   // isnot.
   printf("Length of '%s' : %d\n", mbstr1, _mbstrlen(mbstr1) );
   printf("Bytes in '%s' : %d\n", mbstr1, strlen(mbstr1) );  
 
}



 Its result
Length of 'Count.' : 6
Length of 'Count.' : 6
Length of 'ABCァD' : 5
Length of 'ABCァD' : 5
Bytes in 'ABCァD' : 6







You can see the same thing at this page:
http://msdn.microsoft.com/en-us/library/78zh94ax.aspx

from MSDN