PPCGeeks

PPCGeeks (http://forum.ppcgeeks.com/index.php)
-   HTC Touch Pro (http://forum.ppcgeeks.com/forumdisplay.php?f=63)
-   -   Running two instances of a program at the same time? (http://forum.ppcgeeks.com/showthread.php?t=68953)

garyflynn 05-17-2009 10:04 PM

Running two instances of a program at the same time?
 
I'd like to run two copies of tcmp music player, one playing a podcast, one playing background music.

Is it possible to do that?

havox22 05-17-2009 10:12 PM

Re: Running two instances of a program at the same time?
 
Quote:

Originally Posted by garyflynn (Post 921074)
I'd like to run two copies of tcmp music player, one playing a podcast, one playing background music.

Is it possible to do that?

im not sure but have u tried using tcmp for the podcast & wmp or something similar for your background music??

volDeus 05-17-2009 10:15 PM

Re: Running two instances of a program at the same time?
 
It depends completely on the complexity of the program you are running... What resources it uses and wether or not it uses intelligent checks for another copy of itself running at it's startup BUT! .....

Make a copy of the .EXE with a different name ... I have used it in the past and sometimes it works ...

EDIT: If you are having trouble ... copy the .EXE to another folder .. navigate to that folder .. rename the .EXE .. copy the renamed .EXE back to the original folder ..

theedon 05-17-2009 10:55 PM

Re: Running two instances of a program at the same time?
 
Most windows mobile programs will sense if a previous instance is alreasy running and instead of starting another instance it will simply tell the running program to move to the forground.

i believe the code for tcpmp is open so you can get the code and change its behavior. otherwise.... as suggested before use another program... gsplayer is quite nice.

volDeus 05-18-2009 12:44 PM

Re: Running two instances of a program at the same time?
 
Quote:

Originally Posted by theedon (Post 921149)
Most windows mobile programs will sense if a previous instance is alreasy running and instead of starting another instance it will simply tell the running program to move to the forground.

In most cases, when you see this behavior it's caused by the OS, not the application itself ... In my experience, the only check done by the OS to determine wether or not the application you are trying to execute is already running, is wether or not it's executable's filename matches one of the currently running processes ...

Although some more complicated (and more safely written) applications will be more "clone-aware" ... The majority of smaller WM apps will not, and can be "cloned" through the renaming method I posted above.

I have used this method many times in the past and it is effective... Unfortunately it does not work with TCPMP (I just tested it)...

Considering that, I agree with the earlier post suggesting that you use multiple applications...

theedon 05-18-2009 10:50 PM

Re: Running two instances of a program at the same time?
 
Quote:

Originally Posted by volDeus (Post 921919)
In most cases, when you see this behavior it's caused by the OS, not the application itself ... In my experience, the only check done by the OS to determine wether or not the application you are trying to execute is already running, is wether or not it's executable's filename matches one of the currently running processes ...

Although some more complicated (and more safely written) applications will be more "clone-aware" ... The majority of smaller WM apps will not, and can be "cloned" through the renaming method I posted above.

I have used this method many times in the past and it is effective... Unfortunately it does not work with TCPMP (I just tested it)...

Considering that, I agree with the earlier post suggesting that you use multiple applications...

get yourself a copy of ms visual studio 2008. instantiate an unmanaged code project (thats win32 C++). now compile and run. thats it... the default template has the check pre coded for you. when im back at my computer i'll post the actual lines of code. it requires the coder to specifically change the behavior. the template also hard codes the window name and the window class. the reason it does this is so that it can do a search with those two inputs to determine if the program is running. that is why changing the program name doesnt always work. the coder has to tell the program to allo such behavior. but, the default template does not allow that.

now since tcpmp is written in unmanaged code and it behaves as i have described... need i say more?


Promised code:

//If it is already running, then focus on the window, and exit
hWnd = FindWindow(szWindowClass, szTitle);
if (hWnd)
{
// set focus to foremost child window
// The "| 0x00000001" is used to bring any owned windows to the foreground and
// activate them.
SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
return 0;
}

NOTE: The comments as well as the code are pulled directly from the windows mobile win32 C++ template.


I did some digging and here is the actual code from TCPMP

static bool_t FindRunning(const tchar_t* CmdLine)
{
HWND Wnd;
tchar_t ClassName[32];
int n = tcslen(ProgramName);
tcscpy_s(ClassName,TSIZEOF(ClassName),ProgramName) ;
tcscpy_s(ClassName+n,TSIZEOF(ClassName)-n,T("_Win"));
Wnd = FindWindow(ClassName, NULL);
if (Wnd)
{
HWND WndMain = Wnd;

while (!IsWindowEnabled(Wnd))
{
HWND Last = Wnd;
EnumWindows(EnumWindowsProc,(LPARAM)&Wnd);
if (Wnd == Last)
break;
}

SetForegroundWindow(Wnd);

if (CmdLine && CmdLine[0])
{
COPYDATASTRUCT Data;
Data.dwData = 0;
Data.cbData = (tcslen(CmdLine)+1)*sizeof(tchar_t);
Data.lpData = (PVOID)CmdLine;
SendMessage(WndMain,WM_COPYDATA,(WPARAM)WndMain,(L PARAM)&Data);
}

return 1;
}
return 0;
}

volDeus 05-19-2009 12:31 AM

Re: Running two instances of a program at the same time?
 
Quote:

Originally Posted by theedon (Post 923039)
get yourself a copy of ms visual studio 2008. instantiate an unmanaged code project (thats win32 C++). now compile and run. thats it... the default template has the check pre coded for you. when im back at my computer i'll post the actual lines of code. it requires the coder to specifically change the behavior. the template also hard codes the window name and the window class. the reason it does this is so that it can do a search with those two inputs to determine if the program is running. that is why changing the program name doesnt always work. the coder has to tell the program to allo such behavior. but, the default template does not allow that.

now since tcpmp is written in unmanaged code and it behaves as i have described... need i say more?

You seem to know more about the specifics than I do ... But I have MSVC 2008 and at least one small app I coded myself works with the renaming method (and a few others that I didn't)...

The app is a simple carpenter's calculator with algebraic formula parsing and common construction formula templates ... Before I added support for multiple memory slots in the calculator I used to run multiple instances of the same process when I had two things at work to keep track of at the same time...

It is unmanaged code (C++ WIN32 API + WM5 SDK) and I never did anything to it to prevent the type of checking you are talking about (obviously, since I wasn't aware of the default behavior until you mentioned it) so ... While I acknowledge that you seem to know more about the specifics than I do ... Apparently there is an exception to the rule...

In any event, I would be curious about the lines of code you mentioned but I don't want to take any more attention from the OP's original question so I'll leave off here... You could PM them to me if you are bored sometime :)


All times are GMT -4. The time now is 12:04 PM.

Powered by vBulletin® ©2000 - 2024, Jelsoft Enterprises Ltd.
©2012 - PPCGeeks.com


Content Relevant URLs by vBSEO 3.6.0