CPB Mailing List

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Q: An executable file(.exe) must be started from another application.



First, thank you and thank you everyone on the list.

That's right. If several apps pass some parameters to 2nd app, 2nd app can
tell them apart.

//on app1's Button1 OnClick Event.
ShellExecute(0, NULL, "achieve.exe", "HowAreYou?", NULL, SW_SHOWNORMAL);

   //on app2's WinMain
   String sStr = GetCommandLine();
   //WinMain()'s LPSTR lpCmdLine doesn't work, not know why, so I use
   //GetCommandLine()
   ShowMessage(sStr);
   String sParam = sStr.SubString(sStr.LastDelimiter("\"")+2, sStr.Length()));
   ShowMessage(sParam);


The result shows sStr as follows:
     "C:\BCB\MyDB\app2.exe" HowAreYou?

ShowMessage shows sParam as
     HowAreYou?

It's easy for me to get the parameter
if it passes only one parameter.

But if there are several parameters, and may be only
use some of them everytime, how should I do?
For exemple,
 app2.exe param1 param2
 app2.exe param1 param2 param3 ...

Could I use agrv, argc to do that? Something like
void main(int argc, char *agrv[])
How to do that?

An interesting is I input that command in Dos Mode, the result is not the
same.

By the way, I find another way to the Question#1.
I use CreateMutex and FindWindow in app2's WinMain
to confirm that app1 is running and existing.

If not, app2 terminates.

About Question#2, Sorry ask that question. I think it may not
be possible to know who started it if app2 doesn't run to detect
and app1 doesn't pass some parameters to it.

Because for studying programming by myself,
sorry lack of some common sense.

_____________________
Best Regards,
      Juany Wu
_____________




W Komornicki's Home Page | Main Index | Thread Index