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
ADVERTISEMENT
Mar 2, 2014
I'm trying to make a "Rain" application, by drawing some lines on the form, and then they must fall. So here is my start code:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
Random r = new Random();
Graphics paper;
Line line;
[Code] ....
So when I start debugging I get the "Object reference not set to an instance of an object." error. If I remove the comments lines at "timer1_Tick" this error doesn't appear of course. What can I do to escape from this because it follows me everywhere I go />. I tried to make with arrays, but same problem.
View 4 Replies
View Related
Dec 18, 2014
I have a service A, and an application B. Service A needs to launch application B only if it's not running currently. This can be easily done in Windows by calling GetExitCodeProcess function. I cannot find an equivalent method for doing so in Linux/Mac.
So my current code says:
system("open /Users/adsmaster/client/client &"); // to launch the application from the service in a new shell
I read that on a Linux-line machine you can use $ cal to get the exit value of the recently run process but I am not sure how can get the exit value of a particular process?
View 1 Replies
View Related
Feb 26, 2015
I'm fairly new to PowerShell and I'm trying to run this command from my application to return the 25 newest entries in the application event log and save them to a file on my desktop. Here's the code. I get an Common Language Runtime error with no real information.
PowerShell ps = PowerShell.Create();
ps.AddCommand("Get-EventLog");
ps.AddArgument("application");
ps.AddParameter("Newest", 25);
ps.AddScript("Format-List > ~\Desktop\samplelog.txt");
ps.Invoke();
Here is the Method: [URL] ....
Here is the Error: [URL] ....
View 10 Replies
View Related
Apr 3, 2015
For my c++ we're suppose to write a program that prints out a check. It's suppose to translate the numeric value of the dollars to worded strings.
Header File:
#ifndef CHECKWRITING_H
#define CHECKWRITING_H
#include <string>
[Code]....
View 1 Replies
View Related
Mar 24, 2013
actually it is the windows application .When i'm running my program it is not allowing me to enter the data into textboxes means the cursor is not appearing
View 1 Replies
View Related
Dec 11, 2013
I have written a program which uses a pid to check if the process is currently running and return a value based on the system call result.But the program core dumps
Code:
#include <stdio.h>
#include <string.h
int main( argc, argv )
int argc;
char * argv[];
{
int p_pid = 99;
char buff[1000];
}
[code]....
What is the mistake in this code and is it portable in both unix/linux , is the method secure (grepping for program name )?
View 6 Replies
View Related
Nov 26, 2014
I'm trying to simulate a ctrl+ keypress into a running application.
Code:
#include <stdio.h>
int main (void) {
system("/usr/local/bin/rundb");
}
My problem is that the rundb program needs the user to type ctrl-b then s to actually start executing. What is the best way to handle this automatically? Some sort of fork/pipe?
View 3 Replies
View Related
May 23, 2013
I need to create an object of a mfc derived CFormView class that's not in the doc/template (a second view class). But it was generated with a protected ctor. Here's the code explanation with comments.
I'm thinking all the normal classes of the Doc/View template are created starting with this code, but within the template code base.
Code:
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(IDR_MAINFRAME,
RUNTIME_CLASS(CViewSwitchDoc), //<-expands to-> ((CRuntimeClass*)(&CViewSwitchDoc::classCViewSwitchDoc)),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CViewSwitchView));
But I have generated "another view" using the "Add Class" Wizard, it's a derived class of mfc CFormView which I named ViewForm. However I'm having a problem creating an instance of it because of the generated protected ctor and pulls a compile error of not being able to access ctor. Below are the header and implementation files of this said ViewForm class. How to create an object of this view ? Did I go about it all the wrong way since it's not in the doc/template group ?
// ViewForm.h file
#pragma once
// ViewForm form view
class ViewForm : public CFormView {
DECLARE_DYNCREATE(ViewForm)
[Code] ....
View 5 Replies
View Related
Apr 22, 2013
i created a windows service that will run another program. but the program i want to run has a gui and i don't want the gui to be visible, i just want the program to run in the background.
But i have to do it without editing the gui program
here's my code:
Code:
TCHAR* path = L"C:Myfile est.exe";
STARTUPINFO info = {0};
PROCESS_INFORMATION processInfo;
ZeroMemory( &info, sizeof(info) );
info.cb = sizeof(info);
[code]....
i tested this code with notepad and it runs notepad in the background without displaying the window but when i try run my program it doesn't work. i don't know why its works for one program and not the other..
View 14 Replies
View Related
Aug 30, 2013
I would like to programmatically monitor a directory for new files, and if the file happens to be an executable, I want to prevent it from running. Something like a AV program.
However, I don't know where to start. Simple is best.
View 9 Replies
View Related
Nov 25, 2014
I'm having some issues with my code. For the produce function i am getting an error saying 'no instance of overload function produce() matches the argument list' and also for the lines buffer[head].data = message; buffer[head].time = current_time i get an error saying 'expression must have pointer to object type.
In the code i'm not sure if i passed the variables to the function correctly. I have attached the code .....
code produce.txt
View 14 Replies
View Related
May 2, 2013
No I definitely used Visual Studio Command Prompt
c:Program FilesMicrosoft Visual Studio 9.0VC
un_process_from_service>make.bat
View 7 Replies
View Related
Nov 4, 2012
I see there's something called a manifest file but VS C++ EXPRESS seems different than non-express. The solutions I've seen show applets/tabs that I don't have in Express.
In one of my physical DEBUG folders are some .manifest. files and some a .res and .rc file.
I know you need to edit the XML and change asInvoker to requiredAdministrator (or something like that).
The confusing part is if I go into Project Properties, MANIFEST TOOL caret/tree, under INPUT AND OUTPUT, it shows this .manifest file is OUTPUT. It's as if it rewrites it every time with some defaults? I have edited it, but I see it's back to asInvoker. There is a spot to put in a ADDITIONAL manifest file (or .res file).
Does a manifest somehow affect the physical .exe file (something is imbedded in it??)?
How do I change my project to make sure that the .exe always runs as Admin? Will doing this ALSO allow me to DEBUG it in VS C++ EXPRESS without having to do anything different (play with manifest or run VS outright with Admin level)?
View 2 Replies
View Related
Feb 28, 2013
I am stuck on an exercise where i am supposed to use a loop to take user input and keep a running sum until the user enters a 0. the code i have so far is:
#include <iostream>
int main() {
using namespace std;
int num;
int total = 0;
int x;
[Code] ....
The full text of the error message is: error c2678:binary'>>':no operator found which takes a left-hand operand of type 'std::istream' . and one more thing i was wondering, is there a difference between c++ and visual c++?
View 4 Replies
View Related
Apr 25, 2014
I am encountering a problem on retrieving the Window Proc of a window that running in a process with another user.
For example, I have logon windows with domainuser1, and run the following command as:
runas /profile /env /user:domainuser2 C:WindowsSystem32calc.exe
And then the Calculator is shown in domainuser1 desktop, but the process is running in domainuser2 account.
When running Spy++ (either wither domainuser1 or domainuser2) to view the calculator window, the Windoe Proc field is shown 'Unavailable' I also try to call GetWindowLong against this window, it will always returns NULL.
I am just wondering if it is possible to retrieve the Window Proc of the window running in a process of another account, is is possible?
View 9 Replies
View Related
Nov 15, 2013
I have a C++/MFC application that displays a count in a window:
The count (text) is displayed via a `CStatic` control. The mechanism is very simple. I call it every 1000 ms and update the text as such:
Code:
void CTestCountdownFlickerDlg::RedrawCounter(LPCTSTR pText)
{
CStatic* pTxtBox = (CStatic*)this->GetDlgItem(IDC_STATIC_COUNTER);
ASSERT(pTxtBox);
[Code]....
What happens is that the `CStatic` control updates without any issues on the OS with visual themes enabled, but if I run it on the OS with the Windows Classic theme (for instance, the screenshot above is from Windows 7) the `CStatic` control produces a visible flicker every time it updates the text.
Well, I understand that I'm nitpicking here, still I would really like to get rid of this flicker.
Here's what I tried:
1. In my actual project I tried subclassing the `CStatic` control and removed the processing of `WM_ERASEBACKGROUND` by simply returning 1. That didn't work.
2. In the same subclass for `CStatic` control I tried to override `WM_PAINT`, but that didn't work at all. So I'm not sure if I'm going too far with it at this point.
I'm attaching the C++/MFC source code for my test project .....
View 14 Replies
View Related
Jan 21, 2013
How can I check if window media player is running in full screen mode & topmost in c++ MFC?
What I used is this logic:
I compared media player full screen coordinates to that of monitor coordinates.If they are same implies media player is in fullscreen.But it has one flaw.Whenever there are control(for play,pause) displayed in full screen in media player, coordinates are not coming same as that of monitor.
View 10 Replies
View Related
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
View Related
Feb 7, 2013
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.
View 3 Replies
View Related
Jun 23, 2014
I want to achieve such an efect like - one view which takes all MDI area and some views which arelike non modal dialogs
Two Child frames will be correct? one for "big" view which will be always visible and second for a "smal" views
View 2 Replies
View Related
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
Mar 23, 2013
We have developed MDI application on 17 inch monitor in VC++ 2010 MFC. But now management wants application to run on 10 inch laptop.
Application does not fit,it goes out of screen. How to fit application on smaller screen
View 1 Replies
View Related
Feb 11, 2013
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 ?
View 1 Replies
View Related
Jan 15, 2014
I have a HTML code and i need to developing a form application.
issue: i have a html code and a database table , how to put this together with code and link them and peu them on server ...
View 3 Replies
View Related
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