|
Steve,
Have you been able to find any examples (that the lawyers won't complain about) that I can look at?
Larry J. Siddens
Cornerstone Communications
TAME THE DOCUMENT MONSTER
www.unifier.biz
|
|
|
|
|
As part of my techno project I need to be able to emulate my DSP processor in C++. How would I go about outputing a sinewave to the soundcard. I have basic C++ training and can learn fast. Any Help would be appreciated.
Corey
|
|
|
|
|
I want to finish a program that terminates proccesses that are selected in a big list. And my program must run always @ startup. How to terminate proccesses correctly selected in list?
My eyes - fountains of blood
|
|
|
|
|
See if TerminateProcess() helps you.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
I know that, ok, my code that doesn't work:
PROCESSENTRY32* info;<br />
HANDLE proc2;<br />
<br />
Process32First(proc2,info);<br />
for(int i=0;i<35;i++){<br />
Process32Next(proc2,info);<br />
MessageBox(info->szExeFile,"OK");<br />
if(strstr("NOTEPAD",info->szExeFile)){MessageBox("MATCH","OK");break;}<br />
}<br />
proc2=OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE,TRUE,1241980);<br />
<br />
m_name.Format("%d",info->th32ProcessID);<br />
SetDlgItemText(IDC_NAME,m_name.GetBuffer(0));<br />
<br />
<br />
if(WaitForSingleObject(proc2,5000)!=WAIT_OBJECT_0){<br />
result=TerminateProcess(proc2,0);<br />
MessageBox("Terminated","OK");<br />
}else{<br />
result=TRUE;<br />
cw=FindWindow(info->szExeFile,NULL);<br />
cw->PostMessage(WM_CLOSE);<br />
MessageBox("TRUE","VIGA");<br />
}<br />
<br />
CloseHandle(proc2);
Well, it's only for testing... Such a mess for testing
|
|
|
|
|
I'm really sorry about the mess above cause i got something...
|
|
|
|
|
PROCESSENTRY32 ProcessEntry;
ProcessEntry.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hSnapshot, &ProcessEntry) == TRUE)
{
do
{
MessageBox(info->szExeFile, "OK");
if (strstr("NOTEPAD", info->szExeFile)
{
MessageBox("MATCH, "OK");
break;
}
} while (Process32Next(hSnapshot, &ProcessEntry) == TRUE);
}
HANDLE hProcess = OpenProcess(/*PROCESS_ALL_ACCESS*/SYNCHRONIZE|PROCESS_TERMINATE, TRUE, ProcessEntry.th32ProcessID);
if (NULL != hProcess)
{
...
}
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
HANDLE proc;<br />
PROCESSENTRY32* info;<br />
POSITION p;<br />
int sel=0;<br />
BOOL result;<br />
char *name2;<br />
int length=0;<br />
proc=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);<br />
<br />
info=new PROCESSENTRY32;<br />
info->dwSize=sizeof(PROCESSENTRY32);<br />
int id=0;<br />
<br />
Process32First(proc,info);<br />
<br />
p=m_list1.GetFirstSelectedItemPosition();<br />
sel=m_list1.GetNextSelectedItem(p);<br />
<br />
do{<br />
Process32Next(proc,info);<br />
}while(!strstr(info->szExeFile,"NOTEPAD"));<br />
<br />
<br />
proc=OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE,TRUE,info->th32ProcessID);<br />
<br />
m_name.Format("%s",info->szExeFile);<br />
SetDlgItemText(IDC_NAME,m_name.GetBuffer(0));<br />
<br />
<br />
if(WaitForSingleObject(proc,5000)!=WAIT_OBJECT_0){<br />
result=TerminateProcess(proc,0);<br />
MessageBox("Terminated","OK");<br />
}else{<br />
result=TRUE;<br />
cw=FindWindow(info->szExeFile,NULL);<br />
cw->PostMessage(WM_CLOSE);<br />
MessageBox("TRUE","VIGA");<br />
}<br />
<br />
CloseHandle(proc);<br />
delete info;
Well, this should work, but how to use m_mylist.GetItemText(int nItem,intnSubItem,LPTSTR lpszText,innLen) with my code?
|
|
|
|
|
IndrekSnt wrote:
}while(!strstr(info->szExeFile,"NOTEPAD"));
This will loop forever if Notepad is not running!
IndrekSnt wrote:
...how to use m_mylist.GetItemText(int nItem,intnSubItem,LPTSTR lpszText,innLen)...
In order to use CListCtrl::GetItemText() , you must first have added items to the list control. I do not see any calls to CListCtrl::InsertItem() in your code.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
I'm not copying all my code but the InsertItem() functions are here:
proc=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);<br />
<br />
info=new PROCESSENTRY32;<br />
info->dwSize=sizeof(PROCESSENTRY32);<br />
int id=0;<br />
<br />
Process32First(proc,info);<br />
m_list1.InsertItem(0,(LPCTSTR)info->szExeFile);<br />
<br />
while(Process32Next(proc,info)!=FALSE){<br />
id++;<br />
m_list1.InsertItem(id,(LPCTSTR)info->szExeFile);<br />
}<br />
<br />
CloseHandle(proc);
This here was too only a segment of the code...
|
|
|
|
|
Assuming your list control had another column:
int x = m_list1.InsertItem(0,(LPCTSTR)info->szExeFile);
sprintf(szProcId, "%lu", info->th32ProcessID);
m_list1.SetItemText(x, 1, szProcId);
Otherwise, you'll need to use:
int x = m_list1.InsertItem(0,(LPCTSTR)info->szExeFile);
LPDWORD lpProcId = new DWORD;
*lpProcId = info->th32ProcessID;
m_list1.SetItemData(x, lpProcId);
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Thanks, it really helped me out, now i'm executing MSPAINT and NOTEPAD to terminate them...
|
|
|
|
|
How to restore minimized window?
I did so:
and it was not succeded -Why?
<br />
pDlg->ShowWindow(SW_SHOW);<br />
pDlg->SetFocus();<br />
<br />
WINDOWPLACEMENT wndpl;<br />
pDlg->GetWindowPlacement(&wndpl);<br />
<br />
wndpl.length = sizeof(wndpl);<br />
wndpl.flags = WPF_SETMINPOSITION ;<br />
wndpl.showCmd= SW_SHOWMAXIMIZED | SW_SHOW;<br />
<br />
pDlg->SetWindowPlacement(&wndpl);<br />
<br />
<br />
pDlg->UpdateWindow();<br />
thanks.
|
|
|
|
|
vgrigor wrote:
How to restore minimized window?
ShowWindow(SW_RESTORE);
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
|
Hello,
I am having some difficulty using the CArchive socket class in a storing (output) situation. My problem is with the m_pArOut pointer in the following code. It seems that for some unknown reason I am unable to write using the CArchive. Here is a code snippet:
----------------------------------------------------------------
<>
sockClient.Create();<br />
sockClient.Connect("192.168.1.112",3030);<br />
<br />
file = new CSocketFile(&sockClient);<br />
<br />
m_pArIn = new CArchive(file,CArchive::load);<br />
m_pArOut = new CArchive(file,CArchive::store);<br />
<br />
*m_pArOut<<"This is a test";
----------------------------------------------------------------
<>
CSocket sockClient;<br />
CSocketFile* file;<br />
<br />
CArchive* m_pArOut;<br />
CArchive* m_pArIn;
----------------------------------------------------------------
When this code is executed I do not receive the message “This is a test” on my server. However, if I change the code to use a local version of the CArchive object like the following it works:
----------------------------------------------------------------
CArchive arOut(file,CArchive::store);<br />
m_pArOut = &arOut;
----------------------------------------------------------------
The user of the pointer m_pArIn works in every case. I don’t understand why it would work when locally instantiated. I also don’t understand why the same problem doesn’t exist for the input archive.
Thank you for your help
Brian
|
|
|
|
|
I'm a bit of a beginner, but if I were you, I'd try flushing the output after you send "This is a test";
m_pArOut->Flush();
Hope this works for you!
Douglas A. Wright
dawrigh3@kent.edu
|
|
|
|
|
Thanks for the reply Doug. I too am new to VC++. I usually program in straight C in UNIX or VxWorks OS.
I tried flushing before, but no dice. It is the strangest thing, since it works if the object is instantiated locally.
Thanks again
Brian
|
|
|
|
|
hi,
up to now spy++ worked great, but from one moment to the other it won't display dispatched messages... and that happens with every program i want to spy!
Can somebody imagine what's wrong ?
Thanks in advance!
|
|
|
|
|
I'm still new to c++ so please bare with me.
I'm using the ShellExecuteEx in MFC to open a Acrobat .pdf document.
When Acrobat is closed after the document has opened or the process is closed I want to remove the file from the Directory.
my code looks like this.
<br />
char pathBuffer[MAX_PATH];<br />
char szCurrDir[MAX_PATH];<br />
<br />
GetCurrentDirectory(MAX_PATH,szCurrDir);<br />
GetTempFileName (szCurrDir, "", 0, pathBuffer);<br />
CString stmpfile = pathBuffer;<br />
<br />
SHELLEXECUTEINFO si;<br />
memset(&si, 0, sizeof(si));<br />
si.cbSize = sizeof(si);<br />
si.hwnd = this->m_hWnd;<br />
si.lpVerb = "open";<br />
si.lpFile = pathBuffer;<br />
si.nShow = SW_NORMAL;<br />
si.hInstApp = NULL; <br />
si.fMask = SEE_MASK_NOCLOSEPROCESS;<br />
int res = ShellExecuteEx(&si);<br />
if (res==1)<br />
WaitForSingleObject(si.hProcess,INFINITE);<br />
<br />
<br />
CloseHandle(si.hProcess);<br />
<br />
<br />
remove(stmpfile);<br />
When there is no instance of Acrobat running it works fine. But as soon as Acrobat is already running or an instance of the Acrobat exe still in the process tray it doesn’t seem to open the .pdf document.
I cannot use the ShellExecute structure for the simple reason that I need to know when Acrobat is closed so that I can remove that file from the directory.
The ShellExecute will open the Acrobat document regardless of whether there an instance is of Acrobat running.
//ShellExecute(this->m_hWnd,"open",pathBuffer, NULL, NULL, SW_SHOWNORMAL);
Any help would really be appreciated.
|
|
|
|
|
See if this helps:
WaitForSingleObject(si.hProcess, INFINITE);<br />
CloseHandle(si.hProcess);<br />
remove(stmpfile);
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
The WaitForSingleObject function halts program execution temporarily. This function allows a program to wait until something else has happened before execution continues.
The CloseHandle(si.hProcess); will thus in this case only execute after Acrobat is closed.
|
|
|
|
|
My biggest problem is why does the file not open with the ShellExecuteEx()structure when there is already an instance of Acrobat running, where as the ShellExecute() opens the document when there is already an instance of acrobat running.
Could it be due to the handle or process that has beed created to Acrobat using the ShellExecuteEx() structure? Where as ShellExecute() does not.
|
|
|
|
|
I'm aware of this, but you are still responsible for closing the process handle when using the SEE_MASK_NOCLOSEPROCESS flag. See the documentation!
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Hi,
I got the folowing error while running a VC++ program. This program was complied on Debug mode.
====================
Error:-
Debug Assertion Failure.
Program: C:\Saurabh_Server.exe
File: dumpout.cpp
Line: 52
====================
This might be because of some memory leaks. Bcoz if these errors were due to Assertion failures in my code files, then error msg would have displayed my file name and line no itself.
But the file specified here does not belong to me.
I complied this program under "Release" version and it runs absolutely fine. Now my question is:
1. If I continue working on this code and at the end compile it to Release version, will it be Ok. Will it cause any error in future if user works on the Release version generated .EXE? Or this needs to be fixed immediately.
2. How it is to be fixed. Can anybody suggest the approach for it. (also for resolving the memory leaks).
Thanx and Regards,
Saurabh
|
|
|
|