- CVI 정보나눔(www.cvi.kr)
- 스터디
- 개발메모
개발메모(형식에 매이지 않는 짤막한 개발 낙서)
글 수 174
하나의 프로그램이 동시에 여러개 실행되는 것을 막아야하는 경우도 있습니다. 이럴때, CheckForDuplicateAppInstance() 함수를 이용하면 편리합니다. CVI Online Help에 나와있는 예제를 조금 수정하였습니다.
int main (int argc, char *argv[])
{
int thereIsAnother;
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
// 이미 같은 프로그램이 실행되어 있다면, 프로그램 종료 처리 -시작
//KD_Check_DualAppInstance();
// 이미 같은 프로그램이 실행되어 있다면, 프로그램 종료 처리 -마침
// 혹은 같은 프로그램의 두번째 Instance인지를 테스트
if (CheckForDuplicateAppInstance (ACTIVATE_OTHER_INSTANCE, &thereIsAnother) == 0)
{
if (thereIsAnother)
{
MessagePopup("ChkAppInstance", "Prevent duplicate instance");
return 0; /* prevent duplicate instance */
}
}
else
{
MessagePopup("ChkAppInstance", "Out of memory, or not Win 2000/NT/9x");
return -1; /* out of memory, or not Win 2000/NT/9x */
}
// Panel Load
if ((panelHandle = LoadPanel (0, "ChkAppInstance.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
int main (int argc, char *argv[])
{
int thereIsAnother;
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
// 이미 같은 프로그램이 실행되어 있다면, 프로그램 종료 처리 -시작
//KD_Check_DualAppInstance();
// 이미 같은 프로그램이 실행되어 있다면, 프로그램 종료 처리 -마침
// 혹은 같은 프로그램의 두번째 Instance인지를 테스트
if (CheckForDuplicateAppInstance (ACTIVATE_OTHER_INSTANCE, &thereIsAnother) == 0)
{
if (thereIsAnother)
{
MessagePopup("ChkAppInstance", "Prevent duplicate instance");
return 0; /* prevent duplicate instance */
}
}
else
{
MessagePopup("ChkAppInstance", "Out of memory, or not Win 2000/NT/9x");
return -1; /* out of memory, or not Win 2000/NT/9x */
}
// Panel Load
if ((panelHandle = LoadPanel (0, "ChkAppInstance.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
함수명은 KD_Check_DualAppInstance() 입니다.