Hi all,
I am having two exe's, I am running one exe through another using API ShellExecute.... Now what i want is i want to pass a value from one exe to another and want to use that value in second exe. How is this possible???
Thanks in advance
Printable View
Hi all,
I am having two exe's, I am running one exe through another using API ShellExecute.... Now what i want is i want to pass a value from one exe to another and want to use that value in second exe. How is this possible???
Thanks in advance
For instance, using the clipboard.
can u tell me how
Okay, but I don't pretend my solution is the best one.
I use old C programming stuff. Please don't laugh at me.
Code:static LPSTR to_clip_mem = NULL;
int put_txt_in_clipboard(HWND hwnd, char *to_clip)
{
HANDLE hto_clip_mem;
if (to_clip_mem != NULL)
GlobalFree(to_clip_mem);
to_clip_mem = (char *) GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, to_clip_lg + 1);
if (to_clip_mem == NULL)
return FALSE;
hto_clip_mem = GlobalLock(to_clip_mem);
if (!(hto_clip_mem)) {
GlobalFree(to_clip_mem);
return FALSE;
}
lstrcpy((char *)hto_clip_mem, to_clip);
GlobalUnlock(to_clip_mem);
if (OpenClipboard(hwnd) == 0)
return FALSE;
if (EmptyClipboard() == 0) {
CloseClipboard();
return FALSE;
}
if (SetClipboardData(CF_TEXT, to_clip_mem) == NULL) {
CloseClipboard();
return FALSE;
}
if (CloseClipboard() == 0)
return FALSE;
return TRUE;
}
int get_txt_from_clipboard(HWND hwnd, char *from_clip, int from_clip_max)
{
HANDLE hclip; LPSTR clip_mem; int clip_mem_lg;
int from_clip_lg;
if (IsClipboardFormatAvailable(CF_TEXT) == 0)
return FALSE;
if (OpenClipboard(hwnd) == 0)
return FALSE;
hclip = GetClipboardData(CF_TEXT);
if (hclip == 0) {
CloseClipboard();
return FALSE;
}
clip_mem_lg = GlobalSize(hclip);
if (clip_mem_lg <= 0) {
CloseClipboard();
return FALSE;
}
clip_mem = (char *)GlobalLock(hclip);
if (clip_mem == NULL) {
CloseClipboard();
return FALSE;
}
from_clip_lg = clip_mem_lg;
if (from_clip_lg >= from_clip_max) from_clip_lg = from_clip_max - 1;
for (i = 0; i < from_clip_lg; i++)
from_clip[i] = clip_mem[i];
from_clip[i] = '\0';
GlobalUnlock(hclip);
if (CloseClipboard() == 0)
return FALSE;
return TRUE;
}
well there is a simpler way. It deals with sendmessage.. that is if both of your exes run through the message queue. You use RegisterWindowMessage to register a message in both apps and process the message in each app's message queue.....
You could also pass the value on the command line by means of ShellExecute's lpParameters string. The called program would then use ::GetCommandLine() to retrieve the value.
Other possibilities: Interprocess Communications
sockets,named pipes, windows events + (memorymapped) files
What type of value is it? If it's a simple int or short string you can pass it as an argument in the command line when you fire the second process. If you to pass something else (like a structure or a large string), check out the Interprocess Communication link provided earlier.Quote:
Originally Posted by VCProgrammer