|
Since you say you're new at VC++, what follows may make little sense to you, but hopefully you'll grasp the idea soon.
If you're into OOP, many objects will be derived from a common base. Usually, a piece of code uses such object without really knowing the particular class they belong to (only that they're derived from the base). In this situation, passing by value (without pointers) is impossible, since the code won't know in advance how much space will take the object (different derivations can have more or less members not belonging to the base), so no copying around can be performed. I this case, the only solution is to pass to the unknowing code a pointer to the actual location of the object, so preventing copying.
In Java and C# the situation is the same, but the language hides this to you by making implicitly every object variable a pointer to an object --so these languages have pointers but you can't see them.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I've just read in a web site that using pointers have 3 main reasons:
Array Operations,Dynamic Memory(variable sized arrays and structs like linked lists) and Parameter Passing.I've read something about this polimorphism thing,too but i didn't understand any word
Now,are these 3 reasons enough,or is there something more?
|
|
|
|
|
It is a most bizarrely mocking fact that a lot of C++ programmers realize the worth and splendor of pointers only when they start using a language which does not support them directly.
Nish
The posting stats are now in PDF:-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
Updated - May 04th, Saturday
|
|
|
|
|
Some people call C++ the mid-level language. What does "mid-level" mean? Not as high level as Java or VB is (everything you need is just out there: Java has Virtual Machine, and the VB development tool does a lot of things for programmers. ); and not as low level as assembly language is (push, mov, eax, ..... ).
As sort of mid-level language, C++ covers both features of high and low ones. C++ is a structured language and uses 47 ( +1 : 'typename' ) English keywords, and the syntax is close to a certain human speach (if... else. do... while. try...throw... catch... ).
Then, what feature C++ covers as low-level one? Direct access to memory! How? With the feature of pointers, we can.
For example, if you want to set some desired value to somewhere in the memory, we may use:
int* p = (int*)0x0FCC00;
*p = 123456;
Or you can view where the variable is, you can code such:
double dMyMagicNum = 3.1415926535897932384626433832795;
printf("dMyMagicNum is at 0x%p \n", &dMyMagicNum);
There is also a trick called "Placement memory allocation".
If you had allocated some memory in the free store:
char* buf = new char[sizeof(int) * 300];
int* p = new(buf + 6) int;
printf("Buf: 0x%p, p: 0x%p\n", buf, p);
Maxwell Chen
People say "No news is good news". Then, no code is good code!?
|
|
|
|
|
I'm working with a text box (CEdit), but unfortunatly, there aren't any functions to change the text color.
I would like to know what is the easiest way to make a text box with different lines of text in different colors. There are quite some syntax coloring edit boxes out there, but they have way too many features.
Even a rich edit control (Working in a dialog) doesn't seem to support this easily. (you have to select parts of the text or something, then you can change a mask...)
Maybe it can be done with OnCtlColor, but then I can only change the text color of the entire Dialog...
Got any ideas?
|
|
|
|
|
Griffith Sutherns wrote:
Maybe it can be done with OnCtlColor, but then I can only change the text color of the entire Dialog...
Nooo!
You can check and see if nCtlColor is CTLCOLOR_EDIT if you want to change the color for every edit control or you can call GetDlgCtrlID on the pWnd which is a CWnd*, and chk if it's the specific edit control
Nish
The posting stats are now in PDF:-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
Updated - May 04th, Saturday
|
|
|
|
|
unfortunately, you'll need to use one of those syntax coloring edits, if you want to have multiple text colors in a single control. the basic CEdit only allows one color for text. it's hard to believe i know (my own syntax coloring editor implements the whole edit control thing from scratch - just to be able to color text)
there are some classes that make rich edit use easier, especially if the text is read-only. and, even better, you could use an embedded instance of an HTML browser if your text is read-only (it's really quite simple).
-c
There ain't no second chance
Against the thing with the forty eyes, girl
|
|
|
|
|
I'd solve this by using a ritchedit control, but instead of modifying the content, I'd generate some RTF (on the fly if necessary) with color codes in it and do a StreamIn.. it might sound complicated but it only takes a few lines of code and a simple callback function.
Cheers!
Marc.
|
|
|
|
|
Good idea. I'll try that
Thanks for the feedback!
|
|
|
|
|
Hi,
I need to create a program that could have the possibility of kill some exe's running ( I would send a notification to that exe's and if they don´t answer they are hanged.. so kill'em and restart them...).
The problem that I found is that I can only kill an exe if the process that wants to kill it, it´s the same the created it, ... is there another way to do that, or that is reserved to the Task Manager ?
Thanks in advance, greetings
Braulio
|
|
|
|
|
you need to have SE_DEBUG_NAME privilege, then get a Handle to the process with OpenProcess() then call TerminateProcess() to kill the process
HANDLE OpenProcess(
DWORD dwDesiredAccess, // access flag
BOOL bInheritHandle, // handle inheritance option
DWORD dwProcessId // process identifier
);
BOOL TerminateProcess(
HANDLE hProcess, // handle to the process
UINT uExitCode // exit code for the process
);
|
|
|
|
|
Thanks !
One question more, could you tell me a little bit more about the SE_DEBUG_NAME privilege ?, is a privilige that I set to my process or to other processes or... ?
Thanks a lot, greetings
Braulio
|
|
|
|
|
HANDLE hToken;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
{
if (EnablePrivilege(hToken, SE_DEBUG_NAME, TRUE))
{
.....
}
BOOL EnablePrivilege(HANDLE hToken, LPCTSTR szPrivName, BOOL fEnable)
{
TOKEN_PRIVILEGES tp;
tp.PrivilegeCount = 1;
LookupPrivilegeValue(NULL, szPrivName, &tp.Privileges[0].Luid);
tp.Privileges[0].Attributes = fEnable ? SE_PRIVILEGE_ENABLED : 0;
AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), NULL, NULL);
return((GetLastError() == ERROR_SUCCESS));
}
|
|
|
|
|
Usually killing apps is done by posting a WM_CLOSE to their main window. But I guess you want to kill non-responding apps as well.
Nish
The posting stats are now in PDF:-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
Updated - May 04th, Saturday
|
|
|
|
|
Hi Nish !
My main goal is to kill non-responding exe's apps ( well EXE com servers).
I need to have a system up and running 24 hours, and some of the exe's com server are not from my own, so if they f***ed up, my idea is to run a "trouble shooter" program that detects if the EXE server exists, if it is so, then it tries to connect if fails ( donno if this is easy to detect, glups !), then kill the EXE, or if I can connect just have a sink interface to now if it´s alive ( it would be like a "ping"), if something fails, kill the EXE...
Maybe I should use some framework for that stuff, but I feel lost with MSMQ and MTS, or the new stuff..., I don´t know if it´s only oriented for use in Web App's or...
Thanks Nish
Braulio
|
|
|
|
|
what's your program's name? (i'll make sure i never let it near my PC).
-c
There ain't no second chance
Against the thing with the forty eyes, girl
|
|
|
|
|
The name of the program is "VirusKiller.exe" XD :-P
I need it, because I will have some com EXE server that can hang, and I have not control over them ( the will be developed by third parties...), so if they crash, I want to detect it, and kill'em, and then restart the EXE server.
he he, but is not a bad idea for a Virus...
so long
Braulio
|
|
|
|
|
My main goal is to kill non-responding exe's apps ( well EXE com servers).
Then be aware there are occasions you actually can't kill them. :-<
If there's an RPC call (synchronous) that's waiting for a response, the process you want to kill is actually "hanging" inside the kernel and can't be killed. This is one of the resons COM on Windows is hated by some of us: You can't kill a hung process!
Another way to display this would be to (disregarding what the documentation states, the docs lie) create a new file, SetFilePointer to some large value (like 2GB-1), and then SetEndOfFile.
Now do this on a disk that's not using DMA to see how a user-mode process chews away almost all available CPU. Try to kill it using e.g. TaskManager. :-<
But back to your problem: this is depending on what OS you are running under (no one can ever accuse Microsoft of "stable API's" when it comes to this).
If you're using an NT kernel OS you could use the PSAPI to EnumProcesses. Then iterate that set and OpenProcess, then EnumProcessModules and finally GetModuleBaseName to get the name of the process.
If that name fits what you want to kill you then OpenProcess(PROCESS_TERMINATE, FALSE, pid), terminate that process, and finally CloseHandle on the process handle you got from OpenProcess.
Simple, wasn't it. :-/
|
|
|
|
|
Thanks for the help !
Then to control possible unstable COM EXE server what could I do ?, Should I for another solution better ?
My idea was to have a tool that would check the COM EXE servers of my system ( If I said any third party could add his owns exe servers... so I could be in trouble).
Then would be a better idea to use something like MTS or MSMQ, or some other big words technologies ? ( I wouldn´t like to say to the user... "please we have f***ed up, restart your system" ).
Thanks for you help, so long
Braulio
|
|
|
|
|
i am getting a bunch of these warning messages after my OnInitDialog() exits:
First-chance exception in 8028c.exe (KERNEL32.DLL): 0xC0000005: Access Violation.
and i have absolutely no idea why ... i traced it down into the depths of wincore.cpp and its friends but god only knows what they get up to when they're bored ... thing is my app doesn't go squiff even in release mode so i'm a wondering if its something i can ignore or should i be afraid ... very afraid
"... and so i said to him ... if it can't dance and you can't eat it either f**k it or throw it away" 8028finder.com
|
|
|
|
|
What does your code look like. It sounds like an initialization problem.
|
|
|
|
|
Do you have an ActiveX control on your dialog? I get these when I have an in-house ActiveX control in use. I think the windows system is trying to access a default function that is not present or some such. Doesn't seem to affect how my program works.
Roger Allen
Sonork 100.10016
If I had a quote, it would be a very good one.
|
|
|
|
|
I found this article in the MSDN:
INFO: First and Second Chance Exception Handling Q105675
It explains what you are seeing. There are many DLLs (and other code) that throw exceptions on purpose to see if things are valid. I have used this technique to check if memory-mapped files have real memory allocated for them. From the article, the debugger sees these exceptions before the application does. It creates a warning before a handler is able to catch the exception. Note that they must be getting handled or your application would crash.
I see them also in most of my applications and they are safe. I have written hundreds of applications and never seen these messages to be a problem.
Hope this helps...
Jonathan Craig
www.mcw-tech.com
|
|
|
|
|
awesome
thanks for the info
i wondered why my release build wasnt dying at the very least
"... and so i said to him ... if it can't dance and you can't eat it either f**k it or throw it away" 8028finder.com
|
|
|
|
|
Hi
I have created a SDI application ( with COM server option ) using the new appwizard supplied with the WTL 7.0 toolkit. After adding a ATL simple object, I tried to access the interface from VB 6 to no avail?? Has anyone played around with these options?
The code generated by VS registers the object on the ROT, but using ye old ROT/COM viewer, I cannot see my object registered on the ROT when an instance of my SDI application is running. Any ideas?
Frans
|
|
|
|
|