|
Hi,
I am doing a project in vc++ win32. I want to run only one instance of exe at a time.If the user try to execute the exe when one is already running, I want to bring the one that is already running, to the top.
I am creating a mutex to check whether an instance of the app is already running thus preventing any further instance to run. But I want to know how to bring the one that is already running to the front. How do I get the handle of the window that is already running..pls help..
thanks a lot..
|
|
|
|
|
|
You could put some information that you wanted any subsequent instances of a program to read into a memory mapped file. The first instance to run writes the data, like a window handle, and the others can read it when they figure out they are not the first instance, and they can use that data for whatever purposes, such as activating the existing window.
When my first instance runs, I write the window handle the process ID and the primary thread ID to the memory mapped file.
I also left room to store a file path, in case the second instance was activated with a file path on the command line, I can store the file path in the memory mamped file and then activate the first instance by posting its main window a special message. the first instance can attempt to load the file specified by the 'new' instance, since sometimes this happens when user is clicking files in Explorer and your program is already running.
|
|
|
|
|
Hi,
I was wondering if there are any message map entries for right clicking on an entry in a drop down CComboBox control? I'd like to take an action if a user right clicks on an entry. Thank you very much =)
Jay
jaycush@bellsouth.net
|
|
|
|
|
Hi, wrote a dll( MFC dll static lib ): Mydll project:
in the Mydll.cpp: I add a entry function: Fun1(), But
when use rundll32 Mydll Fun1 Command I got error message
" Error in Mydll Missing Entry:Fun1". What is the reason???!!!
BEGIN_MESSAGE_MAP(CMydllApp, CWinApp)
//{{AFX_MSG_MAP(CMydllApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMydllApp construction
CMydllApp::CMydllApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
CMydllApp theApp;
extern "C" BOOL PASCAL EXPORT Fun1()
{
.....
return 1;
}
|
|
|
|
|
From a command line, verify the function really got exported with the name you are expecting by using this:
DumpBin /Exports MyDll.Dll
You should see the Fun1 in the list. If not, the function never 'escaped' from your DLL.
|
|
|
|
|
Dump of file MyDll.dll
File Type: DLL
Section contains the following exports for MyDll.dll
0 characteristics
42B9E5A6 time date stamp Wed Jun 22 18:26:46 2005
0.00 version
1 ordinal base
1 number of functions
1 number of names
ordinal hint RVA name
1 0 0000100A _Fun1@16
Summary
7000 .data
1000 .idata
3000 .rdata
2000 .reloc
2A000 .text
|
|
|
|
|
It is almost like your DLL does not have the DllMain 'entry point' that windows needs to call to load it.
Did you start with a generic DLL or a generic MFC DLL project? If so, that is strange, if not, then you need to add a DllMain to your DLL project.
|
|
|
|
|
I cretae the project by Visuasal Stadio Vizard.
New=>MFC DLL=>... See the file
// MyDll.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include "MyDll.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
/////////////////////////////////////////////////////////////////////////////
// CMyDllApp
BEGIN_MESSAGE_MAP(CMyDllApp, CWinApp)
//{{AFX_MSG_MAP(CMyDllApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDllApp construction
CMyDllApp::CMyDllApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CMyDllApp object
CMyDllApp theApp;
extern "C" __declspec(dllexport) void CALLBACK Fun1(HWND,
HINSTANCE,
LPTSTR lpCmdLine,
int)
{
int i;
i = 1;
}
|
|
|
|
|
When I look at similar entries in the registry, I notice ALL the ones I saw have a comma in between the name of the DLL and the function name.
Instead of
rundll32 Mydll Fun1
why don't you try
rundll32 Mydll.dll,Fun1
|
|
|
|
|
Are you needing the temporary file simply so that the two applications can communicate?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
|
Hi all,
This may be an anal question, but...
I've inherited some code where the original programmer would go through the hassle, for example, of doing an OS check before opening every single registry key the program looks at, eg, if it's VER_PLATFORM_WIN32_NT, then a "SOFTWARE\[whatever]" string is built, and if it's running on Win9x, then the string is "software\[whatever]".
My own tests and experience tell me that opening any key for reading should NOT be case-sensitive. I'm tempted to modify the code and hardwire "SOFTWARE" everywhere, to save the overhead in (a) calling the function and (b) building different strings.
My question...is anyone aware of any circumstances where my change would actually cause failures?
Note that I do understand the difference between creating a new key in lowercase vs uppercase...but I'm talking here strictly about opening existing keys for reading only...
|
|
|
|
|
Daniel Desormeaux wrote:
My question...is anyone aware of any circumstances where my change would actually cause failures...but I'm talking here strictly about opening existing keys for reading only.
I've used mixed-case successfully.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Daniel Desormeaux wrote:
My question...is anyone aware of any circumstances where my change would actually cause failures?
For Last 1 yr, I have used registy in almost each of my project and almost each of Window Platform ranging from 95 to XP, I believe, I never face problem with case sensitivity
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
In .Net, you can retrieve the code page for a given character encoding as follows:
<br />
Encoding blah = Encoding.GetEncoding("utf-7");<br />
<br />
Is there a similar function in Win32 or MFC?
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|
Jack Squirrel wrote:
Is there a similar function in Win32 or MFC?
How about GetCPInfo() ?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Doesn't work.
I'm extracting the encoding attribute from an XML file, afterwhich I need to figure out which Windows code page is needed to convert the text to Unicode.
In theory:
<br />
UINT AfxCharacterEncodingToCodePage(LPCTSTR lpszCharacterEncoding)<br />
{<br />
if (_tscicmp(lpszCharacterEncoding, _T("utf-7") == 0)<br />
return (65000);<br />
...<br />
<br />
}<br />
<br />
...<br />
<br />
CString strExtractedCharacterEncoding = _T("utf-7");<br />
<br />
UINT nCodePage = AfxCharacterEncodingToCodePage(strEncoding);<br />
MultiByteToWideChar(nCodePage, blah...);<br />
<br />
I found this list of encodings and their associated code pages, I just don't want to write a function for this if it already exists.
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|
The IMultiLanguage2 Interface might be of help.
Interface Information
Stock Implementation: mlang.dll
Custom Implementation: No
Inherits from: IUnknown
Header and IDL files: mlang.h, mlang.idl
Minimum availability: Internet Explorer 5
Minimum operating systems: Windows 95, Windows NT 4.0, Windows CE 4.0
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
I'm writing a small VC++ program that works with a single dialog, and I wanted the buttons inside the window to move position, when the user resizes the window, but I don't know how to do that. I know that I must use the Resize message of the window, and then move the buttons to the right position , using some arithmetics, but I don't know how to move buttons from place at runtime. Could you help me?
|
|
|
|
|
Check this [^]article and see if that helps you.
Artificial intelligence is no match for natural
stupidity.
Never argue with an idiot. They will drag you down to their level where they are an expert.
|
|
|
|
|
Thanks, I didn't know I could find supperior inteligence here. I thought I could only find it in some mudhole in Mars.
|
|
|
|
|
I am working with a tree control on a dialog i created. The following code is how i set up the tree in the OnInitDialog() (m_SectionTree is the name of my control):
TVINSERTSTRUCT tvInsert;
tvInsert.hParent = NULL;
tvInsert.hInsertAfter = NULL;
tvInsert.item.mask = TVIF_TEXT;
tvInsert.item.pszText = _T("Circular");
HTREEITEM hCircular = m_SectionTree.InsertItem(&tvInsert);
m_SectionTree.InsertItem(_T("Circular 1"), hCircular, TVI_SORT);
m_SectionTree.InsertItem(_T("Circular 2"), hCircular, TVI_SORT);
etc....
But when i use the program and colapse part of the tree and then try to redraw it again it doesnt redraw correct. It just freezes and redraws the control in a completely random way.
How do i fix this?
thank you
|
|
|
|
|
I am creating a little setup console application in C++. The application is called from autorun on a cd-rom. Once called, the application opens an html page and wait for the html page to be closed and start another setup program. The problem I have is that when someone accidentally eject the CD and reinsert it, the same html page is launch again. Is there a function that I can call to see if the html file is already opened and not open another html file if the first one is still open? I open the html page using ShellExecuteEx(), wait for the page to be closed using WaitForSingleObject(), and launch the second setup program using CreateProcess(). Any help would be appreciated, thanks.
|
|
|
|
|
What happens if you try and open the .html file using OpenFile(..., OF_SHARE_EXCLUSIVE) ? If that fails then you know the file is already open.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|