|
As others have pointed out you should use Mutex to avoid the multiple instances.
Here is code snippet how it will look(not tested)
HANDLE hMutexOneInstance = CreateMutex(NULL, FALSE, _T("Global\\MutexToAvoidMultipleInstances"));
DWORD dLastErr = ::GetLastError();
if(dLastErr == ERROR_ALREADY_EXISTS)
{
CWnd * pPrevCWnd = PreviousInstance();
if(pPrevCWnd != NULL)
{
need to check more :)[/edit]
LaunchPrevInstance(pPrevCWnd);
}
else {
AfxMessageBox("Only one instance is allowed.");
}
return FALSE;
}
Regards,
Sandip.
modified on Tuesday, February 16, 2010 3:34 AM
|
|
|
|
|
Thanks for your valuable reply...
By the way, I got how to avoid multiple instances. But the problem is to restore the minimized or inactive window, which is already running.
The functions like ::BringWindowToTop(), :: SetForegroundWindow(), ::ShowWindow() needs HWND value as parameter. But the problem that i don't have any HWND value ,because we are not using any CFrameWnd derived class.
Could you please suggest me how to show my minimized or inactive application window.
Thanks in advance...
|
|
|
|
|
Hello Sirs
how to insert text into an avi file?
there's a filter that does this, aware motion ... something,
but i wanted to know how to do something like that,
any help would be very ... um, Confused ... helpfull
thanks Failure is Success If we learn from it!!
|
|
|
|
|
I'll assume you mean you want to do that programatically using (V)C++, otherwise you wouldn't be asking here. Imho take a look at writing directshow filters[^] for starters, i hope that will help. > The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
Thanks for your replay !
i need to split I frames and P-frames in avi file and how to insert text into avi file.So please help me .. Failure is Success If we learn from it!!
|
|
|
|
|
I don't know what I and P frames are, sorry, i'm not much into video editing in details. To insert text i would write my own filter which takes the incoming frame, writes its text on it and then passes it along the graph (so it would have 1 input pin for incoming video frames and 1 output pin which passes the frame along after writing text onto it), i think video frames are (usually) passed as DIBs (Device Independent Bitmaps), so you should be able to use GDI (or GDI+) functions to write text onto these before letting them continue their journey.
[edit] And of course, insert my filter into the filter graph by building the graph "manually". [/edit]> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
modified on Tuesday, February 16, 2010 6:15 AM
|
|
|
|
|
|
I don't know of any samples, but google is your friend... > The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
Thanks Failure is Success If we learn from it!!
|
|
|
|
|
I have an MFC application that allows display of different types of objects. It also allows conversion of these objects to other types. The application is an MDI app. I'd like to be able to script the application. If I pass no command line parameters then it runs as a GUI application. If I type command line arguments then I would like it to run as a console application where it performs some work without returning until its done(basically convert one object to another).
I tried putting code in the init_instance but the program returns to the command prompt immediately and the operation is done by a spawned process.
Basically I want my cake and eat it too. I want a console app if command line is present otherwise a GUI application.
I've tried looking for a number of hours a few different times but always fine people talking about command line parsing for an MFC GUI application.
Can someone help me get started, maybe a few pointers?
Thanks
|
|
|
|
|
I have tried that, and now I convinced myself it can't be done, at least if you refuse any flashing window while running in command mode. The reason why is burried deep in the EXE file format, which holds one bit flagging console apps. When the flag is set, your app will run inside an existing console window and perform I/O in there; or when run outside a DOS window, it will create a new console and use it. When a Windows app runs, it will not send its output to an existing console.
So either you set the bit and the app will create a console window, even when you want Forms; or you don't set the bit, and your app will never use the console that launched it.
The "solution" is to build basically the same code twice, and deliver two almost identical EXE files! Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
I believe you can use the AllocConsole[^] function to create and attach a console.
If there are no command line parameters, you can do DoModal and if there are command line parameters you could do an AllocConsole .
Here is an excerpt from the documentation -
This function is primarily used by graphical user interface (GUI) application to create a console window. GUI applications are initialized without a console.
|
|
|
|
|
Member 381289 wrote: I want a console app if command line is present otherwise a GUI application
It is not an MFC problem: a console APP and a GUI app are linked differently and have different entry point from the kernel, that provides them some stdin/stdout services or not.
You can have a console app that has a GUI (it has a main and then creates windows, but it will retain a console until it run - you can eventually hide it) or you can have a GUI app (it has a WinMain ) that has a console (see <<superman>> post down up here.
Note that in MFC GUI apps, WinMain is linked by the MFC library, but exist: it calls the application object methods.
In any case, if you have to be able to hold and redirect the stdin/stdout streams, you must have a console app.
What I typically do in this case, is to breack the application in thre modules:
- A DLL that describe the applicatiomn data and semantics and related "commands"
- An Exe that links the DLL, that provides all the GUI stuff, invoking the DLL "commands"
- An Exe that links the DLL, that provides all the command line parsing stuff, once again invoking thos DLL "commands".
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
Hello, I need my MFC DLL to know what it's current path is. Referencing __targv[0] doesn't help because it only gives me the full path to the exe that links to my DLL. Any suggestions?
|
|
|
|
|
HMODULE hmod = GetModuleHandle(TEXT("OLComDll.dll"));
TCHAR szPath[MAX_PATH + 1] = {0};
DWORD dwLen = GetModuleFileHName(hmod, szPath, MAX_PATH);
|
|
|
|
|
I have an existing C++ project, Visual studio 9, running on Windows 7.
I want to write a non-managed piece of code to open a database.
First time round the database won't exist, so I want an error so that I can then run some code to create it.
So far:
DAO doesn't work (it used to in another project)...
m_pDB = new CDaoDatabase(NULL);// use a temporary workspace
// try to open it, not exclusive, not read only the connect arguements left blank (default)
// failure throws an exception (not nice really - rather it returned a false
// fails if database doesn't exist so catch it and then try a create if the user required that.
try
{
opened = true; // assume success
m_pDB->Open(CString("EventsLog.mdb"), false, false);
}
catch(CDaoException* e)
{
opened = false; // wrong assumption, didn't open
e->Delete();
}
if ((!opened) && (createIfRequired))
{
try
{
opened = true; // assume success
m_pDB->Create(CString("EventsLog.mdb"));
CreateActivityRecordStructure();
CreateActivityRecord("0.1.2.3", "Test sensor 1", "Temp OK", 0);
}
catch(CDaoException* e)
{
opened = false; // wrong assumption, didn't open
LPTSTR errors = new TCHAR[100];
e->GetErrorMessage(errors,100,NULL);
// ALWAYS ENDS HERE COMPLAINING IT CAN'T START DAO
AfxMessageBox(errors);
e->Delete();
}
}
_ConnectionPtr pConnection;
hr = pConnection.CreateInstance(__uuidof(Connection));
if (FAILED(hr))
{
return false;
}
_RecordsetPtr recordset;
hr = recordset.CreateInstance(__uuidof(Recordset));
if (FAILED(hr))
{
return false;
}
hr = pConnection->Open(strConnectionString, "", "", adOpenUnspecified);
// this ALWAYS fails regardless of any connection string I have tried - and I've tried a few.
Anything thats to do with 'wrappers around managed classes' just reveals piles of shite about /clr and what it is incompatible with.
I can't find a piece of example code anywhere on the internet that will compile and work.
Surely it is trivial - after all, what I am trying to do (at this stage) is not really any harder than opening a file!
|
|
|
|
|
What is your question?
The code you posted compiles? Runs? Doesn't behave as expected?
Why don't you use ADO ?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
struct hostent *pHost;
int ip,i,j;
string str;
char ipc[6];
str="";
char ctrl[3] = {'\r','\n','\0'};
pHost = gethostbyname("google.com");
for( i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++ )
{
for(j=0; j<pHost->h_length; j++)
{
ip = pHost->h_addr_list[i][j];
str += itoa(ip,ipc,10);
str += ".";
}
str+=ctrl;
}
alert(str);
I get an alert with four addresses one after the other. i get negative values. for example
-47.85.-103.103
-47.85.-103.104
-47.85.-103.109
-47.85.-103.99
when i tried ip-adress.com i got 74.125.43.104 for google
mine is a shared hosting and the values are less than 128 and i get only one address entry.
i have other alternates to find ip adress of an host and i want to try this too...
is it ok to get negative values... i haven't seen that...Today's Beautiful Moments are
Tomorrow's Beautiful Memories
modified on Monday, February 15, 2010 3:34 PM
|
|
|
|
|
You're seeing negative values because the hostent structure stores the bytes as signed chars. Take a look at inet_ntoa[^] for one way to turn it into a recognisable address.
|
|
|
|
|
You cannot get the IP address of any host on the internet in this way. The gethostbyname() function only performs a lookup in the local hosts database. IP address resolution for non-local hosts is accomplished via DNS servers.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Richard MacCutchan wrote: You cannot get the IP address of any host on the internet in this way.
Sure you can. Try this:
struct hostent *host = gethostbyname("www.google.com");
struct in_addr *ptr = (struct in_addr *) host->h_addr_list[0];
int nOct1 = ptr->S_un.S_un_b.s_b1;
int nOct2 = ptr->S_un.S_un_b.s_b2;
int nOct3 = ptr->S_un.S_un_b.s_b3;
int nOct4 = ptr->S_un.S_un_b.s_b4;
...
char *pIPAddr = inet_ntoa(*ptr); "One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
<br />
hostent* localHost;<br />
char* localIP;<br />
localHost = gethostbyname("vikku.info");<br />
localIP = inet_ntoa (*(struct in_addr *)*localHost->h_addr_list);<br />
alert(localIP);<br />
The above code worked well.
I want to find my ip address so that i can make an HTTP request.
I have been doing this by frequently checking online. since my space is a shared hosting the servers ip changes sometimes. So i want to find the ip of my server to make it automatic.
or i think it is best to use getaddrinfo
anyway will the above code holds good? or my first post?
Thanks to the three of you for your replies.
I am experimenting all.Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
Jayapal Chandran wrote: I want to find my ip address...
Call gethostname() followed by gethostbyname() .
Jayapal Chandran wrote: since my space is a shared hosting the servers ip changes sometimes. So i want to find the ip of my server to make it automatic.
Isn't that the whole reason for using a host name rather than an IP address (to not be affected by IP changes)?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
For now this is all i need. May i know the other purposes?
But yet i want to see in practice the working of all these and the purposes behind.
I want to be aware of Networking from some base point. i have started from sockets... and i hope i have to branch more...Today's Beautiful Moments are
Tomorrow's Beautiful Memories
|
|
|
|
|
Jayapal Chandran wrote: May i know the other purposes?
The other purposes of what?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|