|
Because it's not a variable definition, it's a cast.
|
|
|
|
|
the first one is operation called 'casting' - looking to the same thing in a different way - e.g. when one object is derived from some base and you have a pointer to that object, you can cast it to be the pointer to the base and use methods from the base class, but still using the same instance of object.
The second constructs creates a new uninitialized pointer to CTestDoc.
|
|
|
|
|
(CTestDoc*)m_pDocument; //this is type cast
CTestDoc* m_pDocument; //this declares a variable
Consider this:
void* GetDocument(); //function declaration -> notice it returns a void*
CTestDoc* m_pDocument; //declare a variable of type CTestDoc*
m_pDocument = (CTestDoc*) GetDocument(); //Call the function. Notice how the result is cast using (CTestDoc*). A void* would not fit into the m_pDocument variable of type CTestDoc*. Hence it is cast using (CTestDoc*).
XP
|
|
|
|
|
Hi all
is this Casting?
(void *) TNptr;
|
|
|
|
|
yes, it casts TNptr into a void* pointer ( generic pointer).
Maximilien Lincourt
"Never underestimate the bandwidth of a station wagon filled with backup tapes." ("Computer Networks" by Andrew S Tannenbaum )
|
|
|
|
|
It may help to point out that casting usually occurs on the right hand side of the assignment operator (=). Casting means "make this variable look like...". So if the compiler encountered statements like this, it would complain about the invalid assignment to pFoo :
CBar aBarObject;
CFoo* pFoo = &aBarObject;
But if you made &aBarObject look like a pointer to a CFoo (for the purpose of the assignment), all would be well. As in:
CBar aBarObject;
CFoo* pFoo = (CFoo *) &aBarObject;
Hope this helps.
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
I’m writing telnet program. All chars I get from client socket (except telnet commands of course) I pass to command.com/cmd.exe (running in separate process).
Problem is: when client passes “regedit.exe” for instance – it is run on server machine ( !!) which is not what I intended …..
So the question is: HOW to protect from running GUI programs by my command interpreter?
(I’m pretty sure it can be done ... in pure DOS you can see the message “This program can not be run in DOS mode … this is what I want)
Please HELP
|
|
|
|
|
You mean you're writing a telnet _server_.
But anyway, that's not necessarily a bad thing to run windows apps. For remote administration I find it useful to run, for example, "shutdown.exe /l /r /c /y /t:60" from the NT Reskit via telnet or remote shell, which I believe is a non-console app.
|
|
|
|
|
No, it cannot be done, at least not in a simple way.
There is no "pure DOS" in the modern Windows. cdm.exe executes both Windows and DOS programs.
As far as I know the only way to distinguish between a Win32 console (DOS-like) and Win32 GUI executable is to follow its WinAPI function calls AFTER it was executed or to perform a kind of reverse engineering to know which DLLs and functions supposed to be used by this executable.
Another way (not suitable but still) is to enumerate all windows in the executed process and detect the console window.
--
Best Regards,
Andrew
|
|
|
|
|
If you have control over which programs are run (ie. it's not by cmd.exe ), then you can read the subsystem from the .EXE file header to determine if it's a GUI program or a console program before you run it. I don't have time to go into the specifics here, but look up the PE file format on MSDN.
Hope this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hello, everyone!
I find even if I use signal(SIGCLD,SIG_IGN), I can not prevent
child process from becoming zombie process. I have used ps -aux
to check the result.
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
int main(void)
{
pid_t pid;
signal(SIGCLD,SIG_IGN);
pid = fork();
if(pid)
{
sleep(20); // parent sleep
}
else //child exit
{
exit(1);
}
return 1;
}
Can anyone help?
Thanks in advance,
George
|
|
|
|
|
The result of signal (SIGCLD, SIG_IGN) varies depending on the system. A better solution is to use 'sigaction' with the SA_NOCLDWAIT flag - this stops a child sending the SIGCLD signal in the first place, and works on all systems (as far as Im aware). 'sigaction' is also more preferred to signal, so its worth looking into it more
|
|
|
|
|
Thanks, Johnny buddy!
Can 'sigaction' also prevent a child process from becoming zombie process?
Can you show me a simple example?
regards,
George
|
|
|
|
|
Yes, the SA_NOCLDSTOP flag means that no signal will be raised by the child when it stops, and this should be consistent across different flavours of Unix (check the man page to be sure - it should have been in Linux for several years now)
Its more work to setup, but its a lot more powerful version of signal. You can use it like this:
sigaction sig;<br />
<br />
sigemptyset (&sig);<br />
sig.sa_flags = SA_NOCLDSTOP;<br />
sig.sa_handler = SIG_IGN;<br />
<br />
sigaction (SIGCHLD, &sig, NULL);
|
|
|
|
|
Thanks, Johnny buddy!
I have tried your code, but it does not work. Here is all my sample
code,
Source code:
--------
#include <signal.h>
#include <sys types.h="">
#include <unistd.h>
int main(void)
{
struct sigaction sig;
pid_t pid;
sigemptyset (&sig);
sig.sa_flags = SA_NOCLDSTOP;
sig.sa_handler = SIG_IGN;
sigaction (SIGCHLD, &sig, NULL);
//signal(SIGCLD,SIG_IGN);
pid = fork();
if(pid)
{
sleep(20); // parent sleep
}
else //child exit
{
exit(1);
}
return 1;
}
--------
Here is what I noticed from ps - aux during the running time of the process,
Output:
--------
root 10914 0.0 0.1 1372 280 pts/0 S 19:47 0:00 ./SigZombie
root 10915 0.0 0.0 0 0 pts/0 Z 19:47 0:00 [SigZombie
|
|
|
|
|
The above will work on Solaris, but I have not tried it on Linux. Rather than go to all this hassle of trying to avoid dealing with the SIGCHLD I think the easiest thing is going to be actually handle the signal and call waitpid on the child. Not only will this stop zombies, but its the cleanest and most portable, and you can get all sorts of information back from the child (esp if you use sigaction).
|
|
|
|
|
Thanks, for your advice Johnny buddy!
Thanks, Johnny buddy!
What do you mean "will work"? Do you mean you can not see "defunc" process from "ps -aux"?
I have referenced some materials, and write a sample from your idea, but it does not work. (still can see "defunc" process from "ps -aux")
Source Code:
--------
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
int main(void)
{
struct sigaction sig;
pid_t pid;
sigemptyset (&sig.sa_mask);
sig.sa_flags = SA_NOCLDSTOP;
sig.sa_handler = SIG_IGN;
sigaction (SIGCHLD, &sig, NULL);
//signal(SIGCLD,SIG_IGN);
pid = fork();
if(pid)
{
sleep(20); // parent sleep
}
else //child exit
{
exit(1);
}
return 1;
}
--------
Can you help?
regards,
George
|
|
|
|
|
hi there..
thanks for your time firstly..
i am having a strange problem in the invoke of my IDispatch..
This method is called from the get property of an aX control.
When i call this get method, i dont seem to get any return vaule in the pvarresult variable..
any suggestions..
here is the method:
double CControl:: GetNumber(long nRow, long nCol)
{
DISPPARAMS DispParam1;
EXCEPINFO excep;
UINT nArgErr;
VARIANT pVarResult;
double temp;
DispParam1.cArgs = 2; //number of arguments
DispParam1.cNamedArgs = 0;// Number of named arguments.
DispParam1.rgvarg = new VARIANTARG[2];
DispParam1.rgvarg->vt = VT_ARRAY;
DispParam1.rgvarg[1].vt = VT_I4;
DispParam1.rgvarg[1].lVal = nRow;
DispParam1.rgvarg[0].vt = VT_I4;
DispParam1.rgvarg[0].lVal = nCol;
IImpl::Invoke(DISPID_Number , IID_NULL , 0 , DISPATCH_PROPERTYGET, &DispParam1, &pVarResult , &excep, &nArgErr);
temp = pVarResult.dblVal;
//delete [] DispParam1.rgvarg;
return temp;
}
|
|
|
|
|
try to VariantInit the result variant.
VariantInit( &pVarResult );
this can help (and if not, it's anyway better)
|
|
|
|
|
thanks
kindest regards
|
|
|
|
|
Hello
I'm developing my own controls library and want to implement Office XP menu support, but there is a promblem: I don't know how to calculate appropriate colors. I took a look at ProfUIS, GuiLib, CMenuXP and few other libraries and controls and everybody calculate colors in his own way, but in wrong way. Such applications as SmartFTP, ASP.NET Web Matrix, PHP Expert Editor, etc does the same.
Only one library calculate correct colors. It is Xtreme Toolkit by Codejock Software.
Can anybody help me?
__________________________________________________
Best regards,
v0id
|
|
|
|
|
If the xp colors work and they have no trouble in errors or anything else and are pretty efficient then it really doesn't matter if you use the classes or not. Just first get their permission to use their code and ideas.
[It is possible to represent everything in this universe by using 0 and 1]
I'm going to live forever or die trying.
|
|
|
|
|
I'm new in the programming for Windows (but have few year expirence in programming for Unix).
My app will be work with unlimit number of grouped object. Each object consists of predefined number of text fields and unlimited number of accociated binary objects.
The database will support only one client/database builder.
I can build the db by simply creating directory structure but is there any solution to do this by using Access datafiles of something like that?
|
|
|
|
|
Have a look a this link [^].
// Afterall, I realized that even my comment lines have bugs
When one cannot invent, one must at least improve (in bed).-My latest fortune cookie
|
|
|
|
|
Mastering MFC Development Using Microsoft Visual C++ 6
Chapter 7: Using OLE DB Templates for Data Access
Chapter 8: Creating ADO Database Applications
M$PRESS
|
|
|
|