我已经做了一些研究,寻找从CreateProcess()创建的进程中检索数据的最佳方法,但不幸的是,我没有太多运气。如果有人能指出我正确的方向,将非常感激。
我在C中有一个非常基本的控制台应用程序。这是源代码,
int main() {
STARTUPINFO si;
PROCESS_INFORMATION pi;
char CommandLine[1024] = "\"\" \"501 Willow\" \"\" \"Greenville\" \"AL\" \"36037\"";
memset (&si, 0, sizeof(si));
memset (&pi, 0, sizeof(pi));
GetStartupInfo(&si);
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
if (CreateProcess (("C:\\pathTO\\ValidateRDI.exe"), CommandLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi) != 0) {
printf("Separate Process created\n");
}
else {
printf("Separate Process not created. Error occurred\n");
}
WaitForSingleObject( pi.hProcess, INFINITE );
return 0;
}
CreateProcess运行另一个调用DLL的C控制台应用程序,如此,
typedef void (CALLBACK* LPFNDLLFUNC1)(char*,char*,char*,char*,char*,char*,char*,char*,char*,char*,char*);
int main(int argc, char* argv[]){
HMODULE hDLL;
LPFNDLLFUNC1 lpfnDllFunc;
char name[35+1] = "";
char addr1[35+1] = "";
char addr2[35+1] = "";
char city[20+1] = "";
char state[2+1] = "";
char zip[10+1] = "";
char rdi[1+1] = "";
char returnCode[2+1] = "";
char returnText[101] = "";
char errorWarningCode[2+1] = "";
char errorWarningText[100+1] = "";
sprintf(name, argv[0]);
sprintf(addr1, argv[1]);
sprintf(addr2, argv[2]);
sprintf(city, argv[3]);
sprintf(state, argv[4]);
sprintf(zip, argv[5]);
hDLL = LoadLibraryA((LPCSTR)"ValidateRDI.dll");
if (hDLL != NULL)
{
lpfnDllFunc = (LPFNDLLFUNC1)GetProcAddress(hDLL,"ValidateAddress");
if(lpfnDllFunc)
{
lpfnDllFunc(name,addr1,addr2,city,state,zip,rdi,returnCode,returnText,errorWarningCode,errorWarningText);
}
// free library
FreeLibrary(hDLL);
}
return 1;
}
只是为了抬头,我删除了一些错误检查以减少代码。 如何将以下值传回(或共享变量)到调用CreateProcess()的控制台应用程序:
感谢任何和所有帮助。我曾想过将值写入文件,然后在 WaitForSingleObject(pi.hProcess,INFINITE); 返回时访问数据,但必须有更有效/更好的方法。