|
Thanks a lot Chris!
I got it working. In hindsight your instructions totally make sense since I am just trying to pass data from one class to another. I just never thought of everything in VC++ as classes before even though I always knew they were – tells you how experienced I am in C++.
Anyway, once again thanks; you saved me a lot of time.
-Nick
|
|
|
|
|
You may want to abstract things a bit further and make a container class for your data. Then you can make methods to perform your calculations and easily pass the data object (as a pointer or reference) between dialogs within your app. As Chris mentioned, it would be best to have Set/Get methods in the data container class to access its data.
|
|
|
|
|
What's the difference between
system("myGame.exe");
and
system("start myGame.exe");
?
And how does one use system()? What is the return type? How can one kill a process started by system("start myGame.exe -machinefile bla")?
Is fork() just basically spawns multiple clones on localhost (the same machine)? And can fock() be given additional parameters so that the newly spawned process is executed differently?
|
|
|
|
|
The answer to all of your questions can be answered with: don't use system() . You need to use this instead.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
system just executes a command as you would have typed in DOS...
looking at the 'START' help, it says that it "Starts a nedw windows to execute the programme or the typed command".
in DOS, type START /? to have more details.
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Hello,
I'm writing a windows application with visual c++ that runs an external process which eventually consumes 100% of the cpu (even at Low priority). I understand the windows scheduler will allocate all available cpu resources to a process if no other processes are ready to run. However, I need to limit the cpu usage for my subprocess to a certain percentage of the cpu to 1) reduce cpu temperature, and 2) maintain responsiveness for other applications.
There are a number of freeware utilities that do this like ThreadMaster, AppSense, and various others, but I would rather be able to set cpu usage limits within my application.
My question is, does anybody know how apps like ThreadMaster do it?
Any help would be appreciated.
thanks
|
|
|
|
|
I would take a look at the SetPriorityClass function. For finer grained control, you could also consider enumerating the threads in the process, and using SetThreadPriority to drop the priority of those threads. You could also call SuspendThread and ResumeThread periodically (passing in a thread id of your child process) to further reduce the workload.
|
|
|
|
|
|
Thanks Graham. I thought I had gone the suspend/resume route last week, but I tried so many things, it's all kind of fuzzy right now.
I tried it again this morning, and it seems that if you 1) set the priority class to IDLE_PRIORITY_CLASS, and 2) do the suspend/resume dance every second, you can achieve the desired cpu usage percentage cap.
Example:
CreateProcess(args...) // priority= CREATE_SUSPENDED
SetPriorityClass(procInfo.hProcess, IDLE_PRIORITY_CLASS);
int cap = 60; // cap at 60% usage
int run = cap * 10; // run for 600 ms
int idle = (100 - cap) * 10; // suspend for 400 ms
bool isdone = false;
while (! isdone) {
ResumeThread(procInfo.hThread);
// need better handling to determine when process is complete
isdone = ::WaitForSingleObject(procInfo.hProcess, run) != WAIT_TIMEOUT;
if (! isdone) {
SuspendThread(procInfo.hThread);
isdone = ::WaitForSingleObject(procInfo.hProcess, idle) != WAIT_TIMEOUT;
}
}
The above code snippet seems to work fine without any adverse effects on the running process.
Thanks to all who replied.
mb
|
|
|
|
|
My problem is:
I need to retieve the informations of users of a Windows Server in order to my application. By this moment, my app has a Database (MS-ACCESS) with a Users Table to access to App and I want to use the database from a Windows Server. By this way when a user has log in a system don't need to log to my app.
Can anybody help me?
thaks a lot
Xavier
|
|
|
|
|
ivax wrote:
I need to retieve the informations of users of a Windows Server in order to my application.
I don't quite understand your question, but perhaps I can speculate and offer these:
NetUserEnum()
NetUserGetGroups()
NetUserGetLocalGroups()
NetUserGetInfo()
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Thanks David.
Mu propose is retrieve UserId, Name and Password, Insert them in my Table. When a User Login in a Server I want to use the User Id And PWD in order to login in my app.
For example: A user is logged in a the Windows Server like UserId = IVAX and PWD = MYPwd.
If this User want to login in my app then he must enter again one valid UserId and PWD defined in my Database (MS-ACCESS).
My porpouse is use the User information from Windows Server Database in My application adding in my Table Users other information more.
Thanks again
Xavier
|
|
|
|
|
To my knowledge, there is no way to obtain the password that was used to login to the machine (that's not to say that a way does not exist). The user id is easily obtainable.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
You can't user's passwords at all. See Raymond Chen's blog[^] for a detailed explaination of why not.
|
|
|
|
|
I'm a newbee with MFC. I'm following this article on Worker Threads:
http://www.codeproject.com/threads/usingworkerthreads.asp[^]
With the following code I'm getting the following error. Any suggestions as to what is going on here?
: error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'void (void)'
<br />
<br />
#include "stdafx.h"<br />
#include "canmon.h"<br />
#include "getcanmessages.h"<br />
<br />
#ifdef _DEBUG<br />
#undef THIS_FILE<br />
static char THIS_FILE[]=__FILE__;<br />
#define new DEBUG_NEW<br />
#endif<br />
<br />
<br />
static UINT run(LPVOID p);<br />
void run();<br />
volatile BOOL running;<br />
<br />
Cgetcanmessages::Cgetcanmessages()<br />
{<br />
}<br />
Cgetcanmessages::~Cgetcanmessages()<br />
{<br />
}<br />
void Cgetcanmessages::gogetcan()<br />
{<br />
running = TRUE;<br />
AfxBeginThread(run, this);
}<br />
<br />
UINT Cgetcanmessages::run(LPVOID p)<br />
{<br />
Cgetcanmessages * me = (Cgetcanmessages *)p;<br />
me->run();<br />
return 0;<br />
}<br />
<br />
void Cgetcanmessages::run()<br />
{<br />
}<br />
<br />
|
|
|
|
|
See here.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Freddie Code wrote:
static UINT run(LPVOID p);
void run();
volatile BOOL running;
I suggest you rename the second function above. There are two functions named run(). One is UINT run(LPVOID) and the other is void run().
Rename the void run() to anything else because the compiler is getting confused.
this is this.
|
|
|
|
|
Why does the following code, when running, causes some programs to hang while starting (before presenting any UI), including Windows Explorer/Internet Explorer (when double-clicking an HTML file in Windows Explorer) and the AnalogX PacketMon installer[^]?
#include <iostream>
#include <tchar.h>
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
HWND gWnd = CreateWindow(_T("STATIC"), _T("SomeWindow"), WS_POPUP, 20, 20, 200, 200, 0, 0, 0, 0);
getchar();
return 0;
}
|
|
|
|
|
Why are you trying to create a GUI component in a console application?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I'm using a library (not easily modified) that does that call. If I change "STATIC" to "STATIC_" (or probably anything else), the problem disappears.
|
|
|
|
|
What exactly is it that you are trying to do? CreateWindow() is a GUI, not a console, function that creates a window. It also sends messages (something that a console application knows nothing about) to the window's procedure.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I know it's not proper, but it's in a (internal) library that would be hard to modify. Because using something other than STATIC doesn't appear to cause problems, it seems like there might be a way to get it to work (a define? another header file?). I basically just want to understand why using STATIC causes problems and using anything else doesn't cause problems. I like to know the causes of problems, not just the solutions.
|
|
|
|
|
IGx89 wrote:
Because using something other than STATIC doesn't appear to cause problems...
Have you entertained the thought that "doesn't appear" might be the key phrase here? Just because you do not see a problem does not mean a problem ceases to exist.
IGx89 wrote:
I like to know the causes of problems, not just the solutions.
Unless you have not shown all of the code, you're trying to solve something that is the product of a bad design. Why are you trying, or even thinking that it's possible, to create a static window from within a console application?
Much the same result can be achieved by trying to use getch() or printf() in a GUI application. Yes it might compile/link fine, but a "crash" of some sort is emminent.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
|
Can you elaborate on that?
|
|
|
|