|
|
I'm Sorry,
That is a HANDLE,
which is a waitable object.
At anyrate, it's the handle returned by 'FindFirstChangeNotification'
P1p3r
|
|
|
|
|
You can poll...
bool fCancel = false;
while (!fCancel)
{
if (WAIT_TIMEOUT != WaitForSingleObject( hFile, 100 )
{
(event was signaled - do some stuff)
}
}
|
|
|
|
|
Even better than polling (polling takes CPU cycles)...
HANDLE hCancel = ::CreateEvent(NULL, false, false, NULL);
...
#define EVENT_FILE 0
#define EVENT_CANCEL 1
HANDLE Events[] =
{
hFile,
hCancel,
};
DWORD dwEventIndex = ::WaitForMultipleObjects(sizeof(Events) / sizeof(HANDLE),
Events, FALSE, INFINITE);
if (dwEventIndex == WAIT_FAILED)
{
some error occurred
}
dwEventIndex -= WAIT_OBJECT_0;
if (dwEventIndex == EVENT_FILE)
{
file event was signaled - do some stuff
}
else
{
cancelled
}
use ::SetEvent(hCancel) to cancel the wait
|
|
|
|
|
Thanks for for info,
I'm going to try it out
P1p3r
|
|
|
|
|
use setEvent(hFile) function to single handle...
you can't end the wait because of infinte time interval given in WaitForSingleObject.
|
|
|
|
|
Thanks.
This is actually what I was looking for.
The previous post also worked quite well
P1p3r
|
|
|
|
|
I'm trying to mess around with Microsoft's XNA the 360 game programmer if anyone could help please. And even if you can't can I have a tutorial or two to learn how to use visual C++. Or maybe how to create pictures from a coding system?
I'm a true failure.
|
|
|
|
|
Hi,
I'm starting to use Visual Studio 2005 and I'm having some major issues. For instance I create a new C++ -> MFC Application and when I declare some CStrings in a member function they don't initialize correctly.
For instance:
CString a,b,c,d,e,f; <- Right after declaration they will have values of "" except at least one will have a value <bad ptr>
I can also try:
CString a = L"";
CString b = L"";
etc
But I'll end up with the same problem.
Also, I notice when I debug I can't see any ints that I've declared - they are in scope, but I can't see the values.
*** When I make my variables static - everything works fine....
Is this some sort of managed C++ thing? I'm just writing simple code that worked in Visual Studio 6, 2003, etc...
Help!!
Mike
|
|
|
|
|
Can you post an example function showing the variables and how they are defined?
If you declare them but don't use them then the compiler may optimize them out so you can't view
them in the debugger (because they aren't there).
Mark
|
|
|
|
|
I tried creating a new project. Defining CStrings and setting their values to "" and using ints. They all show up normally in the debugger.. I'm pulling my hair out here. I am testing on two different computers. If I create a new project from scratch, I can't reproduce the bug. In my current project, I clean, rebuild, etc, and it won't go away. I'm beginning to think something is corrupted in my project!
In my code, I have a class that declares these locally in a function. The variable names exist no where else. The weird part is as these get defined I watch the <bad ptr> change to "". *Except* for sday, it will always be bad ptr, I can rename the variable, change the order that it is defined - it will *always* be a <bad ptr> how is that possible??
Furthermore - when the variables initialize they all turn to "" except sday. Here's the best part - when the variables get set to "test" I watch CString a,b,c,d etc randomly get those values not the variables I'm setting to test....
The code *seems* to be executing correctly, but debug is just a complete mess! This is on two different systems, one being a clean build.
Once again defining these as static makes everything appear correct in the debugger.
If my project is corrupted somehow - is there a way to super clean it? Or am I stick redoing it?
Thanks!
I've stripped my code down to this:
bool CPCInfo::goodVscanDef(CString local, CString server)
{
CString a,b,c,d,e,f,g,h; //this is just for some additional debug tests
CString lmonth;
CString lday;
CString lyear;
CString lrev;
CString smonth;
CString sday;
CString syear;
CString srev;
lmonth = L"test";
lday = L"test";
lyear = L"test";
lrev = L"test";
smonth = L"test";
sday = L"test";
syear = L"test";
srev = L"test";
return false;
}
|
|
|
|
|
>>I'm beginning to think something is corrupted in my project!
Sounds like it!
May not help, but you could try closing VS2005, rename the solutionname.NCB file to
solutionname.NCB.bak open the solution (solutionname.NCB gets rebuilt), clean\rebuild and see
what happens.
Mark
|
|
|
|
|
Thanks! I forgot about the .nbc - I used to have to delete it to fix intellisense issues with other versions
That fixed it. I was beginning to think somehow I was doing something wrong...
|
|
|
|
|
Hi all,
I am new to windows programming, I am converting my OpenGL program written in Linux platform into Windows platform. I have used glutIdleFunc() for idle callback func, now I would like to use the same callback func as idle func in Windows platform. How can I use a func as idle func in Windows without using GLUT.
Any help would be greatly appriciated.
Thanks
Scody
|
|
|
|
|
I guess it ultimately depends on how you write your own OpenGL program. You can still use GLUT and freeGLUT under Windows platforms, that keeps your code mostly identicle between platforms. The other is to insert your code into it's own call system.
Since freeglut is "free" you can also examine the code to see how the idle function was used. http://freeglut.sourceforge.net/docs/api.php[^]
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
If I setup a static variable like this:
[CODE]
// .h file
class DisplayLine
{
static SolidBrush s_solidBrush;
...
};
[/CODE]
and initialize it like this:
[CODE]
// .cpp file
SolidBrush DisplayLine::s_solidBrush(Color(255, 0, 255, 0));
[/CODE]
and then in the draw() routine do this:
[CODE]
void DisplayLine::Draw(Graphics *pGraphics)
{
// Draw the text
pGraphics->DrawString(buf, -1, &font_big, lineRect, &sFormat, &s_solidBrush);
}
[/CODE]
that the text will not draw due to the brush. Weird.
What am I doing wrong? Why is the brush not getting initialized?
I even tried adding this:
s_solidBrush.SetColor(Color(255, 0, 255, 0));
but that didn't help.
-- modified at 18:51 Monday 9th October, 2006
|
|
|
|
|
>>the text will not draw due to the brush. Weird.
How do you know this??
Mark
|
|
|
|
|
Because if I creat a brush in the draw() method it works fine.
This works:
void DisplayLine::Draw(Graphics *pGraphics)
{
Font font_big(L"FIXEDSYS", 18, FontStyleBold, UnitPixel);
Font font_small(L"FIXEDSYS", 12, FontStyleBold, UnitPixel);
StringFormat sFormat = new StringFormat();
sFormat.SetAlignment(textAlign);
sFormat.SetLineAlignment(lineAlign);
SolidBrush a_solidBrush(Color(255, 0, 255, 0));
// Set text to display
wchar_t buf[20+1] = { 0 };
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lineText.c_str(), (int)lineText.length(), buf, 20);
// Draw the text
pGraphics->DrawString(buf, -1, &font_big, lineRect, &sFormat, &a_solidBrush);
}
}
Even if I make the s_solidbrush public, it still does not work.
|
|
|
|
|
is this...
[CODE]
// .h file
class CduLine
{
static SolidBrush s_solidBrush;
...
};
actually this? (what is the CduLine class?)
[CODE]
// .h file
class DisplayLine
{
static SolidBrush s_solidBrush;
...
};
In CPP file, outside of any function...
SolidBrush DisplayLine::s_solidBrush(Color(255, 0, 255, 0));
|
|
|
|
|
Yes... My mistake... I was changing names to make things clear.
the definition is at the top of the file outside of any functions.
|
|
|
|
|
Geez at least SetColor should have worked
Beats me but I'll keep looking at it...I would expect it to work!
Mark
|
|
|
|
|
by my understanding of what i've found in msdn the folowing code should redirect the output of "ping www.google.com" to a file...and well...it doesn't. Where did i go wrong?
STARTUPINFO StartupInfo;
PROCESS_INFORMATION ProcessInfo;
ULONG rc;
HANDLE hFakeStdOut = CreateFile(
"C:\\myfile.txt",
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL
);
if(hFakeStdOut==INVALID_HANDLE_VALUE)
{
printf("CreateFile failed with %d\n",GetLastError());
return;
}
memset(&StartupInfo, 0, sizeof(StartupInfo));
StartupInfo.cb = sizeof(STARTUPINFO);
StartupInfo.dwFlags = STARTF_USESTDHANDLES;
StartupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
StartupInfo.hStdOutput = hFakeStdOut;//GetStdHandle(STD_OUTPUT_HANDLE);
StartupInfo.hStdError = hFakeStdOut;//GetStdHandle(STD_ERROR_HANDLE);
char sCurDir[1023];
GetCurrentDirectory(1023,sCurDir);
if (!CreateProcess( NULL,
"ping www.google.com",
NULL,
NULL,
TRUE,
NULL,
NULL,
NULL,
&StartupInfo,
&ProcessInfo))
{
printf("Failed with %d\n",GetLastError());
}
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
if(!GetExitCodeProcess(ProcessInfo.hProcess, &rc))
rc = 0;
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(hFakeStdOut);
I've been reading about this for about an hour now and i can't get it. Please help
|
|
|
|
|
eusto wrote: if (!CreateProcess( NULL,
"ping www.google.com",
NULL,
NULL,
TRUE,
NULL,
NULL,
NULL,
&StartupInfo,
&ProcessInfo))
{
printf("Failed with %d\n",GetLastError());
}
I think that you should specify the full path to ping.exe (always a good habit, ask any *nix person, it prevents a command hijack), and put that path into the first parameter. Put the parameters to ping.exe (www.google.com) as the second parameter and see if that works.
I have had situations in the past where specifying everything as the command line fails, but breaking them up works. Dunno why, but try it.
Also, did you try using pipes as suggested in the MSDN article located at http://msdn.microsoft.com/library/en-us/dllproc/base/creating_a_child_process_with_redirected_input_and_output.asp[^]? Maybe it works with pipes but not with normal files? I would get the pipes version working first.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Thanks but the full path is not the problem. Braking the args and actual module name did not work either.
This sucks msdn says that a handle can be anything that supports Read() and Write() so a hadle to a file created by CreateFile shoul work. I realy don't get it
|
|
|
|
|
The handle needs to be inheritable:
try
SECURITY_ATTRIBUTES SecurityAttributes;
SecurityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
SecurityAttributes.lpSecurityDescriptor = NULL;
SecurityAttributes.bInheritHandle = TRUE;
HANDLE hFakeStdOut = CreateFile(
"C:\\myfile.txt",
GENERIC_WRITE,
FILE_SHARE_WRITE,
&SecurityAttributes,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL
);
|
|
|
|
|