|
Dear all,
I have created a process and wait for it to complete a certain job. e.g. "Driver Installation".
When the driver installs, it will request the user to re-start (or skip) your PC. If you choose not to re-start your PC; the main process will continue the incomplete job. On the contrary, if you choose to re-start the PC, the system will cause “Circular Wait”. Because the process informs main process whether the session is ending. In this case- how should I know if the process shows that I need to re-start the computer? If the main process has received the reboot message and then just go to leave.
SHELLEXECUTEINFO ExecuteInfoDriver;
memset(&ExecuteInfoDriver, 0, sizeof(ExecuteInfoDriver));
LPCTSTR lpctDriverPath = (LPCTSTR)DriverPath;
ExecuteInfoDriver.cbSize = sizeof(ExecuteInfoDriver);
ExecuteInfoDriver.fMask = SEE_MASK_NOCLOSEPROCESS;
ExecuteInfoDriver.hwnd = 0;
ExecuteInfoDriver.lpVerb = "open";
ExecuteInfoDriver.lpFile = lpctDriverPath;
ExecuteInfoDriver.lpParameters = NULL;
ExecuteInfoDriver.lpDirectory = 0;
ExecuteInfoDriver.nShow = SW_SHOW;
ExecuteInfoDriver.hInstApp = 0;
......
if (::ShellExecuteEx(&ExecuteInfoDriver))
{
hDriverProcess = ExecuteInfoDriver.hProcess;
if (hDriverProcess != NULL)
{
::WaitForSingleObject(hDriverProcess, INFINITE);
::CloseHandle(hDriverProcess);
}
}
....
do something...
....
Thanks for your help, I really appreciate it.
Best Regards
Steve Chang.
|
|
|
|
|
Hi ,
I was trying to compile a DirectShow sample called the MultiVMR9 from the DirectShow SDK samples,
and I'm getting the following compile error message. Does anyknow how to get around this? or what I'm doing wrong here ?
I'm using VS.NET 2003
Thanks in advance.
g:\Program Files\Microsoft Platform SDK\Samples\Multimedia\DirectShow\Samples\C++\DirectShow\VMR9\MultiVMR9\MultiPlayer\VMR9Subgraph.cpp(78): error C2065: 'CLSID_VideoMixingRenderer9' : undeclared identifier
g:\Program Files\Microsoft Platform SDK\Samples\Multimedia\DirectShow\Samples\C++\DirectShow\VMR9\MultiVMR9\MultiPlayer\MultiPlayer.cpp(55): error C2065: 'CLSID_VideoMixingRenderer9' : undeclared identifier
-Cindy
|
|
|
|
|
the Operation System is Win NT/XP
i want to write a print preview and setup program, i've fount in msdn library,
I get the DEVMODE structure,and modify the dmFormName Field to my own FormName(which have been use AddForm() to insert into to system),but why my program cant work out ,can anybody give me some tips?
|
|
|
|
|
Hello, i need help in my project based on content based image retrieval system where i will have to extract shape from sketches submitted by the user n compare it to other images...i am actually searching for code in VC++ for shape matching(fourier,grid-based descriptor,etc) n also code to detect geometric shape like circle,triangle,ect...plz help me..thx u in advance
Yesha
|
|
|
|
|
hello
what do I do if I want to print a string like this:
("how")
with fprintf
because if I do this fprintf(stream,"("how")");
it gives me compiler errors??
|
|
|
|
|
In C/C++, the backslash \ is the escape. So, you'd do this:
fprintf(stream, "(\"how\")");
|
|
|
|
|
How would i write a trim(char *str) function??
|
|
|
|
|
run through the string from the start, find the first non-whitespace. run through it from the end, find the last whitespace. the result is everything between those two points.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
|
example:
output:
Enter a sentence and I will strip out all spaces.
this is a test of the emergency broadcast system
Your sentence without spaces (8) is:
this.is.a.test.of.the.emergency.broadcast.system
code:
int stripWhite(char *str)
{
int len=0; // number of spaces
char *ptr = str;
int pos = 0;
while(*ptr)
{
if (isspace(*ptr))
{
len++;
*ptr = '.';
}
ptr++; pos++;
}
return len;
}
so i want to take all spaces out of a string instead of what i do now (replace with '.' so the string is:
thisisatestoftheemergencybroadcastsystem
how?
|
|
|
|
|
use ::strcpy to copy the rest of the string from that position down one. Make sure you copy the null at the end as well.
Christian Graus - Microsoft MVP - C++
-- modified at 23:21 Thursday 22nd September, 2005
Here's a solution:
#include "stdafx.h"
#include <iostream>
using namespace std;
size_t trim(char * str)
{
size_t len = ::strlen(str);
for(size_t i =0; i < len; ++i)
{
if (::isspace(str[i]))
{
::strcpy(&str[i], &str[i+1]);
-- len;
}
}
return len;
}
int _tmain(int argc, _TCHAR* argv[])
{
char * str1 = new char[200];
strcpy(str1, " This is a test of the veracity of my system..... ");
cout << strlen(str1);
cout << trim(str1);
cout << str1;
cin >> str1;
return 0;
}
|
|
|
|
|
Christian Graus wrote:
::strcpy(&str[i], &str[i+1]);
That will probably work, but depends on the compiler implementation. From the remarks on strcpy documentation[^]:
"The behavior of strcpy is undefined if the source and destination strings overlap."
Here's an alternative, which doesn't use strcpy , and in which each character is copied only once. How and why this works is left as an exercise to the original poster.
size_t strip_white(_TCHAR* str)
{
_TCHAR* p = str;
_TCHAR* q = str;
while (*q)
{
if (::_istspace(*q))
q++;
else
{
if (p != q)
*p = *q;
p++; q++;
}
}
*p = '\0';
return p - str;
}
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
I started with something like this, then decided it was bloat, easily replaced by strcpy. I guess I should have looked a little closer. Is memcpy the same ?
|
|
|
|
|
Christian Graus wrote:
I started with something like this, then decided it was bloat, easily replaced by strcpy. I guess I should have looked a little closer. Is memcpy the same ?
Yes, memcpy is also undefined for overlapping buffers. You could use memmove , though, which does support overlaps.
However, an additional problem in that solution is one of efficiency. Since for each space found you copy the remainder string, many characters are copied multiple times. In you example, which used " This is a test of the veracity of my system..... " as input, which is a short 50 bytes string, the following substrings were copied:
"This is a test of the veracity of my system..... " = 49 bytes
"is a test of the veracity of my system..... " = 44 bytes
"a test of the veracity of my system..... " = 41 bytes
"test of the veracity of my system..... " = 39 bytes
"of the veracity of my system..... " = 34 bytes
"the veracity of my system..... " = 31 bytes
"veracity of my system..... " = 27 bytes
"of my system..... " = 18 bytes
"my system..... " = 15 bytes
"system..... " = 12 bytes
In total, 310 characters were copied. In the alternative solution, each character of the final result was copied only once, that is, only 39 single-byte copy operations were performed. 310 is almost 8 times 39, and to make things worse, the proportion will grow exponentially for larger strings. For example, if we used as input the same string concatenated to the original one (a 100 bytes string), one algorithm would perform 78 byte copy operations, while the other would do 1120, which is more than 14 times larger. If we used as input three times the original string (150 bytes), the numbers would then be 117 bytes copied in one algorithm against 2430 in the other, which is more than 20 times larger!
Using while (*q) instead of the strlen + for combination is an additional optimization, because you don't need to traverse the whole [potentially long] string just to find out its length. Using while , all the processing can be done in a single pass.
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Hi guys ,
i have next question :
what will the output be of this program?
...
char* foo()
{
char *c = "this is a test";
return c;
}
char* foo1()
{
char c[] = "this is a test";
return c;
}
int _tmain(int argc, _TCHAR* argv[])
{
...
char p1 = foo1();
char p = foo();
cout<<p1<<endl;
cout<<p;
return 0;
...
}
i dont get it. i thought that the output of foo() and foo1() had to be the same . more exactly foo1() had to print some strange symbols as the memory allocated for c[] would be freed after this funcion ended. but why does not the sane happen with c* in foo()?
what am i getting wrong??
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
-- modified at 17:48 Thursday 22nd September, 2005
|
|
|
|
|
Giorgi Moniava wrote:
char c[] = "this is a test";
Because it's an array, this memory is allocated in to context of the function, and lost when you return.
Giorgi Moniava wrote:
char *c = "this is a test";
Because it's a pointer, this memory is not freed, and so is a leak, unless the caller deletes it.
In both cases, you'd do better to return std::string. ( Yes, I realise this is an experiment, but that's the lesson to learn from it )
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote:
Because it's a pointer, this memory is not freed, and so is a leak, unless the caller deletes it.
Nom you don't have to (and you shouldn't) delete this memory, otherwise you will get an assertion. This memory has not been dynamically allocated so it shouldn't be deleted by the user. The two cases are the same. No memory has been dynamically allocated so everything will be freed at the end of the function.
Christian Graus wrote:
In both cases, you'd do better to return std::string
So true
|
|
|
|
|
Both returned adresses point to memory that has been freed. So you cannot predict what will be the contents of these adresses. Maybe it is still good (if nothing erased it), maybe it is totally wrong. In your case, if the contents of p are still good and not those of p1, it's probably due to the fact that after calling foo(), you don't allocate extra memory. As a test, you could just reverse the calls of the function and check the results:
char p = foo(); <br />
char p1 = foo1();
|
|
|
|
|
char *c="This is a test"
here c points to the constant string "This is a test" which, presumably, resides somewhere in the constant or text section of the executable image. This pointer will always be valid independent of scope. Of course, it's bad programming practise that will easily give you problems, but c actually points to valid memory upon return from foo(), and this memory will never be freed (and won't have to be).
Of course, it's a totally different situation with char c[]="This is a test" . Here a copy of the constant string is made, and the copy (c[]) goes out of scope, is freed (well, the stack space is reclaimed) and lost in cyberspace. That's why foo1() doesn't work.
I wonder what would happen if c[] was declared const? Would the compiler make an actual copy or just let c point to the constant string "This is a test"? Since c is declared to point to constant memory I can easily imagine that the optimiser would do this.
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
Steen Krogsgaard wrote:
I wonder what would happen if c[] was declared const? Would the compiler make an actual copy or just let c point to the constant string "This is a test"? Since c is declared to point to constant memory I can easily imagine that the optimiser would do this.
Hi Steen,
thanks for reply,
the same is happening when i declare c[] as a const
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
|
|
|
|
|
So, apparently the compiler still makes a copy. Anyway it's not significant, the point is that your pointer version is valid (but bad design in my mind) and the array version is not. The reason for this is as I have described previously.
Just out of curiosity, did you try the const-array version in both debug and release mode? I would guess that in debug you would still see problems, but in release mode it might work. But it's still a bad idea
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
Yes Steen i agree that it is bad design , i was just experimenting.
Steen Krogsgaard wrote:
Just out of curiosity, did you try the const-array version in both debug and release mode? I would guess that in debug you would still see problems, but in release mode it might work. But it's still a bad idea
Yep , and the result is the same in both Debug and Release Builds
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
|
|
|
|
|
cedric moonen wrote:
Both returned adresses point to memory that has been freed.
I also knew this and thats why i expected that the output of foo() and foo1() had to be the same.
cedric moonen wrote:
As a test, you could just reverse the calls of the function and check the results:
i've done it already but result is the same.
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
|
|
|
|
|
how many times are you going to ask the same question ?
Yesterday[^], DavidCrow And Nishant Sivakumar already gave you some efficient enough answers...
what are you looking for man ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
-- modified at 4:27 Friday 23rd September, 2005
|
|
|
|
|
toxcct wrote:
how many times are you going to ask the same question ?
Yesterday[^], DavidCrow And Nishant Sivakumar already gave you some efficient enough answers...
what are you looking for man ?
Loo well at the question i asked yesterday and at this question .
I'm sure you will find difference
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
|
|
|
|
|