출처 : http://msdn2.microsoft.com/ko-kr/library/y817hyb6(VS.80).aspx

 

.NET Framework Visual Studio 프로그래머 가이드

Windows 서비스 응용 프로그램

Microsoft Visual Studio 또는 Microsoft .NET Framework SDK 사용하면 서비스로 설치되는 응용 프로그램을 만드는 방식으로 간편하게 서비스를 만들 있습니다. 이러한 응용 프로그램 형식을 Windows 서비스라고 합니다. 프레임워크 기능을 사용하여 서비스를 만들고, 설치하고, 서비스의 동작을 시작하거나 중지하고, 제어할 수도 있습니다.

참고

Visual Studio Standard Edition에서는 Windows 서비스 템플릿과 관련 기능을 사용할 수 없습니다. 자세한 내용은 Visual Studio Edition을 참조하십시오.

단원 내용

Windows 서비스 응용 프로그램 소개

Windows 서비스 응용 프로그램의 개요, 서비스의 수명 다른 공용 프로젝트 형식과 서비스 응용 프로그램 간의 차이점에 대한 간략한 설명을 제공합니다.

연습: 구성 요소 디자이너에서 Windows 서비스 응용 프로그램 만들기

Visual Basic, Visual C# Visual J#에서 서비스를 만드는 예제를 제공합니다.

서비스 응용 프로그램 프로그래밍 아키텍처

서비스 프로그래밍에 사용되는 언어 요소를 설명합니다.

방법: Windows 서비스 만들기

Windows 서비스 프로젝트 템플릿을 사용하여 Windows 서비스를 만들고 구성하는 과정을 설명합니다.

관련 단원

ServiceBase

서비스를 만드는 사용하는 ServiceBase 클래스의 주요 기능에 대해 설명합니다.

ServiceProcessInstaller

서비스를 설치하고 제거하는 ServiceInstaller 클래스와 함께 사용하는 ServiceProcessInstaller 클래스의 기능에 대해 설명합니다.

ServiceInstaller

서비스를 설치하고 제거하는 ServiceProcessInstaller 클래스와 함께 사용하는 ServiceInstaller 클래스의 기능에 대해 설명합니다.

Windows 서비스 모니터링

ServiceController 구성 요소를 사용하여 기존 서비스와 상호 작용하는 방법에 대해 설명합니다.

Visual Studio 기본 프로젝트 템플릿

장에서 사용되는 프로젝트 형식과 프로젝트를 선택하는 방법에 대해 설명합니다.

응용 프로그램 구성 요소 배포

배포에 관한 주요 페이지와 페이지에 포함된 정보를 보여 줍니다.

 

안정적인 DNS서비스 DNSEver DNS server, DNS service
Posted by 키르히아이스
,

CryptGenRandom

CryptGenRandom is a random number generator function that is included in Microsoft's Cryptographic Application Programming Interface. Microsoft recommends its use in all software where security is an issue.

Method of operation

All Microsoft-provided cryptography providers share the same implementation of CryptGenRandom, currently based on an internal function called RtlGenRandom. [1]. Only a general outline of the algorithm has been published as of 2006:

[RtlGenRandom] generates as specified in FIPS 186-2 appendix 3.1 with SHA-1 as the G function. And with entropy from:

  • The current process ID (GetCurrentProcessID).
  • The current thread ID (GetCurrentThreadID).
  • The tick count since boot time (GetTickCount).
  • The current time (GetLocalTime).
  • Various high-precision performance counters (QueryPerformanceCounter).
  • An MD4 hash of the user's environment block, which includes username, computer name, and search path. [...]
  • High-precision internal CPU counters, such as RDTSC, RDMSR, RDPMC
[omitted: long lists of low-level system information fields and performance counters]

Source: Writing Secure Code, Second Edition. ISBN 0-7356-1722-8. 

The exact algorithm has not been published, thus it is impossible for independent researchers to peer-review it and evaluate its effectiveness. Theoretical weaknesses include the use of outdated algorithms (such as MD4), and the reliance for entropy gathering on several monotonically-increasing counters that might be estimated or controlled to an extent by an attacker with local access to the machine.

See also

External links

 

=========================================================================================

 

MSDN : http://msdn2.microsoft.com/en-us/library/aa379942.aspx

 

CryptGenRandom(HCRYPTPROV,DWORD,BYTE) function [Security]

The CryptGenRandom function fills a buffer with cryptographically random bytes.

BOOL WINAPI CryptGenRandom( HCRYPTPROV hProv, DWORD dwLen, BYTE* pbBuffer );

Parameters

hProv

[in] Handle of a cryptographic service provider (CSP) created by a call to CryptAcquireContext.

dwLen

[in] Number of bytes of random data to be generated.

pbBuffer

[in, out] Buffer to receive the returned data. This buffer must be at least dwLen bytes in length.

Optionally, the application can fill this buffer with data to use as an auxiliary random seed.

Return Value

If the function succeeds, the return value is nonzero (TRUE).

If the function fails, the return value is zero (FALSE). For extended error information, call GetLastError.

The error codes prefaced by "NTE" are generated by the particular CSP being used. Some possible error codes are listed in the following table.

Return code

Description

ERROR_INVALID_HANDLE

One of the parameters specifies a handle that is not valid.

ERROR_INVALID_PARAMETER

One of the parameters contains a value that is not valid. This is most often a pointer that is not valid.

NTE_BAD_UID

The hProv parameter does not contain a valid context handle.

NTE_FAIL

The function failed in some unexpected way.

Remarks

The data produced by this function is cryptographically random. It is far more random than the data generated by the typical random number generator such as the one shipped with your C compiler.

This function is often used to generate random initialization vectors and salt values.

Software random number generators work in fundamentally the same way. They start with a random number, known as the seed, and then use an algorithm to generate a pseudo-random sequence of bits based on it. The most difficult part of this process is to get a seed that is truly random. This is usually based on user input latency, or the jitter from one or more hardware components.

With Microsoft CSPs, CryptGenRandom uses the same random number generator used by other security components. This allows numerous processes to contribute to a system-wide seed. CryptoAPI stores an intermediate random seed with every user. To form the seed for the random number generator, a calling application supplies bits it might have—for instance, mouse or keyboard timing input—that are then added to both the stored seed and various system data and user data such as the process ID and thread ID, the system clock, the system time, the system counter, memory status, free disk clusters, the hashed user environment block. This result is SHA-1 hashed, and the output is used to seed an RC4 stream, which is then used as the random stream and used to update the stored seed. If an application has access to a good random source, it can fill the pbBuffer buffer with some random data before calling CryptGenRandom. The CSP then uses this data to further randomize its internal seed. It is acceptable to omit the step of initializing the pbBuffer buffer before calling CryptGenRandom.

Example Code [C++]

The following example shows the generation of 8 random bytes. These can be used to create cryptographic keys or for any application that uses random numbers. For an example that includes the complete context for this example, see Example C Program: Duplicating a Session Key.

Copy Code

//-------------------------------------------------------------------- // Declare and initialize variables.

 

HCRYPTPROV hCryptProv;

BYTE pbData[16];

 

//-------------------------------------------------------------------- // This code assumes that a cryptographic context has been acquired // For code details, see "Example C Program: Duplicating a Session

// Key."

//--------------------------------------------------------------------

// Generate a random initialization vector.

if(CryptGenRandom( hCryptProv, 8, pbData))

{

printf("Random sequence generated. \n");

}

else

{

printf("Error during CryptGenRandom.\n"); exit(1);

}

Requirements

Client

Requires Windows Vista, Windows XP, Windows Me, Windows 2000 Professional, Windows 98, Windows NT Workstation 4.0, or Windows 95 OSR2 and later.

Server

Requires Windows Server "Longhorn", Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.

Redistributable

Requires Internet Explorer 3.02 or later on Windows 95.

Header

Declared in Wincrypt.h.

Library

Use Advapi32.lib.

DLL

Requires Advapi32.dll.

See Also

Key Generation and Exchange Functions
CryptAcquireContext
CryptGenKey
CryptSetKeyParam

 

 

 

안정적인 DNS서비스 DNSEver DNS server, DNS service
Posted by 키르히아이스
,

출처 : http://msdn.microsoft.com/ko-kr/library/bb385735.aspx

 

클래스 디자이너에서 Visual C++ 코드 사용

업데이트: 2007 11

클래스 디자이너에는 프로젝트의 코드 요소를 시각적으로 나타내 주는 클래스 다이어그램이라는 시각적 디자인 화면이 표시됩니다. 클래스 다이어그램을 사용하여 프로젝트의 클래스 기타 형식을 디자인하고 시각화할 있습니다.

이전 버전 Visual Studio 클래스 디자이너에서는 Visual C# Visual Basic 같은 관리되는 언어만 지원되었습니다. Visual Studio 2008 클래스 디자이너에서는 추가로 시각화 문서화에만 사용되는 네이티브 C++ 코드가 제한적으로 지원됩니다.

클래스 디자이너에서 지원되는 C++ 코드 요소는 다음과 같습니다.

  • 클래스(상속 관계가 여러 있을 있다는 점을 제외하고는 관리되는 클래스의 모양과 비슷함)
  • 익명 클래스(익명 형식에 대해 클래스 뷰에서 생성된 이름이 표시됨)
  • 템플릿 클래스
  • 구조체
  • 열거형
  • 매크로(후처리된 매크로 뷰가 표시됨)
  • 형식 정의

 형식 확인 표시 문제 해결

소스 파일의 위치

클래스 디자이너에서는 소스 파일의 위치를 추적하지 않습니다. 따라서 프로젝트 구조를 수정하거나 프로젝트의 소스 파일을 이동하면 특히 형식 정의, 기본 클래스 또는 형식 연결의 소스 형식에 대해 클래스 디자이너에서 해당 형식을 추적할 없게 됩니다. 또한 클래스 디자이너에서 형식을 표시할 없습니다. 같은 오류가 발생할 있습니다. 경우 수정하거나 재배치한 소스 코드를 클래스 다이어그램으로 다시 끌어 다시 표시합니다.

업데이트 성능 문제

Visual C++ 프로젝트의 경우 소스 파일의 변경 내용이 클래스 다이어그램에 나타나는 데는 30-60초가 소요될 있습니다. 시간 지연으로 인해 클래스 디자이너에서 선택한 항목에서 형식을 찾을 없습니다. 오류를 throw 수도 있습니다. 이와 같은 오류가 발생하면 오류 메시지에서 취소를 클릭하고 클래스 뷰에 해당 코드 요소가 나타날 때까지 기다립니다. 그런 후에 클래스 디자이너에서 해당 형식이 표시될 있습니다.

코드에서 변경한 내용으로 클래스 다이어그램이 업데이트되지 않으면 다이어그램을 닫았다가 다시 열어 보십시오.

형식 확인 문제

클래스 디자이너에서는 다음과 같은 경우에 형식을 확인할 없습니다.

  • 클래스 다이어그램이 속한 프로젝트에서 참조되지 않는 프로젝트나 어셈블리에 형식이 있습니다. 오류를 수정하려면 해당 형식을 포함하는 프로젝트나 어셈블리에 대한 참조를 추가합니다. 자세한 내용은 방법: Visual Studio에서 참조 추가 또는 제거(Visual Basic) 참조하십시오.
  • 형식이 올바른 범위에 있지 않아 클래스 디자이너에서 해당 형식을 찾을 없습니다. 경우 코드에 using, imports 또는 #include 문이 누락되지 않았는지 확인합니다. 또한 해당 형식이나 관련 형식을 원래 있던 네임스페이스 밖으로 이동하지 않았는지 확인합니다. 자세한 내용은 네임스페이스 구성 요소 참조 참조하십시오.
  • 형식이 존재하지 않거나 주석 처리되었습니다. 오류를 해결하려면 해당 형식을 실수로 주석으로 처리하거나 삭제하지 않았는지 확인합니다.

형식 확인 문제의 경우 가장 발생하기 쉬운 오류는 클래스 다이어그램 '<element>'에서 하나 이상의 모양에 대한 코드를 찾을 없습니다.입니다. 자세한 내용은 해당 오류의 설명을 참조하십시오.

특정 오류 메시지의 문제 해결

특정 오류 메시지의 문제 해결에 대한 자세한 내용은 클래스 디자이너 오류 메시지 오류 항목을 참조하십시오.

 C++ 코드 요소에 대한 제한

  • Visual C++ 프로젝트가 로드되면 클래스 디자이너는 읽기 전용 방식으로 작동합니다. , 클래스 다이어그램을 변경할 있지만 클래스 다이어그램에서 변경한 내용을 소스 코드에 저장할 수는 없습니다.
  • 클래스 디자이너에서는 네이티브 C++ 의미 체계만 지원됩니다. 관리 코드로 컴파일된 Visual C++ 프로젝트의 경우 클래스 디자이너에는 네이티브 형식인 코드 요소만 시각화됩니다. 따라서 프로젝트에 클래스 다이어그램을 추가할 수는 있지만 IsManaged 속성이 true 설정된 요소, 형식과 참조 형식은 클래스 디자이너에 시각화되지 않습니다.
  • Visual C++ 프로젝트의 경우 클래스 디자이너에서는 형식의 정의만 읽습니다. 예를 들어 헤더 파일(.h) 형식을 정의하고 해당 멤버는 구현 파일(.cpp) 정의할 경우, 구현 파일(.cpp)에서 "클래스 다이어그램 보기" 호출하면 클래스 디자이너에 아무 것도 표시되지 않습니다. 다른 예로, #include 문을 사용하여 다른 파일을 포함하지만 실제 클래스 정의는 포함하지 않는 .cpp 파일에서 "클래스 다이어그램 보기" 호출할 경우에도 클래스 디자이너에 아무 것도 표시되지 않습니다.
  • COM 인터페이스와 형식 라이브러리를 정의하는 IDL 파일(.idl) 네이티브 C++ 코드로 컴파일되기 전까지는 다이어그램에 표시되지 않습니다.
  • 클래스 디자이너에서는 전역 함수 변수가 지원되지 않습니다.
  • 클래스 디자이너에서는 공용 구조체가 지원되지 않습니다. 공용 구조체는 해당 데이터 멤버 가장 데이터 멤버에 필요한 만큼만 메모리가 할당되는 특수한 클래스 형식입니다.
  • 클래스 디자이너에서는 int, char 등의 기본 데이터 형식이 표시되지 않습니다.
  • 클래스 디자이너에서는 현재 프로젝트에 프로젝트 외부에 정의된 형식에 대한 올바른 참조가 없을 경우 해당 형식이 표시되지 않습니다.
  • 클래스 디자이너에서 중첩된 형식을 표시할 수는 있지만 중첩된 형식과 기타 형식 사이의 관계는 표시할 없습니다.
  • 클래스 디자이너에서는 void 형식이거나 void 형식에서 파생된 형식을 표시할 없습니다.

안정적인 DNS서비스 DNSEver DNS server, DNS service
Posted by 키르히아이스
,

출처 : http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=51&MAEULNO=20&no=7451

 

Runtime Library

 

Visual C++ 프로젝트 속성에서 C/C++ -> Code Generation -> Runtime Library 항목을 보면 다음과 같은 4가지 값이 있는데..

/MT
/MTd
/MD
/MDd

/MD, /MDd 옵션에서는 MSVCRT~~~.dll을 쓴다. depends.exe 를 통해 확인

 

혹시 MSVCRT~~.dll 브라더스 땜에 실행 파일 배포시에 문제가 생긴다면 (1)을 고려해 볼만 하다.

아니면 옵션을 바꿔서 컴파일을 다시 하덩가.

 

manifest 파일

 

Visual Studio 2005 부터는 manifest 파일은 무조건 generate 되도록 했다고 한다. msdn에서 보니깐...

그건 그거고 실행파일에 embed 시킬지 말지는 프로젝트 속성에서 정할 수 있다.

 

예전에 manifest 파일내용과 depends.exe 로 살펴본 dll 들이 달라서 실행파일이 실행되지 않은 경우가 있었다.

notepad 로 manifest 파일을 열어보고서야 알았는데...

VC++ 6.0프로젝트를 컨버팅하다 발생한 현상인지, VS2005 버그인지, MS에서 의도한 걸 내가 잘못 이해했던지.. 중에 하나일듯.

manifest 파일때문에 실행파일에 오류가 발생되는 것이 의심될 때
1. 프로젝트 속성->Manifest Tool->Input and Output->Embed Manifest->No 로 설정.
2. 컴파일 한후 ***.manifest 파일을 노트패드에서 연다. manifest파일 이름은 프로젝트 속성->Linker->Manifest File->Manifest File에서 확인
3. 파일 내용을 편집한다. 편집내용은 (2)를 참고

sample:
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.VC80.CRT" version="8.0.50608.0" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
    </dependentAssembly>
  </dependency>
</assembly>

4. mt.exe 를 실행해서 실행파일에 manifest 파일을 embed 시킨다.
mt.exe 사용은 (3)을 참고.

sample:
mt.exe –manifest MyApp.exe.manifest -outputresource:MyApp.exe;1

 

 

 

 

<Reference>
(1) Microsoft Visual C++ 2005 Redistributable Package (x86)
http://www.microsoft.com/downloads/details.aspx?FamilyID=32bc1bee-a3f9-4c13-9c99-220b62a191ee&DisplayLang=en

(2) Troubleshooting C/C++ Isolated Applications and Side-by-side Assemblies 
http://msdn2.microsoft.com/en-us/library/ms235342.aspx

(3) How to: Embed a Manifest Inside a C/C++ Application
http://msdn2.microsoft.com/en-us/library/ms235591.aspx

안정적인 DNS서비스 DNSEver DNS server, DNS service
Posted by 키르히아이스
,