| 1 |
/* |
| 2 |
* FeliCa2Money |
| 3 |
* |
| 4 |
* Copyright (C) 2001-2007 Takuya Murakami |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 |
*/ |
| 20 |
//--------------------------------------------------------------------------- |
| 21 |
#include <vcl.h> |
| 22 |
#pragma hdrstop |
| 23 |
#include <stdio.h> |
| 24 |
|
| 25 |
#include "SfcPeep.h" |
| 26 |
|
| 27 |
//--------------------------------------------------------------------------- |
| 28 |
class SFCPeep *SfcPeep = NULL; |
| 29 |
|
| 30 |
//--------------------------------------------------------------------------- |
| 31 |
/// constructor |
| 32 |
SFCPeep::SFCPeep(void) |
| 33 |
{ |
| 34 |
lines = new TStringList; |
| 35 |
} |
| 36 |
//--------------------------------------------------------------------------- |
| 37 |
/// destructor |
| 38 |
SFCPeep::~SFCPeep() |
| 39 |
{ |
| 40 |
delete lines; |
| 41 |
} |
| 42 |
|
| 43 |
//--------------------------------------------------------------------------- |
| 44 |
/** |
| 45 |
@brief SFCPeep �����s |
| 46 |
@param[in] arg SFCPeep���n���I�v�V���� |
| 47 |
@return �G���[�R�[�h (0:����, -1:���s) |
| 48 |
|
| 49 |
�������������f�[�^�� lines ���i�[�������B |
| 50 |
*/ |
| 51 |
int SFCPeep::Execute(AnsiString arg) |
| 52 |
{ |
| 53 |
AnsiString cmdline; |
| 54 |
|
| 55 |
cmdline.sprintf("\"%s\" %s", SFCPeepPath.c_str(), arg.c_str()); |
| 56 |
STARTUPINFO si; |
| 57 |
PROCESS_INFORMATION pi; |
| 58 |
|
| 59 |
// open temp file |
| 60 |
SECURITY_ATTRIBUTES sa; |
| 61 |
memset(&sa, 0, sizeof(sa)); |
| 62 |
sa.nLength = sizeof(sa); |
| 63 |
sa.lpSecurityDescriptor = NULL; |
| 64 |
sa.bInheritHandle = TRUE; |
| 65 |
HANDLE hFile = CreateFile(TempFile.c_str(), |
| 66 |
GENERIC_READ | GENERIC_WRITE, |
| 67 |
FILE_SHARE_READ | FILE_SHARE_WRITE, |
| 68 |
&sa, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
| 69 |
|
| 70 |
// create process |
| 71 |
memset(&si, 0, sizeof(si)); |
| 72 |
si.cb = sizeof(si); |
| 73 |
si.dwFlags = STARTF_USESTDHANDLES; |
| 74 |
si.hStdInput = stdin; |
| 75 |
si.hStdOutput = hFile; |
| 76 |
si.hStdError = hFile; |
| 77 |
memset(&pi, 0, sizeof(pi)); |
| 78 |
int ret = CreateProcess(NULL, cmdline.c_str(), NULL, NULL, TRUE, |
| 79 |
CREATE_NO_WINDOW, NULL, |
| 80 |
ExtractFilePath(SFCPeepPath).c_str(), |
| 81 |
&si, &pi); |
| 82 |
|
| 83 |
if (ret == 0) { |
| 84 |
Application->MessageBox("SFCPeep ���s�G���[\n�������m�F������������", "�G���[", MB_OK); |
| 85 |
CloseHandle(hFile); |
| 86 |
return -1; |
| 87 |
} |
| 88 |
|
| 89 |
WaitForSingleObject(pi.hProcess, INFINITE); |
| 90 |
CloseHandle(hFile); |
| 91 |
|
| 92 |
lines->LoadFromFile(TempFile); |
| 93 |
DeleteFile(TempFile); |
| 94 |
|
| 95 |
return 0; |
| 96 |
} |
| 97 |
|
| 98 |
#pragma package(smart_init) |