성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] 아래의 글을 보면, MoveWindow 하면 될 듯한데요. ^^...
[Tom Lee] 안녕하세요 올려주신 글 참고하여 WPF 어플리케이션 안에 Uni...
[정성태] A graphical depiction of the steps ...
[정성태] 질문을 주셔서 출판사 측에 문의를 했습니다. 약 한 달 정도 후...
[Thorondor
] @정성태 개인 블로그인데도 거의 커뮤니티 급 인 것 같아요. 요...
[정성태] Roll A Lisp In C - Reading ; https...
[정성태] Java - How to use the Foreign Funct...
[정성태] 제가 큰 실수를 했군요. ^^; Delegate를 통한 Bein...
[정성태] Working with Rust Libraries from C#...
[정성태] Detecting blocking calls using asyn...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>C/C++ - SYSTEMTIME 값 기준으로 특정 시간이 지났는지를 판단하는 함수</h1> <p> C#으로 구현하면 이런 식인데,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > static void Main(string[] args) { DateTime old = DateTime.Now; Thread.Sleep(1000); if ((DateTime.Now - old).TotalMilliseconds > 1000) { Console.Write("Hello"); } Console.WriteLine("World!"); } </pre> <br /> Windows 환경의 C/C++에서 SYSTEMTIME으로 저 작업을 하려니 코드가 좀 복잡해지는데, ^^ 제 경우에는 stackoverflow의 어느 코드인가를 참고해서 다음과 같이 만들어봤습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > bool IsElapsedTime(SYSTEMTIME* oldTime, SYSTEMTIME* currentTime, ULONGLONG milliSeconds) { union TimeUnit { ULARGE_INTEGER li; FILETIME ft; }; TimeUnit oldUnit, newUnit; SystemTimeToFileTime(oldTime, &oldUnit.ft); SystemTimeToFileTime(currentTime, &newUnit.ft); // Add in the seconds oldUnit.li.QuadPart += (milliSeconds * 10000); // 1 milli == 1000000 nano // 1 milli == 10000 * 100 nano return oldUnit.li.QuadPart <= newUnit.li.QuadPart; } </pre> <br /> SYSTEMTIME을 FileTime으로 바꾸면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > SYSTEMTIME structure ; <a target='tab' href='https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-systemtime'>https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-systemtime</a> FILETIME structure ; <a target='tab' href='https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime'>https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime</a> </pre> <br /> QuadPart에 1이 있는 경우 그 값이 100 나노초가 되므로 밀리 초를 나타내기 위해 10,000을 곱하는 식으로 해결하면 됩니다.<br /> <br /> 어쨌든 사용법은, 요런 식으로 할 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > if (DateTimeExtension::IsElapsedTime(&oldTime, &currentTime, 500) == true) { // 500ms 지난 후 해야 할 작업 수행 } </pre> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
1694
(왼쪽의 숫자를 입력해야 합니다.)