一个困饶我好久的问题
A程序调用B程序 B程序如果返回一个值(1或者0)
A程序怎么检测这个值呢!
小第写一个安装制作程序,设计到注册码的问题。
安装程序setupbulider.exe
注册码验证程序 project1.exe
小第打算这样做在setupbulider.exe
带参调用project1.exe ->winexec(pchar('projec1.exe '+'注册码 '+' 验证码'),sw_hide)
注册码验证程序启动后,立刻验证该注册码,如果通过返回1,没通过返回0
可是小第不知道如何返回(返回了setupbulider.exe又如何接收呢),查了好久sdk好象mpi可以用,但搞不清楚
!
问题点数:100、回复次数:8Top
1 楼aiirii(ari-http://spaces.msn.com/members/aiirii/)回复于 2004-08-03 15:54:08 得分 70
////////////////////////////////////////////////////////////////
// AppName: name (including path) of the application
// AppArgs: command line arguments
// Wait: 0 = don't wait on application
// >0 = wait until application has finished (maximum in milliseconds)
// <0 = wait until application has started (maximum in milliseconds)
// Hide: True = application runs invisible in the background
// ExitCode: exitcode of the application (only avaiable if Wait <> 0)
//
function STO_ShellExecute(const AppName, AppArgs: String; const Wait: Integer;
const Hide: Boolean; var ExitCode: DWORD): Boolean;
var
myStartupInfo: TStartupInfo;
myProcessInfo: TProcessInformation;
sAppName: String;
iWaitRes: Integer;
begin
// initialize the startupinfo
FillChar(myStartupInfo, SizeOf(TStartupInfo), 0);
myStartupInfo.cb := Sizeof(TStartupInfo);
myStartupInfo.dwFlags := STARTF_USESHOWWINDOW;
if Hide then // hide application
myStartupInfo.wShowWindow := SW_HIDE
else // show application
myStartupInfo.wShowWindow := SW_SHOWNORMAL;
// prepare applicationname
sAppName := AppName;
if (Length(sAppName) > 0) and (sAppName[1] <> '"') then
sAppName := '"' + sAppName + '"';
// start process
ExitCode := 0;
Result := CreateProcess(nil, PChar(sAppName + ' ' + AppArgs), nil, nil, False,
NORMAL_PRIORITY_CLASS, nil, PChar(ExtractFilePath(AppName)),
myStartupInfo, myProcessInfo);
// could process be started ?
if Result then
begin
// wait on process ?
if (Wait <> 0) then
begin
if (Wait > 0) then // wait until process terminates
iWaitRes := WaitForSingleObject(myProcessInfo.hProcess, Wait)
else // wait until process has been started
iWaitRes := WaitForInputIdle(myProcessInfo.hProcess, Abs(Wait));
// timeout reached ?
if iWaitRes = WAIT_TIMEOUT then
begin
Result := False;
TerminateProcess(myProcessInfo.hProcess, 1);
end;
// getexitcode
GetExitCodeProcess(myProcessInfo.hProcess, ExitCode);
end;
CloseHandle(myProcessInfo.hProcess);
end;
end;
Top
2 楼aiirii(ari-http://spaces.msn.com/members/aiirii/)回复于 2004-08-03 15:56:07 得分 0
CreateProcess
GetExitCode
應該可返回你要的東西, 但你這樣很不安全, 我覺得, 人家要是替換你的
>>注册码验证程序 project1.exe
自己返回呢??
最好用共享全局內存變量
or 消息類傳剃Top
3 楼lianshaohua(永远深爱一个叫“...”的好女孩儿!)回复于 2004-08-03 15:56:23 得分 5
一、可以A,B共享一块内存区域,然后如果B执行完了,向这块共享区写入一个值,然后发一条自定的信息通知A,就可以了,Top
4 楼GoldShield(李柏岑)回复于 2004-08-03 16:39:48 得分 5
学习一下Top
5 楼wizardqi(男巫)回复于 2004-08-03 16:52:28 得分 5
正如aiirii(ari-爱的眼睛) 所说,楼主这样做很不安全。
可以将注册文件做成DLL,当安装时调用该DLL的某个函数进行校验注册,这要安全很多。Top
6 楼ylyxd622(yxd)回复于 2004-08-03 18:16:32 得分 5
学习中
Top
7 楼ghchen()回复于 2004-08-04 09:07:54 得分 5
upTop
8 楼waini12(魔刀王子)回复于 2004-08-04 09:22:56 得分 5
一点都不明白Top




