Visual C++ :: How To Check Thread With MFC

Feb 12, 2013

I use MFC Find console window and send key to console like this.

Code:
HWND w;
w = FindWindow(NULL, L"c:userspkrudocumentsvisual studio 2010ProjectsCleanVirusDebugCleanVirus.exe");

[Code]....

After program process success in console it not close console windows but it show like this in Output

The thread 'Win32 Thread' (0x1300) has exited with code 0 (0x0).

I think if I can check when VC will show this line, then I can use FreeConsole(); for close console windows.

View 3 Replies


ADVERTISEMENT

C# :: One Thread Trying To Pass Data To Another Thread Using Serial Port

Jul 30, 2014

I have a class which I wrote and one of its object is "SerialPort" .NET class. In my MainWindow I created instance of my class called "SerialPortComm", then I send through some functions of mine, commands to the Serial Port, and I receive answers through "DataReceived" event.

But when I trying to use Dispatcher.BeginInvoke to write my data I have received (successfully), nothing shows on the RichTextBox which I'm trying to write to.

What can caused that, and How I can make it works?

SerialPortComm.cs

public partial class SerialPortComm : UserControl {
public SerialPort mySerialPort = new SerialPort();
public void Open_Port(string comNumber, int baudRate) {
mySerialPort.PortName = comNumber;
mySerialPort.BaudRate = baudRate;

[Code] ....

View 7 Replies View Related

Visual C++ :: Add To Listbox Thread

Feb 15, 2015

Startthread get called to launch to update list box.

a)is it the only way to pass string to the PostMessage?. my concern is that allocate using new in each iteration each time slows it down a bit.

b)does OnAddToListBox look memory leak free?.

c)What is the best way handle m_pThread at the end?. Any way to improve it?.

Code:
UINT CMyDlg::Dump(LPVOID lparam) {
HWND *pHndl = static_cast<HWND *>(lparam);
char buffer[200];
for (int i = 0; i < 100; i++) {
sprintf_s(buf,"user %d, data %s",i, "Connected");

[Code] ....

View 8 Replies View Related

Visual C++ :: Exit Application Using Thread In MFC SDI

Feb 4, 2014

I have a SDI application. I created a method OnClose to handle ON_WM_CLOSE of CMainFrm. This onclose() function calls a method in cmyview.cpp. Here, I created a thread that calls global function and from this function it calls another function in cmyview.cpp. At certain condition my application should close at here, I used postmessgae(WM_CLOSE (or) WM_DESTROY). I am having an error as object reference not set on postmessage(WM_CLOSE) it is going to afxwin2.inl page where exception occurs.

Below is code snippetHere, either j or k will only be true depneds on user input)

MainFrm.cpp:
void CMainFrame::OnClose()
{
CMyView* pview = (CMyView*)((CFrameWnd*)AfxGetMainWnd())->GetActiveView();
pview->method1();
}

[Code]...

View 3 Replies View Related

Visual C++ :: Using One Thread At A Time With CSemaphore

Oct 6, 2014

I need using CSemaphore class in MFC C++ application. I have an edit1 box with multil ine and each line has a string. I'm trying to loop through edit1 box and for each string to start a thread that is using the string for specific function. I'm trying to limit the run of only one thread at the same time with semaphores but all treads start at the same time.

So when i click button1 i loop through edit1 box and start threads:

Code:
void CMFCApplication1Dlg::onButton1Click() {
int i, nLineCount = edit1.GetLineCount();
CString strText, strLine, mesaj;
for (i = 0; i < nLineCount; i++) {

[Code] ....

While looping through edit1 box multi line and starting the threads:

Code:
UINT CMFCApplication1Dlg::StartThread(LPVOID param) {
WaitForSingleObject(semafor, INFINITE); // wait for semafor to signal
THREADSTRUCT* ts = (THREADSTRUCT*)param;
// here i'm doing some operations with the string from edit1 box
ReleaseSemaphore(semafor, 1, NULL); //release the semaphore for next thread to begin
}

Instead of running only one thread at a time all threads start. What am i doing wrong ?

View 14 Replies View Related

Visual C++ :: How To Fork Or Create Thread

Dec 23, 2012

How can I implement the paradigm demonstrated by the code below to run on WinXP?

I want to fork a process or create a thread that shares global variables with the parent process/thread.

The child process/thread monitors the progress of the parent process/thread.

I cannot find documentation for a fork function per se, a Unix term. It might be called something different for WinXP.

I would be happy to use threads instead. But I'm rusty even with Unix application threads; and I know nothing of WinXP application threads.

So any turnkey implementation that demonstrates the simplest use of process or thread functions for my purpose demonstrated below.

In either case, do "forked" processes and threads share global address space in WinXP, as they do in Unix?

I would prefer to avoid the overhead of IPC mechanisms. The "overhead" includes my own relearning curve.

The GUI screwed up my indentation. I would try to correct it. But the proper indentation appears when I edit the posting. I suppose I need to insert real tabs. Haven't figured out how (yet).

Not even real tabs work; and I cannot get the "paste as text" button to behave as I expect. What is the trick for posting indented text in this GUI?

#include "stdafx.h"
#include <stdlib.h>
#include <Windows.h>
long curCount;
int isRunning;
int _tmain(int argc, char* argv[]) {
curCount = 0;
isRunning = 1;

[code]....

View 4 Replies View Related

Visual C++ :: Unable To Display Dialog In UI Thread

Mar 11, 2015

I am having a strange problem trying to display a dialog from a UI thread. The dialog simply fails to display. I have a function DisplayFlashBox(), which creates the UI thread:

CUIThread* CIMUIHelper:: DisplayFlashBox(const CString &sMessage, const int nInstrumentUID) {
CUIThread *pThread = new CUIThread();
pThread->SetString(sMessage);
pThread->SetInstrumentUID(nInstrumentUID);
pThread->CreateThread();

[Code] .....

The dialog doesn't display. When I tried debugging, I found the OnInitDialog() method of CIMFlashBox class doesn't actually return. Very strange. I tried calling the DoModal() method instead of Create, but doesn't display the dialog either.

View 5 Replies View Related

Visual C++ :: Calling Self-contained Posix Thread?

Mar 2, 2015

pThread turns out to be NULL here. Wondering what the correct way is...

Code:
class CPF_Thread {
public:
unsigned int threadID;
Coordinater coordinater;
virtual UINT proc() {

[Code] .....

View 2 Replies View Related

Visual C++ :: Unable To Invoke JScript Functions From Another Thread

May 6, 2013

I have main thread that creates an WebBrowser2 COM object. and i want to invoke JScript functions on it from another thread. i try to use GIT but still doesn't work for me.. there is a problem with marshal WebBrowser2 for JScript?

View 4 Replies View Related

Visual C++ :: Local Variable Be Passed As Parameter Into A New Thread?

Apr 1, 2013

Can local variable be passed as the parameter for a new created thread procedure? Here is the example code:

Code:
void CDLG::some_function()
{
CString strFileName="abc.doc";
//local variable, can it be valid for being passed into the following new thread???
//Can strFileName still be accessed from within the stack of thread procedure?
::AfxBeginThread(ProcessContentThread,(LPVOID)&strFileName);
}

[Code]...

There is another method using variable on the heap,

Code:

void CDLG::some_function()
{
CString strFileName="abc.doc";
CString* pstrFN=new CString(strFileName);
::AfxBeginThread(ProcessContentThread,(LPVOID)pstrFN);
}

[Code]...

I test these code, both methods work as expected, but I doubt whether the first method is a good way. OR if only the second method is the correct way to pass a parameter to a thread.

View 12 Replies View Related

Visual C++ :: Terminate A Thread When User Push Stop Button

Nov 16, 2012

I have a thread with a while(1) loop in it. When the user push the stop button I would like that thread to end.

I thought about creating a bool and checking its value periodically in the thread and when I push the stop button I change the value of the bool for that the thread breaks out of the loop and finishes.

View 5 Replies View Related

Visual C++ :: Obtaining Actual Effective Execution Time Per Thread With Hyperthreading

Jun 13, 2013

I'm looking for a function like GetThreadTimes, but one that gives correct results in a hyperthreading CPU.

For instance, if you start 2 threads on a CPU with 1 physical core and 2 logical cores, GetThreadTimes will say that both these threads use 100% CPU.

However, in reality they only use 50% each. Is there a function that returns correct results, or is there another workaround?

View 8 Replies View Related

Visual C++ :: How To Reduce High CPU Usage Caused By Receiver Thread Of CAN Messages

Feb 13, 2013

I am writing a program which handles the CAN messages Received from BUS.My code is taking almost 60% of CPU usage.

View 14 Replies View Related

Visual C++ :: How To Raise Priority Of MIDI Input Callbacks - Thread Pools

Sep 23, 2014

I'm the author of a realtime MIDI software called ChordEase which makes use of the MIDI aspects of the multimedia API, specifically MIDI input callbacks. In XP and before, these callbacks originated in the kernel and therefore had realtime priority by definition, but from Vista on, they originate in thread pool threads, and have a priority of zero. This is a problem because at priority zero they can be blocked by the GUI thread, causing serious latency, and I have proved that such blocking occurs.

I have experimented with raising the callback thread priority, using either of the following methods: 1) calling SetThreadPriority within the MIDI input callback function, and then setting a flag so that it isn't done repeatedly, or 2) creating a DLL that catches thread creation via DLL_ATTACH_THREAD in DllMain, and calling SetThreadPriority there. The first method is slightly wasteful since the flag has to be tested for every MIDI input event, but it also has the advantage of only affecting the MIDI input threads, whereas the second method affects all threads in the pool regardless of what they're used for. Neither method appears to cause any harmful effects but they make me nervous*. Other possible methods would include 3) using the thread pool API to raise the priority of the pool (assuming I could gain access to the pool handle somehow), or 4) permanently lowering the priority of the GUI thread, which I'm very reluctant to do because of the risk of unintended consequences.

I'm assuming the MIDI input callbacks are using threads in the default thread pool though I haven't actually proved this. Assuming that's so, are these threads private to my application, or is my application sharing them with other applications? Is there a safer way to achieve the result of increasing the priority of MIDI input callbacks? It's incredibly frustrating that MS would change the behavior of MIDI input callbacks so drastically without even telling anyone, but that's how it goes!

[URL] ....

*See for example theses warnings about changing thread pool priorities : [URL] ....

View 13 Replies View Related

Visual C++ :: Error C3867 Function Call Missing Argument List For Calling Thread Function

Mar 19, 2013

I searched the web for error: C3867... and the discussions where murky or obscure.

My code excerpt is:

#pragma once
#include <windows.h>
#include <stdlib.h>
#include <process.h>
void PutUpfrmIO(void *);
namespace WordParsor {

[Code] .....

I get the generic message:

error C3867: 'WordParsor::Form1::PutUpfrmIO': function call missing argument list; use '&WordParsor::Form1::PutUpfrmIO' to create a pointer to memberc:userskingc++wordparsorwordparsorForm1.h... and the suggestion fix generate another error.

One person suggested the gcroot<> object wrapper... but I do not know how to modify/declair the function or its argument type.

View 2 Replies View Related

Visual C++ :: Check If Input Is Integer Or Not

Jun 20, 2014

I have been trying to make a very simply programme that checks if the inputted information is an integer or not (i.e: that it contains no other characters).

I have tried using the isdigit function (but this only works for single characters). I have tried cin.clear, cin.ignore (1000) but this doesn't work either..

Any effective way to check if x in the following programme has been entered correctly

#include <iostream>
using namespace std;
int main() {
cout << "Please enter an integer (positive or negative)" << endl;
int x;
cin >> x;
HERE I WOULD LIKE CODE TO CHECK IF THE USERS INPUT IS VALID
}

View 2 Replies View Related

Visual C++ :: Utility To Check DLL Is 32bit Or 64bit?

Jul 25, 2013

I have two third party DLL files that I wanted to check if they are 32bit or 64. I searched the web and some suggested corflags, I found it under "C:Program Files (x86)Microsoft SDKsWindowsv7.0ABin" (my machine is 64bit but I didn't find the utility under "Program Files" folder), it came out with the message:

corflags : error CF007 : The specified file does not have a valid NT file header

Whats wrong with it?

View 4 Replies View Related

Visual C++ :: Check Whether Application Instance Is Running Or Not

Jan 20, 2014

For my project I need to check whether my application instance is already running or not. I got the following code from Net ..

Code :

HANDLE mutex;
mutex = CreateMutex( NULL, TRUE, _T("MYAPPNAME"));
if ( GetLastError() == ERROR_ALREADY_EXISTS ) {
// There's another instance running. What do you do?
AfxMessageBox(_T("Application Already Exists"));
PostQuitMessage(0);
ExitThread(0);
return;
}

The code works fine .. but the code even works fine , even if I pass any string as a parameter to CreateMutex. E.g.

mutex = CreateMutex( NULL, TRUE, _T("QQQQ"));

How it is working fine ?

View 5 Replies View Related

Visual C++ :: Check Type Of Argument Passed To Each Function?

Feb 24, 2015

How to check the type of argument passed to each function, checktype, in below?.

void checktype(void *p)
{
}
or
template <typename Type>
Type checktype(Type t) {
}

View 3 Replies View Related

Visual C++ :: Runtime Check Failure - Variable Used Without Being Initialized

Nov 10, 2014

Under visual studio, this is a typical run time error,

Code:
void func(int x){
x = 3;
}
int main() {
int x;
func(x);
}

When x is passed to the function func, it is not initialized. But my question is that why it should be an error? On the other hand, if I change the definition of func a little bit like this,

Code:
void func(int& x) {
*x = 3;
}
int main() {
int x;
func(&x);
}

Now in main, x is still not initialized, but this time there isn't a run time error like "the variable is being used without being initialized. Why?

View 5 Replies View Related

Visual C++ :: Runtime Check Failure - Value Of ESP Error With Conversions

Dec 2, 2014

I get this error:

run-time check failure #0 - the value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention

when i try to run my code. It has compiled fine on another computer, but it simply will not work on this one. This is the part of code where it is receiving the error. it has to do with the stoi

Code:
#include <string> // for use of string
#include <fstream> //for file handling
#include <iostream> // for file handling
#include <cstdlib>
#include <iomanip> //for the setprecision used further below
using namespace std;
struct MasterData //struct created named 'MasterData' to hold one line from master file

[Code] .....

View 2 Replies View Related

Visual C++ :: Unable To Check If Character In 2D Array Is Alpha?

Nov 20, 2012

I am unable to check if the character in the 2D array is alpha

here is my code

#include<iostream>
#include<cctype>
#include<cassert>
#include<cstring>
const int maxChar = 20 ;
using namespace std ;
int main() {
int count = 0 ;
char d[2][20] = { "hi" , "di" } ;

[code]....

View 8 Replies View Related

Visual C++ :: Check For File Existence - Function Will Fail Or Return Non-zero Value

Sep 21, 2013

Just wonder is it possible that if the file exist, this function below will fail by returning non-zero value?

_access( INIFilename, 00 )
00 - check for Existence only

I noticed that sometimes if even the file exist, the function will fail or return non-zero value. So trying to find out and duplicate this error. It tends to happen intermittently. How can I find out what causing this error?

Code:
char INIFilename[256]="C: emp est.ini";
unsigned long Error = 0;
if( _access( INIFilename, 00 ) != 0 ) {
Error= GetLastError();
printf ("Failed to access INI file %s (%ul)", INIFilename, Error);
}

View 5 Replies View Related

C++ :: Access Objects From Another Thread

Jun 25, 2013

I have the following code below. I am getting a memory access violation when accessing cmd->query_string in the loop function. The loop() function is running in another thread. The cmd object appears to be destroyed after calling the send_command function. How do I create an object on the heap and access the query_string.

std::list<my_command_message_que*> my_command_que;
void loop(){
if(my_command_que.size() > 0){
my_command_message_que * cmd = my_command_que.front();
std::cout << cmd->query_string;

[Code] ....

View 2 Replies View Related

C++ :: Passing Parameters To A Thread

May 9, 2013

I've been using threading for a while, that was no needing parameters. so I used for example the following line :

_beginthread(functionName, 0, (void*)10);

and it worked great...

but now I have a function that has an int parameter (int num), and I dont know how to transfer it using _beginthread...

View 2 Replies View Related

C++ :: Thread Chaining And Latency

Mar 3, 2013

I was working on a problem that was best solved with chaining threads together using a blocking thread-safe queue. Eg threads A and B pass data to each other using a queue ... a simple producer consumer design A -> B. This has two benefits: 1) being that there is a buffer between the two threads to cache for a slow consumer and 2) allows for better throughput when loads of data are high because the two can run in parallel. Most of the time the design works well under load. but I found when pushing data through the threads intermittently, i.e. once about 0.5 seconds it ran poorly, mostly from what seemed to be latency introduced during the OS waking up of the consumer thread B.

What i have come up with to solve this issue is what i call an .... Its a wrapper around a basic thread safe queue and adds one extra function called .... The idea here is that if you have a simple case (or perhaps a slightly more complicated case) of two threads in a prod cons design and you know the producer will create or received the data, process it, and then push onto the queue, why not give the consumer thread a heads up to let it know the data is about to arrive. In this case call .... In this way you can have the consumer thread in a polling state anticipating the arrival of data and avoid the time to schedule it back to a running state.

Anyway, i have some code below and I was looking to get some feedback. I have tested it somewhat and it does improve the responsiveness quite substantially.

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved