공유메모리 사용을 위한 큐생성(Shared memory)

Named Pipe 예제입니다.

참고하세요.

 

 

Compiler 개발관련하여 참조용 소스

VC++ 2003 compiler를 사용하였고,

Diaglog 를 만들어 command 창에서 수행시켜

그 메세지를 받아 richedit에 출력해주고,

더블클릭시 지정된 문자열을 읽어들어 소스 라인을 분석할 수 있도록 함.

하지만 line 추적시 좀더 세밀한 작업 필요

버그 있음.

xxx.cpp에 Thread를 생성한다.

 

// Thread Create.
HANDLE m_thread_cmd = NULL;
ULONG __stdcall autorun_Cmd_Execute(LPVOID pParam);

 

// thread를 생성하거나 실행시키는 부분.

// Command Line Run & exit.
if(m_thread_cmd ==NULL) m_thread_cmd =CreateThread(0,0, autorun_Cmd_Execute, this, 0,0);
else{ ::TerminateThread(m_thread_cmd ,0); m_thread_cmd =CreateThread(0,0, autorun_Cmd_Execute, this, 0,0); }

 

 

//////////////////////////////////////////////////////////////////////////
// Create :
// Update :
// Function : autorun_Cmd_Execute
// parameter: LPVOID pParam
// return : true, false
// review : the create Thread and then execute.
//////////////////////////////////////////////////////////////////////////
ULONG __stdcall autorun_Cmd_Execute(LPVOID pParam)

{

// 부모 핸들을 가져온다.

CTSDEV_BuilerDlg* pDlg=(CTSDEV_BuilerDlg*)pParam; //추가
if (pDlg == NULL || !pDlg->IsKindOf(RUNTIME_CLASS(CTSDEV_BuilerDlg))) return false;

}

 

하기 CreateProcess를 사용하여 VC++ Compiler를 이용,

자체 IDE 환경에서 컴파일러를 구현하는 경우,

지정된 Path에 따옴표를 하여 한 문자열로 인식되게끔하여야만,

컴파일이 되는것을 확인하였다.

^^ 음훼훼~~

 

 

#define VS2003DEVENV_PATH "\"E:/Program Files/Microsoft Visual Studio .NET 2003/Common7/IDE/devenv.com\""

 

xxx.h에 선언

HANDLE SpawnAndRedirect(LPCTSTR commandLine, HANDLE *hStdOutputReadPipe, LPCTSTR lpCurrentDirectory);

 

xxx.cpp에 사용함수와 선언부

{

// strSpawn의 내용으로, 실행시킬 full path+명령.exe parametor로 작성.

HANDLE hOutput, hProcess;
hProcess = SpawnAndRedirect(strSpawn, &hOutput, NULL);
if (!hProcess) return false;

 

// 종료시점 기다리기..
int fcnt=0;
m_flag=FALSE;
char buffer[1024]="";
char tbuffer[1025*3]="";
DWORD read=0;
while (ReadFile(hOutput, buffer, 1024, &read, NULL))
{
//buffer[read] = '\0';
strcat(tbuffer, buffer);
memset(buffer, 0, sizeof(buffer));
}

char *token="";
token=strtok(tbuffer,"\n");
m_flag=ErrorChk(token);
if(m_flag!=TRUE){fcnt++; AddMessage(FAIL, token);}
else CmdMsgBoxInit(PASS, token);
while(1){
token = strtok(NULL,"\n");
if(token == NULL) break;
m_flag=ErrorChk(token);
if(m_flag!=TRUE){fcnt++; AddMessage(FAIL, token);}
else AddMessage(PASS, token);
}

}

 

선언부..


BOOL CPG_SendDlg::ErrorChk(char *strbuf)
{
CString strmsg;
strmsg.Format("%s",strbuf);
//strmsg.MakeUpper();
int pos=strmsg.Find("Error:");
if(pos == -1) return TRUE;
return FALSE;
}


// The following function is a shortened variant of Q190351 - HOWTO: Spawn Console Processes with Redirected Standard Handles
// There is no special magic here, and this version doesn't address issues like:
// - redirecting Input handle
// - spawning 16-bits process (well, RTconsole is a 32-bit process anyway so it should solve the problem)
// - command-line limitations (unsafe 1024-char buffer)
// So you might want to use more advanced versions such as the ones you can find on CodeProject
HANDLE SpawnAndRedirect(LPCTSTR commandLine, HANDLE *hStdOutputReadPipe, LPCTSTR lpCurrentDirectory)
{
HANDLE hStdOutputWritePipe, hStdOutput, hStdError;
CreatePipe(hStdOutputReadPipe, &hStdOutputWritePipe, NULL, 0); // create a non-inheritable pipe
DuplicateHandle(GetCurrentProcess(), hStdOutputWritePipe,
GetCurrentProcess(), &hStdOutput, // duplicate the "write" end as inheritable stdout
0, TRUE, DUPLICATE_SAME_ACCESS);
DuplicateHandle(GetCurrentProcess(), hStdOutput,
GetCurrentProcess(), &hStdError, // duplicate stdout as inheritable stderr
0, TRUE, DUPLICATE_SAME_ACCESS);
CloseHandle(hStdOutputWritePipe); // no longer need the non-inheritable "write" end of the pipe

PROCESS_INFORMATION pi;
memset(&pi, 0, sizeof(pi));

STARTUPINFO si;
ZeroMemory(&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE); // (this is bad on a GUI app)
si.hStdOutput = hStdOutput;
si.hStdError = hStdError;
si.wShowWindow = SW_HIDE; // IMPORTANT: hide subprocess console window

TCHAR commandLineCopy[1024]; // CreateProcess requires a modifiable buffer
_tcscpy(commandLineCopy, commandLine);
if (!CreateProcess(NULL, commandLineCopy, NULL, NULL, TRUE,
CREATE_NEW_CONSOLE, NULL, lpCurrentDirectory, &si, &pi))
{
CloseHandle(hStdOutput);
CloseHandle(hStdError);
CloseHandle(*hStdOutputReadPipe);
*hStdOutputReadPipe = INVALID_HANDLE_VALUE;
return NULL;
}

CloseHandle(pi.hThread);
CloseHandle(hStdOutput);
CloseHandle(hStdError);
return pi.hProcess;
}

 

GUI 상태에서 Radio Button을 설정 후,

IDC_RADIO -> DDX(m_radio) 선언한다.

 

초기시 Radio를 default로 Check상태로 두려면,

m_radio.SetCheck(true);

 

Check되어있는 Radio Button을 알아오려면.

GetCheckedRadioButton(IDC_RTD110, IDC_RTD114);

1. Find Dialog Box를 생성해보자


bool CPG_SendDlg::FindTDDialog(int mode)
{
// TODO: Add your control notification handler code here
CFileDialog fDlg(TRUE); // file open
fDlg.m_ofn.lpstrTitle = "search! TD ROM *.pof Files";
fDlg.m_ofn.lpstrInitialDir = "c:/";

char szFilter[] = "pof Files (*.pof)\0*.pof\0All Files (*.*)\0*.*\0\0";
fDlg.m_ofn.lpstrFilter = szFilter;

// file select... not cancle
if(fDlg.DoModal() == 1){
m_sFilepath = fDlg.GetPathName();
m_sFilename = fDlg.GetFileName();
int pos=0;
CString tempstr = m_sFilepath.Tokenize(" ",pos);
int comparesize=m_sFilepath.GetLength();

if((pos-1) != comparesize) {
AfxMessageBox("Rom data File. full path Error!! confirm Please...\r\n"
"==> blank existence in fullpath(quartus not execute)!!");
return false;
}

 

CString temp=" "+m_sFilename;
GetDlgItem(mode)->SetWindowText(temp);

m_sTDpath[mode-IDC_PE1DP] = m_sFilepath;
m_sTDname[mode-IDC_PE1DP] = m_sFilename;
}

return true;
}
or

 

static char szFilter[] = "dll Files(*.dll)|*.dll";
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT , szFilter, NULL);

dlg.m_ofn.nMaxFile = MAX_PATH;
if (dlg.DoModal() == IDOK)
{
CString strpath = dlg.GetPathName(); // 파일의 풀 디렉토리 명을 얻는다.
CDevLink->SetDeviceName(strpath);
m_ctlEditDevPathDisp.SetWindowTextA(strpath);
Invalidate();
}

 

 

 

//////////////////////////////////////////////////////////////////////////
#include "tlhelp32.h" ==> h 필요.
void _LibProcSafeKill(); ==> function으로 작성.
//////////////////////////////////////////////////////////////////////////

 

void _LibProcSafeKill()
{
HANDLE hProcessSnap;
HANDLE hProcess;
DWORD dwPriorityClass;
CString strModuleName;
PROCESSENTRY32 pe32;
// Take a snapshot of all processes in the system.
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(hProcessSnap == INVALID_HANDLE_VALUE) return;

// Set the size of the structure before using it.
pe32.dwSize = sizeof(PROCESSENTRY32);

// Retrieve information about the first process,
// and exit if unsuccessful
if(!Process32First(hProcessSnap, &pe32))
{
CloseHandle(hProcessSnap); // Must clean up the snapshot object!
return;
}

// Now walk the snapshot of processes, and
// display information about each process in turn
do
{
// Retrieve the priority class.
dwPriorityClass = 0;
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);
if(hProcess == NULL)
continue;

strModuleName = (LPCTSTR)pe32.szExeFile;
strModuleName.MakeLower();
if(strModuleName.Find(_T("tos.exe")) > -1)
{
DWORD dwExitCode;
::GetExitCodeProcess(hProcess, &dwExitCode);
::TerminateProcess (hProcess, dwExitCode);
CloseHandle(hProcess);
break;
}
CloseHandle(hProcess);
} while(Process32Next(hProcessSnap, &pe32));
CloseHandle(hProcessSnap);
}

 

time_t timer;
struct tm *t;
/* gets time of day */
timer = time(NULL);
/* converts date/time to a structure */
t = localtime(&timer);
sprintf(today"%04d-%02d-%02d", t->tm_year+1900, t->tm_mon+1, t->tm_mday);

+ Recent posts