|
<br />
TCHAR lpszPath[MAX_PATH] = {0};<br />
DWORD dwResult = ::GetModuleFileName(AfxGetInstanceHandle(), lpszPath, MAX_PATH);<br />
That should do the trick
|
|
|
|
|
Try looking into GetModuleFileName(...) . Despite the name, it returns a fully qualified path.
Peace!
[EDIT] Hmmm... Guess I should refresh more often...! [/EDIT]
-=- 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! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites
|
|
|
|
|
Hello,
I have a problem with the combo box in the CGridCtrl. I set an options list and I don't get a default selection. Also when I do select an item, the selection goes away when I select an other cell or control...
Do I need to do something special to get a default selection or to get the new selection visible?
Thanks in advance,
Bob
|
|
|
|
|
Hi,
Can you please get me the answers for the following questions
1. VTABLE lies in what part of the memory? Isit in Stack, Heap or Datasegment?
Is VTABLE created at compile time or at runtime?
2. Whats the exact diff. between Abstraction and encapsulation?
3. There is base and derived class, Say there is a virtual fn Draw() in the Base class and its not overrided in the derived class. Now the object for the derived class is created and stored in the base class pointer. Now call the Draw() fn via the base class pointer. The base class Draw() is called as there is no implementation in the derived class.
Internally, two VTABLEs are created one for base and other for derived class. How internally the compiler calls the base class Draw() fn. How does this work wrt the VTABLE?
4. Where class member fn are stored in memory and how the compiler makes a call to these member fns?
5. What are the things the parent and child thread doesn't share?
6. Say, char* pstr = "Helloworld";
Now reverse the string pstr without using any temp variable? When we cout the pstr it should Helloworld should be reversed?
Thanks in advance.
sarathymail
|
|
|
|
|
psmail wrote:
Can you please get me the answers for the following questions
This smells of homework.
psmail wrote:
6. Say, char* pstr = "Helloworld";
Now reverse the string pstr without using any temp variable? When we cout the pstr it should Helloworld should be reversed?
Ue strrev() .
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
DavidCrow wrote:
This smells of homework.
Hmmm... you're right, I didn't see that. Anyway, all the implementation of virtual functions stuff is compiler dependent IIRC, so it's only valid for VC++
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"
|
|
|
|
|
psmail wrote:
1. VTABLE lies in what part of the memory? Isit in Stack, Heap or Datasegment?
Is VTABLE created at compile time or at runtime?
I'm not sure, but since it's function pointers it makes most sense to me that it is in the code segment. Its definitely not in stack or heap. The vtable is created at compile time, as there is only one vtable per class, and this vtable is shared by all instances of that class
psmail wrote:
2. Whats the exact diff. between Abstraction and encapsulation?
Abstraction is an "is-kind-of" situtation, encapsulation is an "is-made-of". For instance, a luxury car "is-kind-of" car, as is compact car, but car "is-made-of" four wheels, not "is-kind-of" four wheels. Does that make any sense?
psmail wrote:
Internally, two VTABLEs are created one for base and other for derived class. How internally the compiler calls the base class Draw() fn. How does this work wrt the VTABLE
IIRC the vtable for the derived class contains all the vtable entries from the base class. If a virtual function is overriden in the derived class the function pointer in the corresponding slot in the vtable of the derived class is substituted to point to the overriden version of the funcion.
psmail wrote:
4. Where class member fn are stored in memory and how the compiler makes a call to these member fns?
If you mean non-virtual functions then they are stored in the code segment. The compiler/linker resolves the address of these functions during compilation/linking. So when a method invocation is compiled, the compiler marks the spot in the code where the address of the called method is to be put. The linker then finds all these marks and substitute them with the actual address of the method. It's all done pre-runtime.
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'm not sure, but since it's function pointers it makes most sense to me that it is in the code segment. Its definitely not in stack or heap. The vtable is created at compile time, as there is only one vtable per class, and this vtable is shared by all instances of that class
Don't take it personally, but that's not quite right
The vtable is part of an object - each object has its own copy. It is stored as part of the object's data, and is initialised as part of the object's construction, before the constructor is called (disassemble the constructor code to see where). It's initialised by copying the data verbatim from its class's class-specific vtable.
The reason it's got its own copy is so that virtual functions work. Take the following code:
void myFunc(MyBaseObject* objPtr)
{
objPtr->myVirtualFunction();
}<br/><br/>myFunc(new MyDerivedObject); If the vtable was per class, then this wouldn't work. When myVirtualFunction was invoked, the compiler would have to know what type of object objPtr was so it could invoke the correct implementation of the function. Since the whole point of polymorphism is that compiler doesn't have to know what type of object it's got, this simply will not work. If the vtable is per-object, all the compiler has to do is lookup in the object's vtable the function pointer using the correct table index and call it. The compiler has to make sure that each implementation of a virtual function is given the same index into the table for all the classes derived from the same base class. So in essence, this call translates to something like:
(*objPtr->vtable[myVirtualFunctionVTABLEindex])() Hopefully that clears things up a little
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"
|
|
|
|
|
Ryan Binns wrote:
Don't take it personally, but that's not quite right
Unfortunately I'm quite sure I'm right (although being so sure of one self always comes with the risk of making a complete fool of one self by actually being wrong )
Look at MSDN, "C++: Under the Hood" by Jan Gray (it's from 1994 and in my October 2001 version of MSDN, but I believe it's still holds true). Each object contains a pointer to the vtable, but not the vtable itself. This pointer is used at runtime to look up the adress of the virtual function.
It wouldn't make much sense to have a per-instantiation vtable. Two objects of the same type will per definition have the same vtable (otherwise they would not be of the same type). What polymorphism does is to allow you to delay the linking so that you don't have to know the exact type of the object in order to call functions on it. However, the compiler will have to know what index in the vtable to use at compile time, that's why the base class vtable entries preceeds the derived class vtable entries. And that's why multiple inheritance is such a mess!
This is of course compiler-implementation dependent, but I'm pretty sure that the above holds true for VC++.
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"
|
|
|
|
|
Aaaah, I've been fooled by MS' double indirection :P. My fatal assumption was that VC++ would be basically the same as other compilers
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"
|
|
|
|
|
Allright.
Are you absolutely sure that other compilers make a copy of the vtable for each instantiated object? It seems such a waste of resources. Imagine having a class with 25 virutal methods, thats 100 bytes for each vtable, and having objects of this class in a large array, say 10000 objects, thats 1MB just for vtables - and identical vtables, I might add. From what I've been able to dig out with Google, GCC also uses pointers to vtables, and this reference http://www.awprofessional.com/articles/article.asp?p=26063&seqNum=3[^] states that not only all C++ compilers, but all compilers for all languages using virtual functions are implemented with at pointer to the vtable in the object. Do you have any references for compilers that use the one-vtable-per-object model? I'm just curious!
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"
|
|
|
|
|
|
Hi all,
My application has two classes (class A and class B), both of them are CDialog class and have message handling capability. Now, I want to write code in class A to ask class B to run its function(RunTimer) which run SetTimer() function to do actions periodically.
My idea is here.
In class A cpp file, I have:
ClassB myclassb;
void test()
{
myclassb.RunTimer();
}
In class B cpp file, I have:
void RunTimer()
{
SetTimer(1000, 3000, NULL);
}
I can compile my program. However, when I run my program, I get exeption error. Is it my idea is wrong? How can I ask class B to handle message?
Thanks
|
|
|
|
|
The first solution that comes to mind is enable Class B to handle user defined messages. This would enable Class A, or any other window for that matter, to send instruction messages to Class B, such as activating the dialogue's timer function.
The only concern is the modality of your dialogues. I have used this method flawlessly in modeless dialog, but I'm not sure how it would work in a modal dialog, since the blocking mechanism my interfare with the sent messages. Maybe someone could verify if this method still works for modal dialogues.
Joseph Newcomer's excellent essay[^] on window messages is a must read.
I Dream of Absolute Zero
|
|
|
|
|
I have a table represented by a control CListCtrl. I want to merge all cells from a specific row and to insert in the new created cell a text. If anybody knows a solution please tell me. Thanks.
BujCat
|
|
|
|
|
Here's my thought "from the hip"...
Loop through all the "SubItems" of a particular "Item" .appending() each sub-item's text to a CString. Now you have your merged text.
If you want to create a new column (not sure what you mean by "cell"), then you'll have to CListCtrl.InsertColumn(), and then redraw the control.
Hope this helps you find the MSDN references you'll need.
thanks,
JennyP
|
|
|
|
|
I have defined "cell" the intersection between a row and a column. My list control have a black grid between cells.
I don't know if you understand me. I want to merge all cells from a row(to merge all columns) and to insert a CString in this row.
I try a lot but I don't have resolved the problem yet
Thanks
BujCat
|
|
|
|
|
Hi everybody,
I have a problem, which I could not solve myself and I hope somebody has made some experiences with CMetaFileDC. First of all: My Code works on onscreen-DCs and what comes out of my printer looks exactly as I want. My only problem is rendering a metafile to a print-preview-DC. The result is always way to large and does not fit the page. It seems that the preview-dc behaves like a printing-dc and PlayMetaFile ignores that.
Some example code (like mine but without unnecessary details):
<br />
CSize ext(cx, cy);<br />
pDC->DPtoHIMETRIC(&ext);<br />
CMetaFileDC mdc;<br />
mdc.CreateEnhanced(pDC, 0, CRect(CPoint(0, 0), ext), 0);<br />
<br />
drawObjects(mdc);<br />
<br />
ext.SetSize(pDC->GetDeviceCaps(PHYSICALWIDTH) - 2 * pDC->GetDeviceCaps(PHYSICALOFFSETX),<br />
pDC->GetDeviceCaps(PHYSICALHEIGHT) - 2 * pDC->GetDeviceCaps(PHYSICALOFFSETY));<br />
<br />
HENHMETAFILE hMf = mdc.CloseEnhanced();<br />
CRect bounds(CPoint(0, 0), ext);<br />
pDC->SaveDC();<br />
pDC->SetMapMode(MM_ANISOTROPIC);<br />
pDC->PlayMetaFile(hMf, &bounds);<br />
pDC->RestoreDC(-1);<br />
<br />
DeleteEnhMetaFile(hMf);<br />
If necessary I can make some screenshots of that effect.
Thanks for reading ,
Christian
|
|
|
|
|
Hmmm, i tried to render the metafile to an offscreen-dc and then BitBlt it to the preview-dc. Same effect. I have no idea what to do...
|
|
|
|
|
How do I export a class written in C++ to a VB project?? How do my VB declare and use this class??
|
|
|
|
|
CLASS .
Exporting Function from C++ DLL is easy but for exporting CLASS you have to create COM DLL ,as i think soo.
"I Think this Will Help"
[Vote One Here,.....]
<h5
alok gupta="" <br=""> visit me at http://www.thisisalok.tk
|
|
|
|
|
is there any way to append a CString [] to another CString [], can anybody help me?
thanks to all.
|
|
|
|
|
|
CString behaves much like a normal C++ string, hence
you can use:
CString strHello = "Hello";
CString strThere = " There";
CString strAppend = strHello + strThere;
Is that what you had in mind?
Cheers,
David
|
|
|
|
|
how can i validate date input from user, i accepts that date in to a CEdit derived control, i want to check whether the user enter the in right format or not ( my required format is DD/MM/YY). any idea ?
Thanks in advance
Ninety-eight percent of the thrill comes from knowing that the thing you designed works, and works almost the way you expected it would. If that happens, part of you is in that machine.
|
|
|
|