• Blog
  • Local Log
  • Tag Cloud
  • Key Log
  • Guestbook
  • RSS Feed
  • Write a Post
  • Admin

혹시 블로그 스킨이 깨져 보이시나요? 최신버전의 Internet Explorer(Windows용), Opera, Firefox를 사용해보세요.

EnumPrinters

Win32 API/MFC
2010/03/30 10:17
 

EnumPrinters


Description


The EnumPrinters function enumerates available printers, print servers, domains, or print providers.


C++ Syntax


BOOL EnumPrinters(

DWORD Flags,

LPTSTR Name,

DWORD Level,

LPBYTE pPrinterEnum,

DWORD cbBuf,

LPDWORD pcbNeeded,

LPDWORD pcReturned

);


PowerBASIC Syntax


FUNCTION EnumPrinters ( _

BYVAL Flags AS DWORD, _

BYREF Name AS ASCIIZ, _

BYVAL Level AS DWORD, _

BYREF pPrinterEnum AS ANY, _

BYVAL cbBuf AS DWORD, _

BYREF pcbNeeded AS DWORD, _

BYREF pcReturned AS DWORD _

) AS LONG


Unicode version:


FUNCTION EnumPrintersW ( _

BYVAL Flags AS DWORD, _

BYVAL Name AS DWORD, _

BYVAL Level AS DWORD, _

BYREF pPrinterEnum AS ANY, _

BYVAL cbBuf AS DWORD, _

BYREF pcbNeeded AS DWORD, _

BYREF pcReturned AS DWORD _

) AS LONG


Parameters


Flags


[in] Specifies the types of print objects that the function should enumerate. This value can be one or more of the following values.


Value

Meaning

PRINTER_ENUM_LOCAL

If the PRINTER_ENUM_NAME flag is not also passed, the function ignores the Name parameter, and enumerates the locally installed printers. If PRINTER_ENUM_NAME is also passed, the function enumerates the local printers on Name.


Windows 95/98/Me: The function will also enumerate network printers because they are handled by the local print provider.

PRINTER_ENUM_NAME

The function enumerates the printer identified by Name. This can be a server, a domain, or a print provider. If Name is NULL, the function enumerates available print providers.

PRINTER_ENUM_SHARED

The function enumerates printers that have the shared attribute. Cannot be used in isolation; use an OR operation to combine with another PRINTER_ENUM type.

PRINTER_ENUM_DEFAULT

Windows 95/98/Me: The function returns information about the default printer.

PRINTER_ENUM_CONNECTIONS

Windows NT/2000/XP: The function enumerates the list of printers to which the user has made previous connections.

PRINTER_ENUM_NETWORK

Windows NT/2000/XP: The function enumerates network printers in the computer's domain. This value is valid only if Level is 1.

PRINTER_ENUM_REMOTE

Windows NT/2000/XP: The function enumerates network printers and print servers in the computer's domain. This value is valid only if Level is 1.


If Level is 4, you can only use the PRINTER_ENUM_CONNECTIONS and PRINTER_ENUM_LOCAL constants.


Name


[in] If Level is 1, Flags contains PRINTER_ENUM_NAME, and Name is non-NULL, then Name is a pointer to a null-terminated string that specifies the name of the object to enumerate. This string can be the name of a server, a domain, or a print provider.


If Level is 1, Flags contains PRINTER_ENUM_NAME, and Name is NULL, then the function enumerates the available print providers.


If Level is 1, Flags contains PRINTER_ENUM_REMOTE, and Name is NULL, then the function enumerates the printers in the user's domain.


If Level is 2 or 5, Name is a pointer to a null-terminated string that specifies the name of a server whose printers are to be enumerated. If this string is NULL, then the function enumerates the printers installed on the local machine.


If Level is 4, Name should be NULL. The function always queries on the local machine.


When Name is NULL, setting Flags to PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS enumerates printers that are installed on the local machine. These printers include those that are physically attached to the local machine as well as remote printers to which it has a network connection.


When Name is not NULL, setting Flags to PRINTER_ENUM_LOCAL | PRINTER_ENUM_NAME enumerates the local printers that are installed on the server Name.


Level


[in] Specifies the type of data structures pointed to by pPrinterEnum. Valid values are 1, 2, 4, and 5, which correspond to the PRINTER_INFO_1, PRINTER_INFO_2, PRINTER_INFO_4, and PRINTER_INFO_5 data structures.


Windows 95/98/Me: The value can be 1, 2, or 5.


Windows NT/2000/XP: This value can be 1, 2, 4, or 5.


pPrinterEnum


[out] Pointer to a buffer that receives an array of PRINTER_INFO_1, PRINTER_INFO_2, PRINTER_INFO_4, or PRINTER_INFO_5 structures. Each structure contains data that describes an available print object.


If Level is 1, the array contains PRINTER_INFO_1 structures. If Level is 2, the array contains PRINTER_INFO_2 structures. If Level is 4, the array contains PRINTER_INFO_4 structures. If Level is 5, the array contains PRINTER_INFO_5 structures.


The buffer must be large enough to receive the array of data structures and any strings or other data to which the structure members point. If the buffer is too small, the pcbNeeded parameter returns the required buffer size.


Windows 95/98/Me: The buffer cannot receive PRINTER_INFO_4 structures. It can receive any of the other types.


cbBuf


[in] Specifies the size, in bytes, of the buffer pointed to by pPrinterEnum.


pcbNeeded


[out] Pointer to a value that receives the number of bytes copied if the function succeeds or the number of bytes required if cbBuf is too small.


pcReturned


[out] Pointer to a value that receives the number of PRINTER_INFO_1, PRINTER_INFO_2, PRINTER_INFO_4, or PRINTER_INFO_5 structures that the function returns in the array to which pPrinterEnum points.


Return Value


If the function succeeds, the return value is nonzero.


If the function fails, the return value is zero.


Remarks


Do not call this method in DllMain.


If EnumPrinters returns a PRINTER_INFO_1 structure in which PRINTER_ENUM_CONTAINER is specified, this indicates that there is a hierarchy of printer objects. An application can enumerate the hierarchy by calling EnumPrinters again, setting Name to the value of the PRINTER_INFO_1 structure's pName member.


The EnumPrinters function does not retrieve security information. If PRINTER_INFO_2 structures are returned in the array pointed to by pPrinterEnum, their pSecurityDescriptor members will be set to NULL.


To get information about the default printer, call the GetProfileString function with the section name string set to "windows" and the key name string set to "device". The returned string contains the name of the default printer, the name of the printer DRV file, and the port to which the printer is attached.


Windows 2000/XP: To get information about the default printer, call GetDefaultPrinter.


Windows NT/2000/XP: The PRINTER_INFO_4 structure provides an easy and extremely fast way to retrieve the names of the printers installed on a local machine, as well as the remote connections that a user has established. When EnumPrinters is called with a PRINTER_INFO_4 data structure, that function queries the registry for the specified information, then returns immediately. This differs from the behavior of EnumPrinters when called with other levels of PRINTER_INFO_* data structures. In particular, when EnumPrinters is called with a level 2 (PRINTER_INFO_2) data structure, it performs an OpenPrinter call on each remote connection. If a remote connection is down, or the remote server no longer exists, or the remote printer no longer exists, the function must wait for RPC to time out and consequently fail the OpenPrinter call. This can take a while. Passing a PRINTER_INFO_4 structure lets an application retrieve a bare minimum of required information; if more detailed information is desired, a subsequent EnumPrinter level 2 call can be made.


Windows 95/98/Me: To quickly enumerate local and network printers, use the PRINTER_INFO_5 structure. This causes EnumPrinters to query the registry rather than make remote calls, and is similar to using the PRINTER_INFO_4 structure as described in the preceding paragraph.


Windows Vista: The printer data returned by EnumPrinters is retrieved from a local cache when the value of Level is 4.


Examples


The following table shows the EnumPrinters output for various Flags values when the Level parameter is set to 1.


In the Name parameter column of the table, you should substitute an appropriate name for Print Provider, Domain, and Machine. For example, for Print Provider, you could use the name of the network print provider, or the name of the local print provider. To retrieve print provider names, call EnumPrinters with Name set to NULL.


Flags parameter

Name parameter

Result

PRINTER_ENUM_LOCAL (and not PRINTER_ENUM_NAME)

The Name parameter is ignored.

All local printers.


Windows 95/98/Me: Also enumerates network printers because they are installed locally.

PRINTER_ENUM_NAME

"Print Provider"

All domain names

PRINTER_ENUM_NAME

Windows NT/2000/XP:

"Print Provider!Domain"

All printers and print servers in the computer's domain

PRINTER_ENUM_NAME

Windows NT/2000/XP:

"Print Provider!!\\Machine"

All printers shared at \\Machine

PRINTER_ENUM_NAME

Windows NT/2000/XP: An empty string, ""


Windows 95/98/Me: The name of the local machine or the local print provider.

All local printers.


Windows 95/98/Me: Also enumerates network printers because they are installed locally.

PRINTER_ENUM_NAME

NULL

All print providers in the computer's domain

Windows NT/2000/XP:

PRINTER_ENUM_CONNECTIONS

The Name parameter is ignored.

All connected remote printers

Windows NT/2000/XP:

PRINTER_ENUM_NETWORK

The Name parameter is ignored.

All printers in the computer's domain

Windows NT/2000/XP:

PRINTER_ENUM_REMOTE

An empty string, ""

All printers and print servers in the computer's domain

Windows NT/2000/XP:

PRINTER_ENUM_REMOTE

"Print Provider"

Same as PRINTER_ENUM_NAME

Windows NT/2000/XP:

PRINTER_ENUM_REMOTE

"Print Provider!Domain"

All printers and print servers in computer's domain, regardless of Domain specified.


가.프린터 열거

Win32 API의 놀라운 기능 중의 하나는 장치에 독립적이라는 것인데 인쇄할 때도 마찬가지로 프린터가 바뀐다고 해서 출력 코드가 바뀔 필요는 없다. 그래서 직접 프린터를 제어하는 것보다 훨씬 더 작은 코드로 복잡한 출력을 해 낼 수가 있는 것이다. 그러나 장치 독립적이라는 것은 굉장히 멋진 개념이지만 실제로는 진실이 아닐 수도 있다. 흑백 프린터에 컬러를 출력할 수 없고 플로터에 비트맵을 출력할 수 없는 것처럼 프린터의 특성에 따라 코드가 달라져야 하는 어쩔 수 없는 경우가 존재한다.

프린터는 굉장히 복잡한 물건이고 그러다 보니 선택할 수 있는 옵션이나 설정 상태가 다양하다. 프로그램이 프린터에 독립적으로 인쇄물을 찍어 내고 또 프린터의 특성을 충분히 활용하는 호환성을 확보하기 위해서는 프린터의 여러 가지 설정 정보를 알아 내고 작업에 맞게 옵션을 강제로 변경할 수 있어야 한다. 여기서는 프린터로부터 정보를 구하는 방법과 변경하는 방법에 대해 알아 볼 예정이되 프린터 정보에 관련된 API 들은 운영체제 버전에 따라 상이한 경우가 많고 플래그의 종류도 많아 본문에서는 꼭 필요한 부분만 보이도록 한다. 모든 옵션과 플래그를 다 설명하자면 오히려 핵심이 되는 내용이 가려지게 되므로 나머지 생략된 부분은 항상 레퍼런스를 참조하기 바란다.

먼저 시스템에 어떤 종류의 프린터가 설치되어 있는지를 조사해 보도록 하자. 윈도우즈는 한꺼번에 여러 대의 프린터를 설치할 수 있으며 인쇄를 하기 전에 사용자가 출력할 프린터를 선택할 수 있도록 해 준다. 그래서 인쇄를 하는 프로그램은 시스템에 설치된 프린터의 목록을 구할 수 있어야 하는데 다음 함수는 시스템에 설치된 프린터와 프린터 서버, 도메인 등의 목록을 조사해 준다.

 

BOOL EnumPrinters(DWORD Flags, LPTSTR Name, DWORD Level, LPBYTE pPrinterEnum, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned);

 

지금까지 EnumFonts, EnumWindows 등의 여러 가지 열거 함수들을 사용해 왔는데 이 함수는 다른 열거 함수들과는 달리 콜백 함수를 사용하지 않고 배열에 모든 정보를 한번에 리턴해 준다. 그래서 사용하는 방법이 조금 특이하다. 이 함수의 인수는 두 개의 그룹으로 나눌 수 있는데 앞쪽 세 인수는 조사할 정보의 종류를 지정하고 뒤쪽 네 개의 인수는 조사된 결과를 돌려 받기 위한 버퍼를 제공한다. 첫번째 인수 Flags는 조사할 오브젝트의 종류를 지정하며 이 인수에 따라 Name, Level 인수에 지정할 수 있는 값들이 달라진다. Flags 인수에는 다음 플레그들의 조합을 지정할 수 있다.

 

플레그

설명

PRINTER_ENUM_LOCAL

로컬 프린터의 이름을 조사한다. 단 95는 네트웍 프린터도 로컬과 동일하게 취급하므로 같이 조사된다.

PRINTER_ENUM_NAME

Name이 지정하는 프린터를 열거하는데 서버, 도메인, 인쇄 프로바이더 등을 열거할 수 있다. Name이 NULL이면 인쇄 프로바이더가 조사된다.

PRINTER_ENUM_SHARED

공유된 프린터만 조사된다. 이 옵션은 단독으로 사용될 수 없으며 다른 플래그와 같이 사용한다.

PRINTER_ENUM_DEFAULT

95 : 기본 프린터를 조사한다. NT에서는 이 플래그를 사용할 수 없다.

PRINTER_ENUM_CONNECTIONS

NT : 이전에 연결한 적이 있는 프린터의 목록을 조사한다.

PRINTER_ENUM_NETWORK

NT : 같은 도메인에 속한 프린터의 목록을 구한다. Level은 반드시 1이어야 한다.

PRINTER_ENUM_REMOTE

NT : 같은 도메인에 속한 네트웍 프린터와 서버의 목록을 구한다. Level은 반드시 1이어야 한다.

 

Name인수는 Flags와 Level에 따라 사용할 수 있는가 없는가가 결정되는데 조사 대상에 대한 추가 정보라고 생각하면 된다. 예를 들어 특정 도메인내의 프린터 목록을 조사한다면 Name에 도메인명을 전달한다. Level은 조사할 정보의 레벨을 지정하는데 이 값에 따라 조사되는 정보의 상세함이 달라지며 요구되는 버퍼도 달라진다. 95/98에서는 1,2,5중 하나의 값을 지정해 줄 수 있고 NT에서는 4를 추가로 지정할 수 있다.

네 번째 이후의 인수는 조사한 정보를 리턴받기 위한 버퍼이다. 네번째 인수 pPrinterEnum에 열거된 정보들이 복사되는데 한꺼번에 여러 오브젝트의 정보가 리턴되므로 이 인수는 배열형이어야 한다. Level인수에 따라 이 배열은 PRINTER_INFO_*형이 된다. 여기서 *는 Level과 동일한 정수값인데 예를 들어 Level이 2라면 이 배열은 PRINTER_INFO_2 구조체 배열이어야 한다.

이 배열은 반드시 조사된 모든 정보를 다 담을 수 있을만큼 충분한 크기를 가져야 한다. cbBuf는 이 배열의 크기를 지정하는데 만약 크기가 충분하지 않을 경우 이 함수는 정보를 조사하는 대신 pcbNeeded에 필요한 버퍼의 크기를 리턴해 준다. 그래서 보통 처음 호출할 때는 cbBuf에 0을 전달하여 고의로 에러를 유발시키며 이때 리턴되는 pcbNeeded로 필요한 메모리 양을 알아낸다. 마지막 인수 pcReturned는 리턴된 구조체 배열의 배열 크기를 리턴해 주는데 이 값은 곧 조사된 오브젝트의 개수가 된다.

다음 예제는 이 함수로 조사할 수 있는 여러 가지 인쇄 오브젝트의 목록을 조사하여 열거한 것이다.

 

void EnumPrintObject()

{

   PRINTER_INFO_1 *pi1;

   PRINTER_INFO_2 *pi2;

   PRINTER_INFO_4 *pi4;

   DWORD cbNeed, cbReturn;

   UINT i;

   HDC hdc;

   int y=1;

   char Mes[256];

 

   hdc=GetDC(hWndMain);

 

   // 로컬 프린터 열거 - 레지스트리에서 얻음

   lstrcpy(Mes,"로컬 프린터 열거 - 레지스트리");

   TextOut(hdc,10,y++*20,Mes,lstrlen(Mes));

   EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 4, NULL, 0, &cbNeed, &cbReturn);

   pi4=(PRINTER_INFO_4 *)malloc(cbNeed);

   EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 4, (PBYTE)pi4, cbNeed, &cbNeed, &cbReturn);

   for (i=0;i<cbReturn;i++) {

      wsprintf(Mes,"프린터 이름: %s, 종류:%s ", pi4[i].pPrinterName, pi4[i].Attributes==PRINTER_ATTRIBUTE_LOCAL ? "로컬":"네트웍");

      TextOut(hdc,10,y++*20,Mes,lstrlen(Mes));

   }

   free(pi4);y++;

 

   // 로컬 프린터 열거 - 실제 프린터에서 구함

   lstrcpy(Mes,"로컬 프린터 열거 - 실제 프린터에서 구함");

   TextOut(hdc,10,y++*20,Mes,lstrlen(Mes));

   EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &cbNeed, &cbReturn);

   pi2=(PRINTER_INFO_2 *)malloc(cbNeed);

   EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 2, (PBYTE)pi2, cbNeed, &cbNeed, &cbReturn);

   for (i=0;i<cbReturn;i++) {

      wsprintf(Mes,"프린터 이름: %s, 포트:%s, 용지:%d ", pi2[i].pPrinterName, pi2[i].pPortName, pi2[i].pDevMode->dmPaperSize);

      TextOut(hdc,10,y++*20,Mes,lstrlen(Mes));

   }

   free(pi2);y++;

 

   // 인쇄 프로바이더 열거

   lstrcpy(Mes,"인쇄 프로바이더 열거");

   TextOut(hdc,10,y++*20,Mes,lstrlen(Mes));

   EnumPrinters(PRINTER_ENUM_NAME, NULL, 1, NULL, 0, &cbNeed, &cbReturn);

   pi1=(PRINTER_INFO_1 *)malloc(cbNeed);

   EnumPrinters(PRINTER_ENUM_NAME, NULL, 1, (PBYTE)pi1, cbNeed, &cbNeed, &cbReturn);

   for (i=0;i<cbReturn;i++) {

      wsprintf(Mes,"인쇄 프로바이더: %s, 설명:%s ", pi1[i].pName, pi1[i].pComment);

      TextOut(hdc,10,y++*20,Mes,lstrlen(Mes));

   }

   free(pi1);y++;

 

   // 도메인내의 프린터 열거

   lstrcpy(Mes,"도메인내의 프린터 열거");

   TextOut(hdc,10,y++*20,Mes,lstrlen(Mes));

   EnumPrinters(PRINTER_ENUM_REMOTE, NULL, 1, NULL, 0, &cbNeed, &cbReturn);

   pi1=(PRINTER_INFO_1 *)malloc(cbNeed);

   EnumPrinters(PRINTER_ENUM_REMOTE, NULL, 1, (PBYTE)pi1, cbNeed, &cbNeed, &cbReturn);

   for (i=0;i<cbReturn;i++) {

      wsprintf(Mes,"프린터 이름: %s ", pi1[i].pName);

      TextOut(hdc,10,y++*20,Mes,lstrlen(Mes));

   }

   free(pi1);y++;

 

   ReleaseDC(hWndMain,hdc);

}

 

LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)

{

   HDC hdc;

   PAINTSTRUCT ps;

 

   switch(iMessage) {

   case WM_LBUTTONDOWN:

      EnumPrintObject();

      return 0;

   case WM_PAINT:

      hdc=BeginPaint(hWnd, &ps);

      EndPaint(hWnd, &ps);

      return 0;

   case WM_DESTROY:

      PostQuitMessage(0);

      return 0;

   }

   return(DefWindowProc(hWnd,iMessage,wParam,lParam));

}

 

로컬 프린터를 열거하는 루틴만 보도록 하자. EnumPrinters 함수를 두번 호출하는데 Flags인수에 ENUM_PRINTER_LOCAL 플래그를 주었고 이 경우 Name 인수는 필요치 않으며 조사되는 정보의 레벨은 4번으로 지정하였다. 이때 pPrinterEnum에 NULL, cbBuf에 0을 전달하여 버퍼를 제공하지 않았는데 이렇게 되면 EnumPrinters 함수는 필요한 버퍼양을 cbNeed에 리턴해 준다. 리턴된 크기만큼 메모리를 할당하고 다시 EnumPrinters 함수를 호출하여 로컬 프린터의 목록을 조사하였다.

버퍼 크기를 0으로 전달함으로써 고의로 에러를 유발시켜 필요한 버퍼 크기를 알아낸 후 조사된 크기만큼 메모리를 할당한다. 물론 이때 필요한 캐스팅은 해 주어야 하며 할당된 버퍼를 다시 전달함으로써 원하는 정보를 획득하였다. 이런 식으로 사용 메모리가 가변적인 함수들은 두 번 호출하는 것이 정형화되어 있는데 앞으로 이런 함수들을 몇개 더 보게 될 것이며 보안 관련 함수들도 이런 유형이 많으므로 동작 원리와 사용 방법을 잘 익혀 두도록 하자.

나머지 열거 루틴도 Flags와 Level만 달라질 뿐 거의 동일하다. 실행 결과는 시스템에 설치된 프린터 목록에 따라 달라지는데 필자의 컴퓨터에서는 다음과 같이 출력되었다. 네트웍에 물려 있기 때문에 설치된 프린터가 많다.

 

 

조사된 정보는 for 루프를 돌며 cbReturn, 즉 조사된 오브젝트 개수만큼 출력되는데 이때 조사된 정보의 어떤 멤버를 참조할 수 있는가는 Level인수에 따라 달라진다. 얼마나 정보를 상세하게 조사할 것인가에 따라 리턴되는 구조체가 달라지며 따라서 정보의 양도 달라지는데 이렇게 레벨을 지정할 수 있도록 해 놓은 이유는 필요에 따라 원하는 정보만을 조사할 수 있도록 하기 위해서이다.

프린터 이름만 알면 되는데 굳이 프린터 설정이나 보안 속성, 현재 상태에 대한 정보까지 같이 조사할 필요는 없기 때문이다. 또한 어떤 정보는 실제로 네트웍에 접속해야만 알 수 있는 것도 있는데 이런 경우는 굉장히 시간이 많이 걸릴 수도 있다. 그래서 원하는 정보의 종류를 레벨로 선택함으로써 불필요한 시간을 낭비하지 않도록 해 놓은 것이다. 다음 도표는 Level 인수에 따라 조사되는 정보를 요약한 것이다.

 

레벨

설명

1

가장 기본적인 정보를 조사해 준다. 프린터의 이름, 설명 정도가 있다.

2

가장 상세한 정보가 조사된다. 서버명, 공유명, 포트, 드라이버, 용지 방향, 프린터의 속성, 출력 속도 등 수십가지의 정보가 한꺼번에 조사된다.

3

프린터의 보안 정보를 조사한다. SECURITY_DESCRIPTOR 구조체가 포함되어 있다.

4

프린터 이름과 종류, 서버명 등의 일반적인 프린터 정보를 조사한다.

5

상세한 프린테 정보를 조사한다. 이름, 포트, 속성, 타임아웃값 등이 포함된다.

6

용지 걸림이나 토너 부족 등 프린터의 현재 상태를 조사한다. 6번 이후의 레벨은 95/98에서는 사용할 수 없으면 NT/2000이상에서만 사용할 수 있다.

7

디렉토리 서비스와 관련된 프린터 정보를 조사한다.

8

프린터의 전역 설정에 관한 초기화 정보

9

프린터의 사용자별 설정에 관한 초기화 정보

 

각각의 PRINTER_INFO_* 구조체가 어떻게 선언되어 있고 각 멤버의 의미가 무엇인가는 본문에서 정리하지 않기로 한다. 멤버가 단순히 많기만 한 정도가 아니라 운영체제 버전과 상황에 따라 의미가 달라지는 것들도 있기 때문에 필요할 때 레퍼런스를 찾아보기 바란다. 여기서는 대표적으로 가장 자주 사용되는 PRINTER_INFO_2 구조체를 구경만 해 보도록 하자.

 

typedef struct _PRINTER_INFO_2 {

  LPTSTR    pServerName;

  LPTSTR    pPrinterName;

  LPTSTR    pShareName;

  LPTSTR    pPortName;

  LPTSTR    pDriverName;

  LPTSTR    pComment;

  LPTSTR    pLocation;

  LPDEVMODE pDevMode;

  LPTSTR    pSepFile;

  LPTSTR    pPrintProcessor;

  LPTSTR    pDatatype;

  LPTSTR    pParameters;

  PSECURITY_DESCRIPTOR pSecurityDescriptor;

  DWORD     Attributes;

  DWORD     Priority;

  DWORD     DefaultPriority;

  DWORD     StartTime;

  DWORD     UntilTime;

  DWORD     Status;

  DWORD     cJobs;

  DWORD     AveragePPM;

} PRINTER_INFO_2, *PPRINTER_INFO_2;

 

멤버가 참 많은데 이름만 봐도 대충 그 의미를 짐작할 수 있도록 되어 있다. EnumPrinters 함수는 그다지 자주 사용되는 함수가 아니며 일반적인 사용예는 앞에서 보인 예제 정도만 이해하면 실무에 적용하기 충분하다.

크리에이티브 커먼즈 라이센스
Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
TAG EnumPrinters
No received trackback. / No comment.

Trackback Address :: http://sinwoong.co.kr/trackback/300

You can also say.

알고 있어야 도움이 되는 몇가지 API들

Win32 API/MFC
2009/09/22 14:11
 

거의 모든 위도 애플리케이션에는 파일을 다루는 로직이 들어가게 된다. 미리 설정된 환경설정 파일을 읽어 내거나, 작업하기 위한 데이터가 있는 파일을 읽기도 하고, 현재 애플리케이션의 환경 설정 파일을 보조 저장장치에 저장하거나, 작업하고 있는 파일 내용을 저장하는 등의 동적은 기본적인 애플리케이션의 기능이다.

 

  보통 이러한 작업은 기존에 재활용을 위하여 잘 정의를 해 놓은 MFC의 CFile과 같은 클래스를 이용하지만, 기존 준비해 놓은 클래스에는 없는 기능을 구현하고 싶거나, 클래스 기능을 확장하고 싶을 때, 혹은 순수 API 환경에서 새로 기능을 구현해야 할 때가 있다. 이럴 경우 파일 관련 유틸리티 클래스를 만들게 되는데, 의외로 이러한 유틸리티 클래스를 만드는 부분에서 문제 있는 코드를 많이 만들어 내게 된다. 예를 들어 디렉토리 인지 판단하는 IsDirectory() 함수를 다음과 같이 정의 했다고 가정해 보자.

 

BOOL IsDirectory(const TCHAR* path) {

WIN32_FIND_DATA findFileData;

HANDLE findFile = FindFirstFile(path, &findFileData);

FindClose(findFile);

return (BOOL)(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);

}

 

  아마 xp가 설치된 일반적인 개발 머신의 환경에서는 잘 동작하기 때문에 잘 동작하는 코드라 생각할 것이다. 그러나 이 함수에는 몇 가지 오류를 일으킬 수 있다.

 

  FindFirstFile의 리턴값을 INVALID_HANDLE_VALUE 인지 체크 하는 부분이 빠져 있는데, 결과적으로 이 함수가 포함된채 릴리즈 되게 되면, xp가 설치가 된 어떤 깨끗한 PC에서는 FALSE가 리턴되어야 할 상황에서TRUE가 리턴 되기도 하고, 어떤 2000 서버와 같은 환경에서는 익셉션이 나서 애플리케이션이 비정상 종료 되는 경우도 있으며, 익셉션 처리가 되어 있는 경우 IsDirectory()를 이용하는 루틴의 수행이 중간에 종료가 되기도 한다.

 

  물론 이러한 문제 있는 코드를 만들지 않도록 함수를 확실히 검증 하고 사용 하는 것이 중요하고, 리턴 값을 철저히 검사 하는 등의 기본을 지키는 코딩을 습관화 하는 것이 중요하다. 그러나 대부분 일정에 대한 데드라인이 있는 상태에서 막히는 부분을 간단히 검색해서 당장의 문제를 해결 하다 보면, 위의 오류가 포함된 것 같은 코딩을 하기가 쉽다.

 

  이러한 기본적인 기능을 하는 함수들은 API 형태로 제공해 주는 것들이 많다. 특히 path에 관련된 API들은 API prefex로 Path가 붙어 있으므로, Shell Path와 관련된 기능이 필요하다면, 먼저 개발자 커뮤니티를 검색하기 전에 MSDN에 Index를 Path로 검색해 보면 유용하면서 검증된 API를 찾을 수 있을 것이다.

 

Shell Path와 관련된 유용한 API중 일부 몇 가지 정리해 보면 다음과 같다

 

 

함 수 명

인  자

결  과

PathAddBackslash

c:\path1

c:\path1\

PathBuildRoot

0

A:\

PathCanonicalize

c:\path1\..\.\path1

c:\path1

PathCompactPath

c:\path1\path2\path3\file.txt

c:\path1\...\file.txt

PathFileExists

c:\path1\file.txt

파일의존재유무[T/F]

PathFindFileName

c:\path1\path2\file.txt

file.txt

PathIsDirectory

c:\path1\path2

디렉토리유무[T/F]

PathIsfileSpec

file.txt

순수파일이름인지[T/F]

PathMakePretty

C:\PATH1\FILE.TXT

C:\path1\file.txt

PathIsNetworkPath

\\YHKim\path1\file.txt

네트워크경로인지[T/F]

PathIsRoot

c:\

루트경로인지유무[T/F]

PathIsSystemFolder

c:\windows\System32

시스템폴더인지유무[T/F]

PathRemoveBackslash

c:\path1\path2\

c:\path1\path2

PathRemoveBlanks

“ c:\path1\path2 “

“c:\path1\path2”

PathRemoveExtension

c:\path1\path2\file.txt

c:\path1\path2\file

PathRemoveFileSpec

c:\path1\path2\file.txt

c:\path1\path2

PathRenameExtension

c:\path1\path2\file.txt

c:\path1\path2\file.changed

PathStripPath

c:\path1\path2\file.txt

file.txt


API를 정리해 놓게 되면, 마치 요가를 해서 관절이 유연해 지는 것과 같은 느낌을 받는다. 요가를 연습하면 유연하지 않은 사람보다 팔과 다리를 움직일 수 있는 범위가 넓어 지듯이, API를 정리해 놓으면 애플리케이션을 통하여 상상력을 발휘할 수 있는 범위가, 학습한 만큼의 관절의 활동 범위처럼 넓어 지게 된다.

 

관련된 참고할 만한 MSDN Resource

Shell Function들 중 일부 함수들

http://msdn2.microsoft.com/en-us/library/bb776426(VS.85).aspx

Shell Lightweight Utility Functions중 Path와 관련된 함수들

http://msdn2.microsoft.com/en-us/library/bb773559(VS.85).aspx

User Profiles Function중 Path를 얻어 오는데 관련된 함수들

http://msdn2.microsoft.com/en-us/library/aa375109(VS.85).aspx

 

 

ps. Path가 등록이된 파일을 찾고 싶다면, SearchPath를 이용하면 FullPath가 넘어 온다.


질문) 클라이언트 컴퓨터에 설치된 firefox의 경로를 찾고 싶은데 어떻게 하지? Firefox가 써 놓은 레지스터리값를 뒤져볼까? firefox의 기본 설치 경로에 exe 파일을 createfile해서 판단할까?

답 예시) SearchPath를 이용하셔서 FullPath를 얻으시고, 얻은 FullPath를 PathFileExists로 검증하시면 됩니다.

 

상세설명:

LPTSTR PathAddBackslash( LPTSTR lpszPath );

Adds a backslash to the end of a string to create the correct syntax for a path. If the source path already has a trailing backslash, no backslash will be added.

경로 문자열의 맨 뒤에 '\'를 붙여준다. 만약 이미 '\'문자로 종결된 상태라면 아무일도 하지 않는다.
lpszPath는 MAX_PATH크기(또는 그 이상)이라야 하며, lpszPath에 '\'를 더 붙일 수 없다면 NULL이 반환된다.

BOOL PathAddExtension( LPTSTR pszPath, LPCTSTR pszExtension );

Adds a file extension to a path string.

파일 경로(pszPath)의 맨 뒤에 지정된 확장자를 붙여준다.
만약 pszPath가 이미 확장자가 포함된 파일 경로라면 아무일도 하지 않는다.
pszExtension이 NULL이라면 기본적으로 ".exe"가 붙는다.

BOOL PathAppend( LPTSTR pszPath, LPCTSTR pszMore );

Appends one path to the end of another.

두개의 경로 문자열 결합. pszPath에 pszMore를 붙여준다. 필요하다면 '\' 문자를 사용해 결합한다.

LPTSTR PathBuildRoot( LPTSTR szRoot, int iDrive );

Creates a root path from a given drive number.

드라이브 식별 번호(iDrive)를 문자열 형(szRoot)으로 변환해 준다. 0 = a:\ 뭐 이런식이다.

BOOL PathCanonicalize( LPTSTR lpszDst, LPCTSTR lpszSrc );

Canonicalizes a path.

경로에 상대경로 지정문자 ( "./", "../")가 포함되어 있다면 이를 적절하게 처리해준다. lpszsrc="c:\\a\\b\\..\\c" temp_src="c:\\a\\b\\..\\c"라면 lpszDst = "c:\\a\\c"가 된다.

LPTSTR PathCombine( LPTSTR lpszDest, LPCTSTR lpszDir, LPCTSTR lpszFile );

Concatenates two strings that represent properly formed paths into one path; also concatenates any relative path elements.

폴더 경로 + 파일경로로 구성해준다. lpszDest = lpszDir + lpszFile.
적절하게 '\'를 사용해서 연결해 주며, 상대경로가 포함되어 있다면 이또한 적절하게 처리해 준다.
적절한 함수로군-ㅅ-ㅋㅋ

int PathCommonPrefix( LPCTSTR pszFile1, LPCTSTR pszFile2, LPTSTR pszPath );

Compares two paths to determine if they share a common prefix. A prefix is one of these types: "C:\\", ".", "..", "..\\".

두 경로 pszFile1과 pszFile2에서 어디까지가 공통된 경로인지 조사하고, pszPath에 공통된 부분을 담아준다.
공통된 부분이 없다면 pszPath는 NULL로 설정된다.

BOOL PathCompactPath( HDC hDC, LPTSTR lpszPath, UINT dx );

Truncates a file path to fit within a given pixel width by replacing path components with ellipses.

lpszPath에 포함된 경로 문자열을 dx pixel 크기에 출력하기 적절하게 잘라준다.
C:\path1\path2\sample.txt
C:\path1\...\sample.txt
C:\p...\sample.txt

BOOL PathCompactPathEx( LPTSTR pszOut, LPCTSTR pszSrc, UINT cchMax, DWORD dwFlags );

Truncates a path to fit within a certain number of characters by replacing path components with ellipses.

PathCompactPath와 유사하다. 다만, pixel단위가 아니라 최대 cchMax만큼 잘라낸다.

HRESULT PathCreateFromUrl( LPCTSTR pszUrl, LPTSTR pszPath, LPDWORD pcchPath, DWORD dwReserved );

Converts a file URL to a Microsoft MS-DOS path.

URL형태로 구성된 경로를 Windows 경로 형식으로 변환해 준다. file:///c:/test.txt = c:\test.txt.
주의: S_OK가 반환되지 않았다면 pszPath는 아무런 변화도 일어나지 않았다는 소리다!!
또, 실제 URL(Web)이 아니라 Local File Url이라야 한다.

BOOL PathFileExists( LPCTSTR pszPath );

Determines whether a path to a file system object such as a file or directory is valid.

제시된 경로의 파일/폴더가 실제로 존재하는지 검사한다.

LPTSTR PathFindExtension( LPCTSTR pPath );

Searches a path for an extension.

파일 경로에서 확장자를 찾아준다. (pPath에서 확장자가 시작되는 위치를 반환).

LPTSTR PathFindFileName( LPCTSTR pPath );

Searches a path for a file name.

파일 경로에서 파일 이름을 찾아준다. (pPath에서 이름이 시작되는 위치를 반환).

LPTSTR PathFindNextComponent( LPCTSTR pszPath );

Parses a path for the next path component.

다음 위치의 경로를 찾아준다. 어떤 경로에 대해 순자접근이 필요하다면 사용해볼 법 하다.
PathFindNextComponent( "c:\windows\system32" ) = windows\system32
PathFindNextComponent( "windows\system32") = system32

BOOL PathFindOnPath( LPTSTR pszFile, LPCTSTR *ppszOtherDirs );

Searches for a file.

파일을 검색한다. 만약 검색에 성공하면 pszFile에는 해당 파일의 전체 경로가 담겨져서 반환된다.
ppszOtherDirs가 NULL이라면 windows 기본 경로(system32, 환경 변수 path의 값 등)에서 파일을 검색한다.
주의: 여러개의 파일이 존재 하더라도, 첫번째로 검색된 파일의 경로만 반환한다.

LPCTSTR PathFindSuffixArray( LPCTSTR pszPath, const LPCTSTR *apszSuffix, int iArraySize );

Determines whether a given file name has one of a list of suffixes.

PathFindOnPath와 유사하다. 다만, apszSuffix를 통해 검색할 경로를 여러개 지정할 수 있다. (기본경로 검색은 하지 않는다.)
주의: 대소문자를 구분한다.

LPTSTR PathGetArgs( LPCTSTR pszPath );

Finds the command line arguments within a given path.

경로에 포함된 매개변수(argv)를 찾아준다.
PathGetArgs("c:\test.exe temp.txt /x") = "temp.txt /x"

UINT PathGetCharType( TUCHAR ch );

Determines the type of character in relation to a path.

문자가 경로 문자열에 사용되면 어떤 의미인지 알려준다. 경로에 포함될 수 있는 문자인가? 경로 구분자('\')인가? 등등..
이 함수를 이용해서 경로에 사용할 수 있는 문자열인지를 검사할 수 있다.

int PathGetDriveNumber( LPCTSTR lpsz );

Searches a path for a drive letter within the range of 'A' to 'Z' and returns the corresponding drive number.

제시된 경로에 포함된 드라이브 문자(c:\) 의 식별 번호를 반환한다.

BOOL PathIsContentType( LPCTSTR pszPath, LPCTSTR pszContentType );

Determines if a file's registered content type matches the specified content type. This function obtains the content type for the specified file type and compares that string with the pszContentType. The comparison is not case-sensitive.

제시된 파일경로가(확장자만 넘겨줘도 된다;) 등록된 contents type과 일치하는지 검사한다.
PathIsContentType( "c:\temp.txt", "text/plain" ) = TRUE

BOOL PathIsDirectory( LPCTSTR pszPath );

Verifies that a path is a valid directory.

실제로 존재하는 폴더인지 확인한다.

BOOL PathIsDirectoryEmpty( LPCTSTR pszPath );

Determines whether a specified path is an empty directory.

비어있는(안에 파일이나 서브 폴더가 없는) 폴더인지 확인한다.

BOOL PathIsFileSpec( LPCTSTR lpszPath );

Searches a path for any path-delimiting characters (for example, ':' or '\' ). If there are no path-delimiting characters present, the path is considered to be a File Spec path.

제시된 경로가 파일명만으로 구성되어 있는지 조사한다.
정확히 말하자면, 경로를 구성하는데 사용되는 문자 (경로 구분자'\' 라던지, 드라이브 구분자':' 라던지..)가 포함되어 있으면 FALSE가 반환된다.
주의: 파일명으로 사용할 수 없는 문자(/, :, * 등)가 들어있는가? 를 검사하는 함수가 아니다!!

BOOL PathIsHTMLFile( LPCTSTR pszFile );

Determines if a file is an HTML file. The determination is made based on the content type that is registered for the file's extension.

제시된 경로의 확장자가 HTML 유형인가를 검사한다.
한마디로, 레지스트리에 등록된 content type이 text/html이라면 TRUE. (.htm, .html, .xhtml ...)

BOOL PathIsLFNFileSpec( LPCTSTR pszName );

Determines whether a file name is in long format.

제시된 경로가 Long File Name spec에 적합한지 검사한다. (아마 쓸 일은 거의 없을듯 싶다 -_-;)

BOOL PathIsNetworkPath( LPCTSTR pszPath );

Determines whether a path string represents a network resource.

경로가 네트워크 경로라면 TRUE. 단, 실제로 존재하는 네트워크 경로인가는 다른 얘기다!

BOOL PathIsPrefix( IN LPCTSTR pszPrefix, IN LPCTSTR pszPath );

Searches a path to determine if it contains a valid prefix of the type passed by pszPrefix. A prefix is one of these types: "C:\\", ".", "..", "..\\".

경로가 pszPrefix로 시작되는가를 검사한다. 같은 드라이브에 있는 파일인지 검사할때 유용하다.

BOOL PathIsRelative( LPCTSTR lpszPath );

Searches a path and determines if it is relative.

경로가 상대경로인지 검사한다.
주의: 파일명만 제시된 경우, 상대경로로 인식한다.
PathIsRelative("../../temp.txt") = TRUE
PathIsRelative("c:/temp.txt") = FALSE
PathIsRelative("temp.txt") = TRUE

BOOL PathIsRoot( LPCTSTR pPath );

Parses a path to determine if it is a directory root.

경로가 루트 폴더(드라이브 바로 밑)인지 검사한다.
PathIsRoot("c:\") = TRUE
PathIsRoot("c:\windows") = FALSE

BOOL PathIsSameRoot( LPCTSTR pszPath1, LPCTSTR pszPath2 );

Compares two paths to determine if they have a common root component.

pszPath1과 pszPath2가 같은 드라이브(루트폴더)에 있는지 검사한다.
PathIsSameRoot( "c:\test1\temp1.txt", "c:\test2\temp2.txt" ) = TRUE

BOOL PathIsSystemFolder( LPCTSTR pszPath, DWORD dwAttrb );

Determines if an existing folder contains the attributes that make it a system folder. Alternately, this function indicates if certain attributes qualify a folder to be a system folder.

제시된 경로가 시스템 폴더인지 검사한다.

BOOL PathIsUNC( LPCTSTR pszPath );

Determines if the string is a valid Universal Naming Convention (UNC) for a server and share path.

UNC(공유)경로인지 확인한다.
PathIsUNC("\\server\folder\") = TRUE
PathIsUNC("server\folder") = FALSE

PathIsUNCServer( LPCTSTR pszPath );

Determines if a string is a valid Universal Naming Convention (UNC) for a server path only.

PathIsUNC와 다른점은 pszPath가 서버이름만으로 구성되어야 한다는 점이다. 주의할 점은, pszPath가 "\\"만으로 된 경우도 TRUE라는 점이다.
PathIsUNCServer("\\server") = TRUE
PathIsUNCServer("\\server\folder") = FALSE

BOOL PathIsUNCServerShare( LPCTSTR pszPath );

Determines if a string is a valid Universal Naming Convention (UNC) share path, \\ server\ share.

PathIsUNC와 다른점은 pszPath가 서버이름 + 공유경로만으로 구성되어야 한다는 점이다. (PathIsUNC는 파일명까지 넘어가도 TRUE)
주의: 대부분의 PathXXX 함수가 그렇듯, pszPath가 실존하는가는 관계없다!!!

BOOL PathIsURL( LPCTSTR pszPath );

Tests a given string to determine if it conforms to a valid URL format.

유효한 URL인지 확인한다.

BOOL PathMakePretty( LPTSTR lpPath );

Converts a path to all lowercase characters to give the path a consistent appearance.

경로를 소문자로 변환해준다. 이미 소문자로 이뤄져서 변환이 이뤄지지 않은 경우 FALSE가 반환된다.
주의할 점은, lpPath가 모두 대문자로 이뤄져 있어야 변환된다는 점이다 -_-;
PathMakePretty( "C:\TEST\TEMP.TXT" ) = "c:\test\temp.txt"
PathMakePretty( "c:\Test\Temp.txt") = 변화 없음

BOOL PathMakeSystemFolder( LPTSTR pszPath );

Gives an existing folder the proper attributes to become a system folder.

지정된 폴더를 시스템 폴더로 만든다.

BOOL PathMatchSpec( LPCSTR pszFile, LPCSTR pszSpec );

Searches a string using a Microsoft MS-DOS wild card match type.

지정된 문자(열)이 경로에 포함되어 있는지 검사한다. DOS명령어 "dir *.bmp" 개념으로 생각하면 된다.
PathMatchSpec( "c:\test\temp.txt", "*.txt") = TRUE

BOOL PathMatchSpecEx( LPCTSTR pszFile, LPCTSTR pszSpec, DWORD dwFlags );

Searches a string using a Microsoft MS-DOS wild card match type and a flag.

PathMatchSpec과 유사하다. 차이점은, dwFlags에 PMSF_MULTIPLE를 사용하면 여러개의 검색 패턴 지정이 가능하다는 점.
주의: shlwapi.dll version 7.0.(Vista) 이상에서 사용 가능하다.
PathMatchSpecEx( "c:\test\temp.txt temp2.bmp", "*.txt temp.*", PMSF_MULTIPLE ) = TRUE

int PathParseIconLocation( LPTSTR pszIconFile );

Parses a file location string containing a file location and icon index, and returns separate values.

pszIconFile에 파일경로와 아이콘 인덱스가 포함되어 있는 경우 이를 적절하게 분리해 준다.
pszIconFile에는 경로가, 아이콘 인덱스는 반환값으로 나오게 되며, pszIconFile은 "경로, icon index"형식 이라야 한다.

BOOL PathQuoteSpaces( LPTSTR lpsz );

Searches a path for spaces. If spaces are found, the entire path is enclosed in quotation marks.

lpsz에서 공백이 발견되면 lpsz를 큰 따옴표(")로 묶어준다. 공백이 없다면 아무일도 하지않고 FALSE가 반환된다.

BOOL PathRelativePathTo( LPTSTR pszPath, LPCTSTR pszFrom, DWORD dwAttrFrom, LPCTSTR pszTo, DWORD dwAttrTo );

Creates a relative path from one file or folder to another.

pszFrom에서 pszTo로 가는 상대경로를 구해서 pszPath에 담아준다. 당연한 소리지만 pszFrom과 pszTo는 동일한 Prefix에서 시작해야 한다.
TCHAR buffer[MAX_PATH];
BOOL PathRelativePathTo( buffer, "c:/a/b/c/", FILE_ATTRIBUTE_DIRECTORY, "c:/a/1/2/test.txt", FILE_ATTRIBUTE_NORMAL);
buffer = "../../1/2/test.txt";

void PathRemoveArgs( LPTSTR pszPath );

Removes any arguments from a given path.

경로에 포함된 인자(argv)를 지워준다.

LPTSTR PathRemoveBackslash( LPTSTR lpszPath );

Removes the trailing backslash from a given path.

경로 맨 끝에 back slash(\)가 있다면 지워준다.

void PathRemoveBlanks( LPTSTR lpszString );

Removes all leading and trailing spaces from a string.

Trim과 유사하다. 경로 앞뒤의 공백을 제거한다.

void PathRemoveExtension( LPTSTR pszPath );

Removes the file extension from a path, if one is present.

확장자를 제거한다.

BOOL PathRemoveFileSpec( LPTSTR pszPath );

Removes the trailing file name and backslash from a path, if they are present.

파일이름을 제거한다. 주의할 점은 맨 끝의 "\"도 지워진다는거~
PathRemoveFileSpec("c:\temp\test.txt") = "c:\temp"

BOOL PathRenameExtension( LPTSTR pszPath, LPCTSTR pszExt );

Replaces the extension of a file name with a new extension. If the file name does not contain an extension, the extension will be attached to the end of the string.

파일 경로의 확장자를 지정된 확장자로 교체한다.
PathRenameExtension( "c:\temp\test.xml", ".txt") = "c:\temp\test.txt"

BOOL PathSearchAndQualify( LPCTSTR pcszPath, LPTSTR pszFullyQualifiedPath, UINT cchFullyQualifiedPath );

Determines if a given path is correctly formatted and fully qualified.

제시된 경로 pcszPath에 오류가 있다면 이를 바로잡아서 pszFullyQualifiedPath에 담아준다.
상대경로를 적절히 계산해 주고, 시스템 변수가 사용된 경우 이를 적절히 확장해 준다.
TCHAR buffer[MAX_PATH];
PathSearchAndQualify( "c:\a\..\b", buffer, MAX_PATH) = c:\b;
PathSearchAndQualify( "c:\a\\\b", buffer, MAX_PATH) = c:\a\b;
PathSearchAndQualify( "notepad.exe", buffer, MAX_PATH) = c:\windows\system32\notepad.exe;
PathSearchAndQualify( "%SystemRoot%system32\notepad.exe", buffer, MAX_PATH) = c:\windows\system32\notepad.exe;

void PathSetDlgItemPath( HWND hDlg, int id, LPCSTR pszPath );

Sets the text of a child control in a window or dialog box, using PathCompactPath to ensure the path fits in the control.

PathCompactPath와 유사하다. id로 지정된 Dialog Item에 출력하기 적합한 길이로 경로를 잘라준다.

LPCTSTR PathSkipRoot( LPCTSTR pszPath );

Parses a path, ignoring the drive letter or Universal Naming Convention (UNC) server/share path elements.

루트 경로를 제거한다. 로컬 경로인 경우 드라이브문자(c:\)가 지워지고, UNC경로인 경우 서버이름, 공유폴더 이름이 제거된다.
PathSkipRoot( "c:\temp\test.txt") = temp\test.txt
PathSkipRoot( "\\server\c$\temp\test.txt") = temp\test.txt

void PathStripPath( LPTSTR pszPath );

Removes the path portion of a fully qualified path and file.

전체 경로에서 파일이름(또는 마지막 폴더 이름)만을 남기고 제거한다.
PathStripPath("c:\temp\test.txt") = test.txt
PathStripPath("c:\temp\foo") = foo

BOOL PathStripToRoot( LPTSTR szRoot );

Removes all parts of the path except for the root information.

루트경로만 남기고 나머지를 제거한다.
PathStripToRoot("c:\temp") = c:\

void PathUndecorate( LPTSTR pszPath );

Removes the decoration from a path string.

이건 뭐라고 설명해야 되나 -_-; 예제를 보자. 참고로, "[n]"형태만 제거한다. (n), {n} 뭐 이런건 영향받지 않는다;
PathUndecorate( "temp[1].txt") = temp.txt

BOOL PathUnExpandEnvStrings( LPCTSTR pszPath, LPTSTR pszBuf, UINT cchBuf );

Replaces folder names in a fully-qualified path with their associated environment string.

경로와 일치하는 환경변수로 치환해 준다.
char szBuffer[MAX_PATH];
PathUnExpandEnvStrings( "c:\windows\", szBuffer, MAX_PATH ) = "%SystemRoot%";

BOOL PathUnmakeSystemFolder( LPTSTR pszPath );

Removes the attributes from a folder that make it a system folder. This folder must actually exist in the file system.

폴더속성에서 system속성을 제거한다.

void PathUnquoteSpaces( LPTSTR lpsz );

Removes quotes from the beginning and end of a path.

경로를 둘러싼 큰 따옴표(")를 제거해 준다.
PathUnquoteSpaces("\"c:\temp\"") = c:\temp

BOOL SHSkipJunction( IBindCtx *pbc, const CLSID *pclsid );

Checks a bind context to see if it is safe to bind to a particular component object.

...이놈은 당최 뭐에 쓰라는건지 모르겠다 -_-;

HRESULT UrlApplyScheme( LPCTSTR pszIn, LPTSTR pszOut, LPDWORD pcchOut, DWORD dwFlags );

Determines a scheme for a specified URL string, and returns a string with an appropriate prefix.

경로앞에 적절한 scheme를 붙여준다. (http://, file:///, ftp:// 등)
효과는 그닥 기대하지 말자;;

HRESULT UrlCanonicalize( LPCTSTR pszUrl, LPTSTR pszCanonicalized, LPDWORD pcchCanonicalized, DWORD dwFlags );

Converts a URL string into canonical form.

URL경로에 포함된 상대경로( '.', '..') 를 적절하게 처리한다. dwFlag값에 따라 안전하지 않은 문자들을 escape처리 하는등의 기능도 수행할 수 있다.

HRESULT UrlCombine( LPCTSTR pszBase, LPCTSTR pszRelative, LPTSTR pszCombined, LPDWORD pcchCombined, DWORD dwFlags );

When provided with a relative URL and its base, returns a URL in canonical form.

두 URL경로를 합쳐준다.
UrlCombine( "http://www.studiocoma.com/", "default.aspx", lpszCombine, &dwSize, 0 ) = "http://www.studiocoma.com/default.aspx"
주의!
UrlCombine( "http://abc.com/a/b/c", "d" ...)는 "http://abc.com/a/b/d"가 된다.
UrlCombine( "http://abc.com/a/b/c/", "d" ...)로 해야 "http://abc.com/a/b/c/d"가 된다.

int UrlCompare( LPCTSTR pszURL1, LPCTSTR pszURL2, BOOL fIgnoreSlash );

Makes a case-sensitive comparison of two URL strings.

두 URL 문자열을 비교한다. (대소문자 구분 없음)

HRESULT UrlCreateFromPath( LPCTSTR pszPath, LPTSTR pszUrl, LPDWORD pcchUrl, DWORD dwReserved );

Converts a Microsoft MS-DOS path to a canonicalized URL.

로컬 경로문자열(c:\temp)을 URL포맷(file:///c:\temp)으로 변환해준다.

HRESULT UrlEscape( LPCTSTR pszURL, LPTSTR pszEscaped, LPDWORD pcchEscaped, DWORD dwFlags );

Converts characters in a URL that might be altered during transport across the Internet ("unsafe" characters) into their corresponding escape sequences.

URL로 사용할 수 없는 문자들(^, {, " 등)을 URL encoding된 문자열로 변환해 준다.

HRESULT UrlEscapeSpaces( LPCTSTR pszURL, LPTSTR pszEscaped, LPDWORD pcchEscaped );

A macro that converts space characters into their corresponding escape sequence.

URL에 포함된 공백을 escapce처리 해 준다.

HRESULT UrlGetPart( LPCTSTR pszIn, LPTSTR pszOut, LPDWORD pcchOut, DWORD dwPart, DWORD dwFlags );

Accepts a URL string and returns a specified part of that URL.

dwPart값에 따라 URL에서 특정부분을 분리해 준다. (hostname, port...)

BOOL UrlIs( LPCTSTR pszUrl, URLIS UrlIs );

Tests whether or not a URL is a specified type.

URL이 UrlIs에 제시된 조건(적합한 URL인가? 파일 경로인가? 등)에 맞는 구성인지 확인한다.

크리에이티브 커먼즈 라이센스
Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
No received trackback. / No comment.

Trackback Address :: http://sinwoong.co.kr/trackback/299

You can also say.

Prev 1 2 3 4 5 6 ... 143 Next
달빛는 지금.. 파이팅파이팅
C와 Assembly를 제2외국어로...
남자RH+ O형사수자리경기도

카테고리

  • 전체 (285)
    • Project HSL (2)
    • Project Talk (8)
    • 생각 (16)
    • 일상 (18)
    • 정보/스크랩 (64)
    • 용어사전 (4)
    • IT외부행사 (15)
    • ASSEMBLY (7)
    • Win32 API/MFC (29)
    • Hacking/Virus/Vaccine (24)
    • 관심거리 (3)
    • 스킨/플러그인 (2)
    • 시간 죽이기 (2)
    • 천연 비누/화장품 (10)
    • Windows Server 2008 (57)
    • 디바이스 드라이버 (23)
    • 카드 (1)
    • 지식베이스캠프 (0)
    • 소프트캠프 업무 일지 (0)

태그목록

  • 보안 USB
  • 의미
  • 개인정보
  • Code Red Worm
  • 애정결핍증
  • ISEC 2007
  • IP Security Policy
  • 느낌
  • 보안책임자
  • 학습 로드맵
  • 개인정보침해
  • IDE
  • 모놀리식
  • 지하철 노선도
  • 문서세단기
  • 한국전자부품전
  • 레이스 컨디션
  • 독학
  • IT통계
  • Window I/O
  • 아스키 코드표
  • 사이드바
  • 정보보호
  • 멜로영화
  • Detoured.dll
  • ATL
  • 조기교육
  • 휴대용 저장장치 보안
  • 컨퍼런스
  • SP2

최근에 올라온 글

  • ExitProcess(), Termina....
  • C/C++ 격리된 응용 프로....
  • EnumPrinters.
  • 알고 있어야 도움이 되....
  • Microsoft Windows XP....

최근에 달린 댓글

  • 좋은 자료 감사합니다.. Minjong Kim 08/09
  • 학습로드맵 잘 보고 갑.... Minjong Kim 08/09
  • 잘보고 갑니다 : ). hothead 07/16
  • 좋은 글 잘읽었습니다. ^^. Rhea君 05/06
  • 좋은 소프트웨어네여. montreal florist 01/12

최근에 받은 트랙백

  • Windows 시스템 실행파.... 김재호의 디지털보단 아... 02/14
  • 스레드만 사용하면 컴퓨.... 철없는강아지의 블로그 2008
  • 언제 다이어그램을 그려.... 너구리의 프로그래밍 세계 2007
  • 국내 웹환경에 기대를.... *~アスタリスク~ 2007
  • [플러그인] IS Flash Vi.... ISCUBIX.COM 2007

글 보관함

  • 2010/06 (1)
  • 2010/03 (2)
  • 2009/09 (1)
  • 2009/04 (2)
  • 2009/03 (5)

달력

«   2010/09   »
일 월 화 수 목 금 토
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    

링크

  • IT 용어사전.
  • Total : 288476
  • Today : 12
  • Yesterday : 245
Tattertools
Eolin
rss

달빛's blog is powered byTattertools1.5.3.1 : Adamantine
Skin by Nyangkum