반응형
MSDN에 있는 샘플. http://msdn.microsoft.com/en-us/library/aa371886(v=vs.85).aspx

#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <pdh.h>
#include <pdhmsg.h>

#pragma comment(lib, "pdh.lib")

CONST ULONG SAMPLE_INTERVAL_MS    = 1000;
CONST PWSTR BROWSE_DIALOG_CAPTION = L"Select a counter to monitor.";

void wmain(void)
{
    PDH_STATUS Status;
    HQUERY Query = NULL;
    HCOUNTER Counter;
    PDH_FMT_COUNTERVALUE DisplayValue;
    DWORD CounterType;
    SYSTEMTIME SampleTime;
    PDH_BROWSE_DLG_CONFIG BrowseDlgData;
    WCHAR CounterPathBuffer[PDH_MAX_COUNTER_PATH];

    //
    // Create a query.
    //

    Status = PdhOpenQuery(NULL, NULL, &Query);
    if (Status != ERROR_SUCCESS) 
    {
       wprintf(L"\nPdhOpenQuery failed with status 0x%x.", Status);
       goto Cleanup;
    }

    //
    // Initialize the browser dialog window settings.
    //

    ZeroMemory(&CounterPathBuffer, sizeof(CounterPathBuffer));
    ZeroMemory(&BrowseDlgData, sizeof(PDH_BROWSE_DLG_CONFIG));

    BrowseDlgData.bIncludeInstanceIndex = FALSE;
    BrowseDlgData.bSingleCounterPerAdd = TRUE;
    BrowseDlgData.bSingleCounterPerDialog = TRUE;
    BrowseDlgData.bLocalCountersOnly = FALSE;
    BrowseDlgData.bWildCardInstances = TRUE;
    BrowseDlgData.bHideDetailBox = TRUE;
    BrowseDlgData.bInitializePath = FALSE;
    BrowseDlgData.bDisableMachineSelection = FALSE;
    BrowseDlgData.bIncludeCostlyObjects = FALSE;
    BrowseDlgData.bShowObjectBrowser = FALSE;
    BrowseDlgData.hWndOwner = NULL;
    BrowseDlgData.szReturnPathBuffer = CounterPathBuffer;
    BrowseDlgData.cchReturnPathLength = PDH_MAX_COUNTER_PATH;
    BrowseDlgData.pCallBack = NULL;
    BrowseDlgData.dwCallBackArg = 0;
    BrowseDlgData.CallBackStatus = ERROR_SUCCESS;
    BrowseDlgData.dwDefaultDetailLevel = PERF_DETAIL_WIZARD;
    BrowseDlgData.szDialogBoxCaption = BROWSE_DIALOG_CAPTION;

    //
    // Display the counter browser window. The dialog is configured
    // to return a single selection from the counter list.
    //

    Status = PdhBrowseCounters(&BrowseDlgData);

    if (Status != ERROR_SUCCESS) 
    {
        if (Status == PDH_DIALOG_CANCELLED) 
        {
            wprintf(L"\nDialog canceled by user.");
        }
        else 
        {
            wprintf(L"\nPdhBrowseCounters failed with status 0x%x.", Status);
        }
        goto Cleanup;
    } 
    else if (wcslen(CounterPathBuffer) == 0) 
    {
        wprintf(L"\nUser did not select any counter.");
        goto Cleanup;
    }
    else
    {
        wprintf(L"\nCounter selected: %s\n", CounterPathBuffer);
    }

    //
    // Add the selected counter to the query.
    //

    Status = PdhAddCounter(Query, CounterPathBuffer, 0, &Counter);
    if (Status != ERROR_SUCCESS) 
    {
        wprintf(L"\nPdhAddCounter failed with status 0x%x.", Status);
        goto Cleanup;
    }

    //
    // Most counters require two sample values to display a formatted value.
    // PDH stores the current sample value and the previously collected
    // sample value. This call retrieves the first value that will be used
    // by PdhGetFormattedCounterValue in the first iteration of the loop
    // Note that this value is lost if the counter does not require two
    // values to compute a displayable value.
    //

    Status = PdhCollectQueryData(Query);
    if (Status != ERROR_SUCCESS) 
    {
        wprintf(L"\nPdhCollectQueryData failed with 0x%x.\n", Status);
        goto Cleanup;
    }

    //
    // Print counter values until a key is pressed.
    //

    while (!_kbhit()) 
    {
        Sleep(SAMPLE_INTERVAL_MS);

        GetLocalTime(&SampleTime);

        Status = PdhCollectQueryData(Query);
        if (Status != ERROR_SUCCESS) 
        {
            wprintf(L"\nPdhCollectQueryData failed with status 0x%x.", Status);
        }

        wprintf(L"\n\"%2.2d/%2.2d/%4.4d %2.2d:%2.2d:%2.2d.%3.3d\"",
                SampleTime.wMonth,
                SampleTime.wDay,
                SampleTime.wYear,
                SampleTime.wHour,
                SampleTime.wMinute,
                SampleTime.wSecond,
                SampleTime.wMilliseconds);

        //
        // Compute a displayable value for the counter.
        //

        Status = PdhGetFormattedCounterValue(Counter,
                                             PDH_FMT_DOUBLE,
                                             &CounterType,
                                             &DisplayValue);
        if (Status != ERROR_SUCCESS) 
        {
            wprintf(L"\nPdhGetFormattedCounterValue failed with status 0x%x.", Status);
            goto Cleanup;
        }

        wprintf(L",\"%.20g\"", DisplayValue.doubleValue);
    }

Cleanup:

    //
    // Close the query.
    //

    if (Query) 
    {
       PdhCloseQuery(Query);
    }
}




반응형

'c' 카테고리의 다른 글

CreateProcess 예제  (0) 2008.10.13
bit test  (0) 2008.08.21
java IpAddress To dns name  (0) 2008.06.08
'LPSTR'에서 'LPCWSTR'(으)로 변환할 수 없습니다.  (0) 2008.05.11
[msdn] Windows Data Types  (0) 2008.05.09
반응형

  STARTUPINFO si = {0,};

  PROCESS_INFORMATION pi;

  si.cb = sizeof(si);

  TCHAR command[] = "notepad.exe";

  SetCurrentDirectory("C:\\windows\\system32");

  ZeroMemory(&pi, sizeof(pi));

  CreateProcess(

   NULL, command, NULL, NULL, 

   TRUE, 0, NULL, NULL, &si, &pi

   );


반응형

'c' 카테고리의 다른 글

Browsing Performance Counters  (0) 2011.03.10
bit test  (0) 2008.08.21
java IpAddress To dns name  (0) 2008.06.08
'LPSTR'에서 'LPCWSTR'(으)로 변환할 수 없습니다.  (0) 2008.05.11
[msdn] Windows Data Types  (0) 2008.05.09
반응형

// // bit_test.cpp : Defines the entry point for the console application. // #include "stdafx.h" void printbit(char ch); void cast(int value); int main(int argc, char* argv[]) { cast(255); return 0; } void cast(int value) { printf("char\t : \'%c\' \n", (char)value); printf("dec \t : \'%d\' \n", value); printf("hex \t : \'%x\' \n", value); printf("bit \t : "); printbit( (char)value ); printf("\n"); /* 비트연산자 & : AND 두 비트가 1일때만 1 | : OR 두 비트중 하나 이상 1이면 1 ^ : XOR 같으면 0, 다르면 1 ~ : 1은 0 , 0은 1 */ } void printbit(char ch) { int i; for(i=0;i<8;i++) { printf("%d", (ch&0200) ? 1 : 0); if(i==3) printf(" "); ch = ch << 1; } }



반응형

'c' 카테고리의 다른 글

Browsing Performance Counters  (0) 2011.03.10
CreateProcess 예제  (0) 2008.10.13
java IpAddress To dns name  (0) 2008.06.08
'LPSTR'에서 'LPCWSTR'(으)로 변환할 수 없습니다.  (0) 2008.05.11
[msdn] Windows Data Types  (0) 2008.05.09
반응형

#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <netdb.h> #include <arpa/inet.h> #include <sys/socket.h> #include <string.h> //#define IP "220.90.197." #define IP "211.115.99." int main(int argc, char *argv[]) { struct hostent *host; struct in_addr in; char ipList[1024]; int i; char temp[10]; for(i=1;i<255;i++) { strcpy(ipList, IP); sprintf(temp, "%d", i); strcat(ipList, temp); printf("Current IP: [%s]\t", ipList); inet_aton(ipList, &in); host = gethostbyaddr( (char *)&in, sizeof(in), AF_INET); if( host == NULL ) { // herror("gethostbyaddr"); // exit(1); printf("DomainName: [%s] (failed)\n", ipList); } else { printf("DomainName: [%s] (success)\n", host->h_name); } } return 0; }



반응형

'c' 카테고리의 다른 글

CreateProcess 예제  (0) 2008.10.13
bit test  (0) 2008.08.21
'LPSTR'에서 'LPCWSTR'(으)로 변환할 수 없습니다.  (0) 2008.05.11
[msdn] Windows Data Types  (0) 2008.05.09
const란?  (0) 2008.04.17
반응형

HDC hdc;
 TCHAR s[256];
 //WCHAR s[256];

 hdc = GetDC(ghWnd);

 wsprintf(s, "Hooked Key Code = %3d. \t" , wParam);
 TextOut( hdc, 50, 50, s, lstrlen(s) );

사용자 삽입 이미지



프로젝트 등록정보에서 문자집합을 유니코드에서 멀티바이트로 바꿔줘야함..
반응형

'c' 카테고리의 다른 글

CreateProcess 예제  (0) 2008.10.13
bit test  (0) 2008.08.21
java IpAddress To dns name  (0) 2008.06.08
[msdn] Windows Data Types  (0) 2008.05.09
const란?  (0) 2008.04.17
반응형
Windows Data Types

The data types supported by Microsoft® Windows® are used to define function return values, function and message parameters, and structure members. They define the size and meaning of these elements. For more information about the underlying C/C++ data types, see Data Type Ranges.

The following table contains the following types: character, integer, Boolean, pointer, and handle. The character, integer, and Boolean types are common to most C compilers. Most of the pointer-type names begin with a prefix of P or LP. Handles refer to a resource that has been loaded into memory.

For more information about handling 64-bit integers, see Large Integers.


http://msdn.microsoft.com/en-us/library/aa383751(VS.85).aspx

반응형

'c' 카테고리의 다른 글

CreateProcess 예제  (0) 2008.10.13
bit test  (0) 2008.08.21
java IpAddress To dns name  (0) 2008.06.08
'LPSTR'에서 'LPCWSTR'(으)로 변환할 수 없습니다.  (0) 2008.05.11
const란?  (0) 2008.04.17
반응형

const란 const 대상이 된 데이터가 변경되면 컴파일러가 에러를 내게 만든 기능입니다.
즉 const 대상 데이터값을 바꾸는 것을 방지하는 기술입니다.

const 같은 경우에는 .. line 이 길어 질수록... 꼭 필요하다고 하네요..
여기서는 간략하게 예시를 제시 했는데..

-------------------------------------------------
float P=3.14;               //   const float P=3.14;
int main()
{
     float rad;
     P=3.07;           // 이곳에서 실수를...
     scanf("%f", &rad);
     printf("원의 넓이는 %f\n",rad*rad*P);
     return 0;
}
-------------------------------------------------

만약 만라인 이상일 경우를 생각했을경우...
본인은 ... P값을 변경할 경우는 전혀 없다고 생각했을텐데..
본인 실수를 했는지 확인하는 것이... 쉽지 않다는 것이죠 _;
위와 같은 유형의 버그가 밤을 세우게 하고 _ ; 뭐 그렇다네요..

그래서 맨 위 전역 변수에게 ... CONST 라는 선물을 _ ;

반응형

'c' 카테고리의 다른 글

CreateProcess 예제  (0) 2008.10.13
bit test  (0) 2008.08.21
java IpAddress To dns name  (0) 2008.06.08
'LPSTR'에서 'LPCWSTR'(으)로 변환할 수 없습니다.  (0) 2008.05.11
[msdn] Windows Data Types  (0) 2008.05.09

+ Recent posts