-
July 16th, 2008, 06:44 AM
#1
Passing value from one exe to another exe
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
-
July 16th, 2008, 06:47 AM
#2
Re: Passing value from one exe to another exe
For instance, using the clipboard.
-
July 16th, 2008, 06:49 AM
#3
Re: Passing value from one exe to another exe
-
July 16th, 2008, 07:00 AM
#4
Re: Passing value from one exe to another exe
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;
}
-
July 16th, 2008, 07:08 AM
#5
Re: Passing value from one exe to another exe
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.....
0100 0111 0110 1111 0110 0100 0010 0000 0110 1001 0111 0011 0010 0000 0110 0110 0110 1111 0111 0010
0110 0101 0111 0110 0110 0101 0111 0010 0010 0001 0010 0001 0000 0000 0000 0000 0000 0000 0000 0000
-
July 16th, 2008, 07:14 AM
#6
Re: Passing value from one exe to another exe
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.
-
July 16th, 2008, 07:20 AM
#7
Re: Passing value from one exe to another exe
Victor Nijegorodov
-
July 16th, 2008, 07:22 AM
#8
Re: Passing value from one exe to another exe
sockets,named pipes, windows events + (memorymapped) files
-
July 16th, 2008, 12:24 PM
#9
Re: Passing value from one exe to another exe
Originally Posted by VCProgrammer
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
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|