|
Hi Friends,
I need to invoke a .exe file and pass a message to that file.
Using CreateProcess,I invoked(called) the exe file, FindWindow API to
get the invoked exe and SendMessage to send the message.
The problem is, there is a time delay in CreateProcess that the
FindWindow API cannot find it,if WaitForSingleObject() function is not used.
<br />
CreateProcess("C:\\Bin\\wfp.exe",NULL,0,0,FALSE,CREATE_NEW_CONSOLE,0,0,&si,&pi);<br />
WaitForSingleObject(pi.hThread,500);
CloseHandle(pi.hProcess);<br />
<br />
hExeWnd=FindWindow(NULL,"WFP");<br />
if(hExeWnd)<br />
{<br />
::SendMessage(hExeWnd,WM_PLOTWAVE,0,0);<br />
ShowWindow(hExeWnd,SW_SHOW);<br />
}<br />
The delay time 500ms may vary from machine to machine in accordance with its
performance.If I give it as INFINITE,the program stops there UNTILL the wfp.exe window is CLOSED,which is unacceptable.
So how can I make the program to wait untill the CreateProcess() completes its
task in executing the exe.
NOTE:I tried using ShellExecute API,but there too Sleep() function is needed for the time delay.
|
|
|
|
|
Check out WaitForInputIdle()
|
|
|
|
|
Hey...
WaitForInputIdle() also works,if I specify the delay time as INFINITE.
Great!
Thanks a lot.
Thank you!
|
|
|
|
|
if both parent application and child is urs, u can implement another technique.
Create a named event in both application. The parent application, after calling the createprocess should wait for this event. The child process may set the event to signalled state after initialized.
nave
|
|
|
|
|
Thanks friends!
I cannot use WaitForInputIdle() since it also requires the time delay.
I tried using Naveen's idea of creating events.
It worked!
In the Parent application,I wrote as
<br />
HANDLE hEvent;<br />
hEvent=CreateEvent(NULL,FALSE,FALSE,"WFP_EVENT");
<br />
CreateProcess("C:\\Bin\\wfp.exe",NULL,0,0,FALSE,CREATE_NEW_CONSOLE,0,0,&si,&pi); <br />
<br />
WaitForSingleObject(hEvent,INFINITE); <br />
CloseHandle(pi.hProcess);<br />
CloseHandle(hEvent);<br />
In the child application(i.e the called Exe)
<br />
BOOL CWFPDlg::OnInitDialog()<br />
{<br />
...<br />
HANDLE hEvent;<br />
hEvent=CreateEvent(NULL,FALSE,FALSE,"WFP_EVENT"); <br />
if(GetLastError()==ERROR_ALREADY_EXISTS)<br />
{<br />
hEvent=OpenEvent(EVENT_MODIFY_STATE,FALSE,"WFP_EVENT");<br />
SetEvent(hEvent);
}<br />
...<br />
}<br />
|
|
|
|
|
poda123 wrote: if(GetLastError()==ERROR_ALREADY_EXISTS)
{
hEvent=OpenEvent(EVENT_MODIFY_STATE,FALSE,"WFP_EVENT");
why r u openeing the event again. u already have the handle of the event?I think u can skip that line..
nave
|
|
|
|
|
|
Hi All,
I'm having trouble finding defines for Clipboard Formats. The unknowns appear after Microsoft Word places a gif on the Clipboard. Has anyone been able come across the meaining of:
49251
49298
46289
49158
49159
Jeff
#include <windows.h>
int main(int argc, char* argv[])
{
int count = CountClipboardFormats();
cout << count << _T(" formats available on the clipboard:") << endl << endl;
if( TRUE == OpenClipboard( NULL ) )
{
UINT format = 0;
while( 0 != (format = EnumClipboardFormats( format ) ) )
{
switch( format )
{
case CF_BITMAP:
cout << _T(" CF_BITMAP") << endl;
break;
case CF_DIB:
cout << _T(" CF_DIB") << endl;
break;
case CF_DIBV5:
cout << _T(" CF_DIBV5") << endl;
break;
case CF_DIF:
cout << _T(" CF_DIF") << endl;
break;
case CF_DSPBITMAP:
cout << _T(" CF_DSPBITMAP") << endl;
break;
case CF_DSPENHMETAFILE:
cout << _T(" CF_DIB") << endl;
break;
case CF_DSPMETAFILEPICT:
cout << _T(" CF_DSPMETAFILEPICT") << endl;
break;
case CF_DSPTEXT:
cout << _T(" CF_DSPTEXT") << endl;
break;
case CF_ENHMETAFILE:
cout << _T(" CF_ENHMETAFILE") << endl;
break;
case CF_HDROP:
cout << _T(" CF_HDROP") << endl;
break;
case CF_LOCALE:
cout << _T(" CF_LOCALE") << endl;
break;
case CF_METAFILEPICT:
cout << _T(" CF_METAFILEPICT") << endl;
break;
case CF_OEMTEXT:
cout << _T(" CF_OEMTEXT") << endl;
break;
case CF_PALETTE:
cout << _T(" CF_PALETTE") << endl;
break;
case CF_PENDATA:
cout << _T(" CF_PENDATA") << endl;
break;
case CF_RIFF:
cout << _T(" CF_RIFF") << endl;
break;
case CF_SYLK:
cout << _T(" CF_SYLK") << endl;
break;
case CF_TEXT:
cout << _T(" CF_TEXT") << endl;
break;
case CF_WAVE:
cout << _T(" CF_OWNERDISPLAY") << endl;
break;
case CF_TIFF:
cout << _T(" CF_TIFF") << endl;
break;
case CF_UNICODETEXT:
cout << _T(" CF_UNICODETEXT") << endl;
break;
case 49161:
cout << _T(" Data Object") << endl;
break;
case 49166:
cout << _T(" Object Descriptor") << endl;
break;
case 49272:
cout << _T(" Rich Text Format") << endl;
break;
case 49457:
cout << _T(" HTML Format") << endl;
break;
case 49163:
cout << _T(" Embed Source") << endl;
break;
case 49156:
cout << _T(" Native") << endl;
break;
case 49155:
cout << _T(" OwnerLink") << endl;
break;
case 49167:
cout << _T(" Link Source Descriptor") << endl;
break;
case 49154:
cout << _T(" ObjectLink") << endl;
break;
case 49545:
cout << _T(" Hyperlink") << endl;
break;
case 49171:
cout << _T(" Ole Private Data") << endl;
break;
default:
if( format >= CF_GDIOBJFIRST && format <= CF_GDIOBJLAST )
{
cout << _T(" CF_GDIOBJFIRST + ") << format - CF_GDIOBJFIRST << endl;
} else
if( format >= CF_PRIVATEFIRST && format <= CF_PRIVATELAST )
{
cout << _T(" CF_PRIVATEFIRST + ") << format - CF_PRIVATEFIRST << endl;
} else
{
cout << _T(" Format: ") << format << endl;
}
break;
}
}
CloseClipboard( );
}
return 0;
}
|
|
|
|
|
An app can put pretty much any data it wants to on the clipboard, the numbers won't always be the same from one session to the next. You can call GetClipboardFormatName() to get the string that was originally passed to RegisterClipboardFormat() .
|
|
|
|
|
Hi Mike,
Thanks. That was it.
Jeff
Format: 49161 (DataObject)
Format: 49166 (Object Descriptor)
Format: 49239 (Rich Text Format)
Format: 49297 (HTML Format)
CF_ENHMETAFILE
CF_METAFILEPICT
Format: 49345 (PNG)
Format: 49589 (GIF)
Format: 49346 (JFIF)
Format: 49592 (PNG+Office Art)
Format: 49590 (GIF+Office Art)
Format: 49591 (JFIF+Office Art)
Format: 49586 (Office Drawing Shape Format)
Format: 49594 (ActiveClipboard)
CF_DIB
CF_BITMAP
Format: 49163 (Embed Source)
Format: 49156 (Native)
Format: 49155 (OwnerLink)
Format: 49165 (Link Source)
Format: 49167 (Link Source Descriptor)
Format: 49154 (ObjectLink)
Format: 49171 (Ole Private Data)
CF_DIBV5
|
|
|
|
|
In case anyone is interested in the code...
#include <windows.h>
int main(int argc, char* argv[])
{
int count = CountClipboardFormats();
cout << count << _T(" formats available on the clipboard:") << endl << endl;
if( TRUE == OpenClipboard( NULL ) )
{
UINT format = 0;
while( 0 != (format = EnumClipboardFormats( format ) ) )
{
switch( format )
{
case CF_BITMAP:
cout << _T(" CF_BITMAP") << endl;
break;
case CF_DIB:
cout << _T(" CF_DIB") << endl;
break;
case CF_DIBV5:
cout << _T(" CF_DIBV5") << endl;
break;
case CF_DIF:
cout << _T(" CF_DIF") << endl;
break;
case CF_DSPBITMAP:
cout << _T(" CF_DSPBITMAP") << endl;
break;
case CF_DSPENHMETAFILE:
cout << _T(" CF_DIB") << endl;
break;
case CF_DSPMETAFILEPICT:
cout << _T(" CF_DSPMETAFILEPICT") << endl;
break;
case CF_DSPTEXT:
cout << _T(" CF_DSPTEXT") << endl;
break;
case CF_ENHMETAFILE:
cout << _T(" CF_ENHMETAFILE") << endl;
break;
case CF_HDROP:
cout << _T(" CF_HDROP") << endl;
break;
case CF_LOCALE:
cout << _T(" CF_LOCALE") << endl;
break;
case CF_METAFILEPICT:
cout << _T(" CF_METAFILEPICT") << endl;
break;
case CF_OEMTEXT:
cout << _T(" CF_OEMTEXT") << endl;
break;
case CF_PALETTE:
cout << _T(" CF_PALETTE") << endl;
break;
case CF_PENDATA:
cout << _T(" CF_PENDATA") << endl;
break;
case CF_RIFF:
cout << _T(" CF_RIFF") << endl;
break;
case CF_SYLK:
cout << _T(" CF_SYLK") << endl;
break;
case CF_TEXT:
cout << _T(" CF_TEXT") << endl;
break;
case CF_WAVE:
cout << _T(" CF_OWNERDISPLAY") << endl;
break;
case CF_TIFF:
cout << _T(" CF_TIFF") << endl;
break;
case CF_UNICODETEXT:
cout << _T(" CF_UNICODETEXT") << endl;
break;
default:
if( format >= CF_GDIOBJFIRST && format <= CF_GDIOBJLAST )
{
cout << _T(" CF_GDIOBJFIRST + ") << format - CF_GDIOBJFIRST << endl;
}
else
if( format >= CF_PRIVATEFIRST && format <= CF_PRIVATELAST )
{
cout << _T(" CF_PRIVATEFIRST + ") << format - CF_PRIVATEFIRST << endl;
}
else
{
cout << _T(" Format: ") << format;
TCHAR FormatName[ MAX_PATH + 1 ];
if( 0 != GetClipboardFormatName( format, FormatName, MAX_PATH ) )
{
cout << _T(" (") << FormatName << _T(")");
}
cout << endl;
}
break;
}
}
CloseClipboard( );
}
return 0;
}
|
|
|
|
|
|
I would like to know which function will be called when drop the document file created in multiple document application on exe file icon.
Thanks & Regards,
Suman
|
|
|
|
|
No single function is called. The OS runs the EXE and passes full path to the file on the command line.
|
|
|
|
|
Is it possible to get the command line path? Because, I want to initialize some variables.
Thanks & Regards,
Suman
|
|
|
|
|
It's a parameter to WinMain(), or you can call GetCommandLine()
|
|
|
|
|
Thank you very much for great help!
Thanks & Regards,
Suman
|
|
|
|
|
Hi~!!
I'am Korean. Not Use English. So I can't English well.
I have problem. like subject.
i need to setting Mixer.(MFC Programing)
but i don't know how setting Front Mic in coding.
each computer are different. one thing in inline-list, otherwise anoter in mic-volume.
so it is hard to solve. my word is diffent to setting Front-Mic.
Help me. please.
d
|
|
|
|
|
My program generates the message
"Windows has triggered a breakpoint in your application. This may be due to corruption of the heap, and indicates a bug in the application or any of the dll's it has loaded...."
The question is, there are no memory leaks, so what kinds of misbehavior cause this?
--------------------------------
"All that is necessary for the forces of evil to win in the world is for enough good men to do nothing" -- Edmund Burke
|
|
|
|
|
Stuff like this:
int *pInt = new int;
memset(pInt, 0, sizeof(6*sizeof(int)));
Here I only allocate enough space for one integer but write past the end of the memory I allocated.
My advice is to download WinDBG[^] and turn on the page heap for your application. Follow these steps to do so (after installing WinDBG).
1. In the start menu find "Debugging Tools for Windows" and run the "Global Flags" application that's within it.
2. Select the "Image File" tab.
3. In the "Image: (TAB to refresh)" edit control enter the name (not the full path) of your application including the file extension.
4. Press TAB.
5. Tick the following: "Enable heap tail checking", the "Enable heap free checking", "Enable heap parameter checking", ""Enable heap validation on call", "Disable heap coalesce on free" and "Enable page heap".
6. Click "Apply".
7. Debug the application and reproduce the fault. If all goes well a beakpoint will be generated near the code that actually caused the problem.
When done untick all the options and click "Apply". Another option (which I prefer) is to find the registry key "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options" and delete the key named after your application.
Be aware that turning on these options on will make you application run very slowly and consume heaps of memory. It's normally good to have a machine loaded up with RAM.
Steve
|
|
|
|
|
Thank you very much Steve, for all that information! It is much appreciated. I will try that right away.
--------------------------------
"All that is necessary for the forces of evil to win in the world is for enough good men to do nothing" -- Edmund Burke
|
|
|
|
|
I'm getting a debug assertation error on my MFC program. It compiles fine with no warnings or anything, but I'm still getting the error. When I hit "retry" it points to this line:
Background_dcPtr->DrawText("It Works!", ItWorksDimensions, DT_CENTER);
The rest of the code is here:
#include "game_interface.h"
#include <afxwin.h>
#include "game_ids.h"
using namespace std;
CGameWin::CGameWin() : CGameKeyBindingDialog("CKeyboardDialog")
{
Create(NULL, "Ard-Ri", WS_OVERLAPPEDWINDOW,
rectDefault, NULL, "Game");
CGameKeyBindingDialog.setMainWnd(this);
OffSetX, OffSetY = 0;
}
CDC* CGameWin::DrawBackground()
{
CDC* Background_dcPtr = new CDC;
CRect ItWorksDimensions;
ItWorksDimensions.left = 0;
ItWorksDimensions.top = 0;
ItWorksDimensions.right = 50;
ItWorksDimensions.bottom = 20;
Background_dcPtr->DrawText("It Works!", ItWorksDimensions, DT_CENTER);
return Background_dcPtr;
}
afx_msg void CGameWin::OnPaint()
{
CPaintDC Screen(this);
CRect WindowArea;
CDC* Background = NULL;
GetClientRect(&WindowArea);
OffSetX = WindowArea.right / 4;
OffSetY = WindowArea.bottom / 4;
Background = DrawBackground();
Screen.CreateCompatibleDC(Background);
Screen.BitBlt(OffSetX, OffSetY, OffSetX + 50, OffSetY + 20, Background, 0, 0, SRCCOPY);
delete Background;
}
afx_msg void CGameWin::OnExit()
{
SendMessage(WM_CLOSE);
}
BEGIN_MESSAGE_MAP(CGameWin, CFrameWnd)
ON_WM_PAINT()
ON_COMMAND(IDM_EXIT, OnExit)
END_MESSAGE_MAP()
CGameKeyBindingDialog::CGameKeyBindingDialog(char* lpszName) : CDialog(lpszName)
{
}
BOOL CGameKeyBindingDialog::OnInitDialog()
{
CDialog::OnInitDialog();
return TRUE;
}
CGameWin* CGameKeyBindingDialog::getMainWnd()
{
return m_pMainWnd;
}
void CGameKeyBindingDialog::setMainWnd(CGameWin* mp)
{
m_pMainWnd = mp;
}
afx_msg void CGameKeyBindingDialog::OnExitDialog()
{
EndDialog(IDM_EXIT);
}
BEGIN_MESSAGE_MAP(CGameKeyBindingDialog, CDialog)
ON_COMMAND(IDM_EXIT, OnExitDialog)
END_MESSAGE_MAP()
The header file:
#ifndef GAME_INTERFACE_H
#define GAME_INTEFRACE_H
#include <afxwin.h>
using namespace std;
class CGameWin;
class CGameKeyBindingDialog : public CDialog
{
public:
CGameKeyBindingDialog(char* lpszName);
BOOL OnInitDialog();
CGameWin* getMainWnd();
void setMainWnd(CGameWin* mp);
void InitAll();
afx_msg void OnExitDialog();
private:
CGameWin* m_pMainWnd; //pointer to main window
DECLARE_MESSAGE_MAP()
};
class CGameWin : public CFrameWnd
{
public:
CGameWin();
afx_msg void OnPaint();
//file menu "File"
afx_msg void OnExit();
private:
CDC* DrawBackground();
CGameKeyBindingDialog CGameKeyBindingDialog;
int OffSetX;
int OffSetY;
DECLARE_MESSAGE_MAP()
};
#endif
I'd appreciate any help.
|
|
|
|
|
|
The DC you are drawing text on isn't created. You have a CDC object but no HDC windows object.
You could pass the paint DC to DrawBackground() or in the function get a DC for the window:
CWindowDC* Background_dcPtr = new CWindowDC(this);
...
|
|
|
|
|
Thanks.
|
|
|
|
|