|
Or CreateProcess()
Todd Smith
|
|
|
|
|
I'm working on a program which is not allowed to be run more than once in same directory, but is allowed to be run as many times as users want if the programs are located in diffrent directory. For example, suppose my program is named "abc.exe":
run c:\path1\abc.exe -> OK
run c:\path1\abc.exe -> Not OK
However:
run c:\path1\abc.exe -> OK
run c:\path2\abc.exe -> OK
run c:\path3\abc.exe -> OK
I wish I explained clear enoguh in above scenario. Now, to accomplish this, I thought using mutex should be good, this is how I did:
In beginning of the program I use GetModuleFileName to obtain application path and store it in a string, say g_szAppPath , and I use this string to create MUTEX object. Hmm, I thought it should work since g_szAppPath would only be different if the programs are located in different directory, is it not? But somehow this method does not work, I can always run the program multiple times in same directory.
What am I doing wrong? Is there a good way to get what I want? Thanks guys.
|
|
|
|
|
errrrrr
getcurrentdirectory() ?
"even if my world is weird it's my world" biz stuff about me
|
|
|
|
|
it is very easy, save running exes in a file or register, check before a new exe runs.
includeh10
|
|
|
|
|
This is what I would try:
CString strFile;
::GetModuleFileName(NULL, strFile.GetBuffer(MAX_PATH), MAX_PATH);
strFile.ReleaseBuffer();
CMutex(FALSE, strFile);
if (::GetLastError() == ERROR_ALREADY_EXISTS)
return FALSE;
static CMutex mutex(FALSE, strFile);
[edit]Put this in your InitInstance and try it.[/edit]
Regards,
Alvaro
There is much pleasure to be gained from useless knowledge. - Bertrand Russell
|
|
|
|
|
Thank you. I tried but got runtime error as shown below:
--------------------------------------------
Microsoft Visual C++ runtime library error:
Program: c:\blahblah\blah.exe
Abnormal program termination.
---------------------------------------------
Don't know what's wrong...
|
|
|
|
|
Yep, I tried it and it blew up on me too. For some reason it didn't like the name of the mutex (with the backslashes). I replaced the backslashes with regular slashes and it works like a champ. I also changed to code to be a little simpler:
CString strMutex;
::GetModuleFileName(NULL, strMutex.GetBuffer(MAX_PATH), MAX_PATH);
strMutex.ReleaseBuffer();
strMutex.Replace('\\', '/');
static CMutex mutex(FALSE, strMutex);
if (::GetLastError() == ERROR_ALREADY_EXISTS)
return FALSE;
Regards,
Alvaro
There is much pleasure to be gained from useless knowledge. - Bertrand Russell
|
|
|
|
|
YES man! Finally!
OK it works perfectly now, so the real trick is that we cannot have back-slashes in a mutex name, damn it, where in MSDN said that?
Thank you a lot.
Bin
|
|
|
|
|
i saved lparam and wparam values when a key
(say U)pressed on a perticuler edit box.
i want to use these values of lparam and wparam again on different edit box.in order to see that key
(say U) .
is that code is correct or not for that purpose?
is there any change in logic if yes then plz tell?
LPEVENTMSG lpEvent= (LPEVENTMSG)lParam;
PostMessage(different_hWnd,
lpEvent->message,wParam,lParam);
r00d0034@yahoo.com
|
|
|
|
|
Where does the second editbox reside?
Kuphryn
|
|
|
|
|
infect second edit box reside on different procss
r00d0034@yahoo.com
|
|
|
|
|
Assuming you design and implement both processes, the simplest solution to sending the data between the two edit boxes is file mapping and named object.
I am not familiar with the code you posted.
Kuphryn
|
|
|
|
|
how to make lparam and wparam of a kewdown message so that i can put into postmessage with an hwnd of edit box in order to see a perticuler key pressed into an edit box?
r00d0034@yahoo.com
|
|
|
|
|
You've been asking this question for days. Have you written any code in that time ? What is not working ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
yes i have developed an applecation which can install any type of software with out any user interaction on the network i have used (vb.net,csharp,vc.net).
for that purpose i have recorded events and stroed it into a file and with the help of threading i have replay it. it work nicesly but only for mouse events it works.
but it dont work for keboard events.
i dont know why thats why i am asking this question again and again plz help me.
plzzzzzzzzz
r00d0034@yahoo.com
|
|
|
|
|
What I'm asking is if you've tried anything to make it work, and if so, what ? You see, the more info you provide, the easier it is to help you, and it gives the impression you're doing more than just asking over and over again.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
i am giving you some part of my code so that you could help.
plz see it.
if part works but else dont (which is my problem).
if(E_to_Match->message==WM_LBUTTONUP){
::SetCursorPos(fp.x,fp.y);
PostMessage(h,WM_LBUTTONDOWN,0,0);
PostMessage(h,WM_LBUTTONDOWN,0,0);
::Sleep(500);
PostMessage(h,E_to_Match->message,0,0);
}else
{
::Sleep(2000);
PostMessage(h,E_to_Match->message,(WPARAM)E_to_Match->wParam,(LPARAM)E_to_Match->lParam);
}
only else part dont work here.
Control tranfer here only when a keydown and keyup message appear
before that i store E_to_Match object and set its values
in a CALLBACK function
LRESULT CALLBACK JournalRecorderFunc(int nCode, WPARAM wParam, LPARAM lParam)
{
...
...
E_to_Match->Class_name=c_n;
E_to_Match->W_text=wn;
E_to_Match->wParam=(Int32)wParam;
E_to_Match->f_point_x=f_point.x;
E_to_Match->f_point_y=f_point.y;
E_to_Match->lParam=(Int32)lParam;
E_to_Match->C_pt_x=C_pt.x;
E_to_Match->C_pt_y=C_pt.y;
E_to_Match->w_Level=w_Level;
LPEVENTMSG lpEvent2=(LPEVENTMSG)lParam;
Current_event->message=lpEvent2->message;
....
....
}
plz reply whats the problem with else part?
what to do because in else part hwnd is correct but dont displa key that is pressed.
it perform both keydown and keyup messages.
when i placed following line of code it display 777 in edit box.
i dont know why.
PostMessage(h,E_to_Match->message,103,
(LPARAM)E_to_Match->lParam); i am waiting for ur reply
r00d0034@yahoo.com
|
|
|
|
|
Have you traced through the code and verified that exactly the same PostMessage is occuring in both instances, with all parameters the same values ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
yes i have checked that whan key board event have to execute only then else part executed hwnd is also correct
because when i put that line in else part it will dispaly 777 in edit box
PostMessage(hWnd,
lpEvent->message,103,lParam);
r00d0034@yahoo.com
|
|
|
|
|
I'm using Chris Maunder's excellent CSystemTray class and I'm having some odd behavior that has to do with icon size. I don't believe that this has anything to do with Chris' class, but I thought I'd throw that in. What I'm finding is that the tray icon that's being inserted is the icon for my application, but an interpolated version of the large icon, not the real 16 x 16 icon. I've messed with SetIcon(icon,TRUE/FALSE) before inserting the icon in the tray to no avail. What's the proper procedure for guaranteeing the proper icon displays.
Paul Oss
|
|
|
|
|
Have you tried explicitly loading the 16x16 version of your icon, then setting this into the tray class?
I have run into this problem before, when just dealing with the shell tray directly.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
I have not. I guess I'm ignorant as to how to do that. I know how to load the icon (as resource) and then set the 16 x 16 through the SetIcon(xxx,BOOL) api (but that's not working for me). How do I explicitly load the 16 x 16 icon?
Paul Oss
|
|
|
|
|
You need to use the ::LoadImage API function, and specify the size for the icon, 16 x 16. Also, for the tray with anything below Win2000 and win9x you can only use the VGA palette for systray icons.
Good Luck
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Be sure you use LoadImage() to load a 16x16 icon. LoadIcon() only loads 32x32 (the AppWizard generated code does this, but it's buggy).
--Mike--
"I'd rather you just give me a fish today, because even if you teach me how to fish, I won't do it. I'm lazy." -- Nish
Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
#include <hash_map>
#include <string>
void foo {
std::hash_map<std::string, int> queries;
queries.find(std::string()); }
produces
C:\...\xhash(38): error C2440: 'type cast' : cannot convert from 'const std::string' to 'size_t'
error. That looks like a bug to me, since that is a fine C++ code.
looking into xhash we see
size_t operator()(const _Kty& _Keyval) const
{ // hash _Keyval to size_t value
return ((size_t)_Keyval);
}
which is at least weird.
Any comments?
|
|
|
|