Visual C++ :: Exiting Application During While Loop Operation
Jun 16, 2013
I have a VC++ 6 dialog-based application. This application is intended for reading data from a USB device (this is a FTDI FT245R chip). I have a start button on the dialog. On clicking it, unsigned char data retrieved from the USB device is displayed on the dialog. The start button invokes a function which includes a while (1) loop inside which the USB device is read and the values displayed.
There are no break or continue statements inside the always operating while (1) loop. All this works fine. My problem is how do I exit the application as normally it would just run forever? I have put an exit button on the dialog with code added to call OnOK(). Normally this would nicely close the application but as I have an endless while loop in my application so this button doesn't seem to work. Nothing happens on clicking it and clicking it repeatedly just hangs the program.
If I were to exit a program, is it okay if I fail to properly destroy whatever structures were allocated?
For instance, if I do this with SDL, there might be obvious consequences like a dead window perhaps. But if I do this with a POD structure, is it okay?
Also, I realize RAII is supposed to fix parts of this but it's not perfect when environments are suddenly cut off with something like exit(1/0);
I have a question about to run an MFC dialog based C++ application from console: if I run my application from console, I see the application start and the console immediately back to prompt. I need that console wait the application exit before show me the prompt again. I tried on Visual Studio 6, 2005 and 2010 but the behavior is the same.
I passed the CStringArray to dll & wrote the String in a file.
The error File: array_s.cpp, Line No: 420 was occured when i close the .exe file.
For your reference:
Code: Function Declaration in DLL : DECLDIR void SetParName(CStringArray& ParName); Function Definition in DLL : DECLDIR void SetParName(CStringArray& ParName){
ParName.Add("X1"); ParName.Add("X2");
[Vode] .....
My doubt is, CStringArray items are allocated in the DLL. So, when i release the CStringArray object in the application. Is it can release memory that are allocated in the DLL ?
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)
I have a Win32 C++ application which works pretty well, but I don't like the GUI and I want to replace it with one designed graphically, a la Windows Forms. What is the best strategy to port my code? I tried creating a new Windows Forms C++ application and got pretty far with it, but was stymied when trying to call my unmanaged functions on a button press. If I can't use Forms to add a GUI without completely rewriting the program, what's my best bet?
In a typical MFC application I use SetRegistryKey(_T("My_Company")); to set the root registry entry for my application. The MFC application however creates an entry by the name of executable where it stores all the settings of that application. I don't want that because we often change the name of executable and I want it read registry from the same set location. As example if my application name is Calculator.exe and Calculator_debug.exe it creates two different registry settings.
I am developing a MDI application that will contain a RibbonBar and a Properties Pane window. The MDI documents are not tabbed. I am finding that when I try to move the client window around, it gets clipped by the RibbonBar and the Properties Pane window (shown in image). I know the client window cannot go outside the client area, but can the client window be on top of the ribbon bar and the properties pane window?
I am new in Visual C++ and I have to make an MFC application with "child" windows. Here is what i need to achieve - [URL] ..... As you can observe when you click on the cross of popup window or child window 2 both are closing.
I'm struggling with the pan gesture in a desktop application for my Surface Pro 2.
I simply want to pan (or "swipe" if you prefer) with two fingers, but it doesn't behave like I want it to. If I put two fingers on the screen and move them straight diagonally, I receive a series of client coordinates that are aligned in a vertical or horizontal direction. Only if I perform some circular motion, then it's suddenly possible to move diagonally and receive coordinates accordingly.
I've tried with MFC, by overriding CView::OnGesturePan. I've also tried with a sample project provided by Intel, that handles the GID_PAN message in WndProc to move a rectangle around, but with the very same result. The project can be downloaded from [URL] ... fordesktop.zip, so you can quickly reproduce the behaviour if you have a touch screen.
I first thought it had to do with the points being too close to each other. I mean, if two points lies only one pixel apart, it can only result in eight different directions. But if I modify the code to only update "m_first" when the distance between the points are greater than some minimum distance, the points still keep being projected to a horizontal or vertical line relative to the first starting point.
I have created a MFC dialog based application. Now I want to implement such a functionailty that I will be closing my application through command prompt. And while closing of my application the ExitInstance() method of my application should get called. What is the command which I should put in the command prompt to close my application in such a way.
I am doing an project in SDI. I have two functions name sendtext(CString str) and displaytext(CString inr) both in different class. I have a pointer name pView to send the string str to function "displaytext". The problem is after some operations i get a text in str and i send that text to display text in the output screen i get the text and wen the second text comes to "displaytext" the former text disappears and the latest string only present. How can i display both the text in the output window on ClistCtrl class.
I use standard libraries and INNO Setup, wich is a free setup file creator.
I succeeded in adding NetFrameWork 4.5 installer into the setup (it runs it after installation, and before running my software (named GOFINDER).
Now, i remember that this happened to me, but after three months of programming, mine used to start and still does. But I know it sometimes doesn't start, and I don't know why exactly.
I checked to make sure that I needed only FrameWork 4.5.
But maybe it is because of Visual C++ Runtime wich is not added upon setup.
I will try to check this after posting cause this has just popped up in my mind.
I'm asking you how can I Make sure, that distributing my software won't do that anymore.
Is it because my application file is not set on Run as Administrator?
Cause normally, it opens without this necesity, except as a Shell (well I have to check back but I think it does if I check on the run as administrator checkbox.
The problem is not really with InnoSetup, but I also would like to know how I can check that box automatically upon setup.
they say they have a documentation but I don't find it on my computer.
And... why would it start on my computer, and not on my beta-testers's one?
As a starter project I want convert a Neural net app from "AI Techniques for Game Programming (2002 Buckland)" to a Visual C++ CLI Forms application. I have created the interface and now I have to rewrite the in/output routines, amongst other things.
First question I have has to do with variable initialization used by Buckland. Code looks like this:
Excerpt from header file (CNeuralNet.h):
//------------------------------------------------------------------- //define neuron struct //------------------------------------------------------------------- struct SNeuron { //the number of inputs into the neuron int m_NumInputs; //the weights for each input vector<double>m_vecWeight;
[code]....
Question I have: what is the the function of ": m_NumInputs(NumInputs+1)" after the method declaration? Buckland does this in many places in his code. In this case it's a struct, but he does it with classes too.
I'm using VS 2012. Installed MYSQL 5.6, C++ Connector 1.1.3. Created a sample table using mysql. Now i like to create a connect between mysql and MFC dialog. Using this, i was try to connect.
Server Explorer -> Data Connection -> Add Connections ->MYSQL Database -> Addconnection
To get the connection, i want to enter the connection settings like:
server host name = localhost, user name =root, password=
If I pressed any letter in the keyboard means add connection dialog was closed automatically.
I've been trying to make a little quiz application that takes questions from a file and them presents question by question on a static pannel, a few buttons that have the possible answers on them written as the questions go, and on the bottom a little place where we can see whats our score.when we finish the quiz, the score gets writen in a data.dat file and thats that.
I'm trying to write a program that passes Windows messages back and forth from another program that controls a laboratory instrument. I was able to write a program that successfully passes instructions, as evidenced by the instrument doing what I tell it. However, I am having trouble getting a return status from the instrument. The manual instructs the following:
// demo code, etc. // send message to the instrument operating software here... SendMessage(hwnd, WM_COPYDATA, tag, (LPARAM) &cd)
Either a completion message or return data is returned. Remote commands ReturnStatus, ReturnTiming, and ReturnData return data. In either case, data is received through an asynchronous windows message inside Win32 COPYDATASTRUCT type data packet.For example, a typical OnCopyData window callback is shown below, where the string data retrieved is finally stored into a Microsoft CString object. Note the use of variable replyTag, discussed above, which is used to isolate the correct windows message returned.
BOOL CUserDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* cd) { …. if (cd->dwData == replyTag) { /* String pointing to status */ CString retStatus = (char*) cd->lpData; } …. }
I can't tell if my problem is in generating the replyTag, getting the HWND to my own console window, or the actual receiving part of the code.
When setting the replyTag, the manual instructs: UINT replyTag = RegisterWindowMessage(“SOFTMaxProReplyMsg”);. However, I have to put an "L" in front of the string or I get a data type error (can't convert const char* to LPCWSTR).
When setting a HWND for myself, the manual instructs: HWND MyWnd = GetSafeHwnd().
That produces an error because GetSafeHwnd is a function of the Cwnd class, and I don't have a Cwnd. I have replaced it with HWND MyWnd = GetConsoleWindow();
When listening for the reply message, the manual instructs what I quoted above. However, I again don't have a Cwnd. I therefore simply used
The above if statement always evaluates false, and the cd.lpdata contains the message that I had sent out instead of a reply message. How to get a reply using my console application. Here is the full code of my function:
Code: #include "stdafx.h" #include<iostream> #include<vector> #include<string> #include<afxwin.h> using namespace std; void SendCommand(string command) { // Get tags to identify the receiving and sending messages