|
(either on VC6 and VC.net 2003 )
I have a ctreectrl on which I handle the NM_CLICK notification :
ON_NOTIFY( NM_CLICK,IDC_TREE, OnTreeClick )
and
void CMyClass::OnTreeClick( NMHDR* pNMHDR, LRESULT* pResult )
{
NMTREEVIEW* pNMTreeView = (NMTREEVIEW*)pNMHDR;
HTREEITEM hSelItem = pNMTreeView->itemNew.hItem;
}
the item returned by pNMTreeView->itemNew.hItem is invalid when I click next to a tree item; it's not NULL and it's not a valid HTREEITEM.
Is it valid to use that or do I need to do something else ( like CTreeCtrl::GetSelectedItem ) ?
Thanks.
Max.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
|
I want to know when does "Pure Virtual Function Call" occurs? I am getting this problem in my code and unable to find out.
Note: I am not calling a pure vitual function in my base class constructor. So this error is not due to calling a pure virtual function from a base class constructor.
+
My application is a multithreaded application.
I wanna know the conceptual reasons behind other cases in which pure virtual function call can occur.
Thanks
Muhammad Shoaib Khan
http://geocities.com/lansolution
|
|
|
|
|
I have no idea what you are asking. Could you be more specific in describing your problem?
What do you mean, when does it occur? It occurs when someone types in the function call from another function and runs the program. Is there a compile error or weird runtime behavior that you are debugging?
|
|
|
|
|
The problem occurs on runtime.. a messagebox popups "Pure Virtual Function Call" and program terminates.
i have a base class which contain a pure virtual function. Another derived class provides its implementation. In my multithreaded application, when i try to call that function from base class pointer with address of derived class, this error occurs.. But it occurs in some rare scenario.. not consistant..
I just want to clarify the concept.. when does pure virtual function call occurs? in what possible scenarios can this runtime error occur
|
|
|
|
|
It's still kind of vague to me what you are doing. Normally, you call the virtual function using the base class pointer. I don't see any reason why having a derived class pointer would cause a problem. But as a design critique, the purpose of virtual functions is to be able to hide dependencies by using the base class pointer to interface to the object. That way, the users of the object are only bound to the base class at compile time. During runtime, the user is unaware that the derived class actually implements the function. There isn't much point in creating a pure virtual function if the users of your object are calling the function from a derived class pointer anyway. That defeats the purpose of run time binding.
You should have some kind of factory build the classes so that the dependency on the derived class is controlled and limited. The actual users of the class that call the functions should get pointers of the base class type from the factory. Then if the implementation needs changed in the future, not as many pieces of your program have to recompile when you make changes.
Maybe you could show us your class declarations and a few code snippets where the function calls are made to give us an example of what you are doing.
|
|
|
|
|
Most likely you are, indirectly, calling a pure virtual function in your base class constructor.
I recently wrote up how the compiler handles abstract classes and the C++ rules for which overrides are called at what point in answer to a question here[^].
Basically what's happening is you're trying to call through a virtual function that was declared pure either in your class or one of your base classes.
One possibility:
class A
{
public:
A();
protected:
void OtherFunc();
virtual void MyFunc() = 0;
};
class B : public A
{
public:
B();
virtual void MyFunc();
};
A::A()
{
OtherFunc();
}
void A::OtherFunc()
{
MyFunc();
}
B::B()
{
}
void B::MyFunc()
{
} When A's constructor body runs, the virtual function pointer is still pointing to A's vtable. The constructor calls OtherFunc which calls MyFunc , which is generated as a virtual call through the vtable. However, A::MyFunc is a pure virtual function; calling it this way is an error. The Visual C++ compiler traps the error by making the vtable slot point to a routine in the runtime library which reports the error.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
No , i have already mentioned. i am not calling it through constructor.
Any other reason?
anyways, thanks
Shoaib
|
|
|
|
|
I've never experienced a pure virtual function call. However from what I hear it really can only happen in the constructor or in the deconstructor. Then off course it could be a side effect of using invalid pointers to these objects. Also MSVC6 has been known to allow abstract classes to be created in certain cases. It also never hurts to do a rebuild all. I’ve seen some really straight up weird occurrences cause me a good couple hours of confusion all completely melt with a simple rebuild all.
|
|
|
|
|
I have been trying to use the http://www.beyondlogic.org/porttalk/porttalk.htm[^]">PortTalk device driver to access the parallel ports of my PC.
The sample Console applications works OK, but when I try and use this code in a MFC application I get the following errors:-
c:\ParallelPortTest\ParallelPortTest\pt_ioctl.c(114): error C2065: 'SC_HANDLE' : undeclared identifier
c:\ParallelPortTest\ParallelPortTest\pt_ioctl.c(114): error C2146: syntax error : missing ';' before identifier 'SchSCManager'
c:\ParallelPortTest\ParallelPortTest\pt_ioctl.c(114): error C2065: 'SchSCManager' : undeclared identifier
I have tried many complier options but still get the above errors, any suggestions?
|
|
|
|
|
Check the include files and the defines (maybe version conflict, MFC assumes windows NT 4.0 -> stdafx.h ).
Don't try it, just do it!
|
|
|
|
|
Running Windows 2000 SP3 and have included stdafx.h, still lots of errors.
|
|
|
|
|
|
Thanks, I included #include winsvc.h in the file that was giving the errors.
BUT now get the following Link Erros:-
ParallelPortTest error LNK2005: "void __cdecl outportb(unsigned short,unsigned char)" (?outportb@@YAXGE@Z) already defined in ParallelPortTest.obj
ParallelPortTest error LNK2005: "unsigned char __cdecl inportb(unsigned short)" (?inportb@@YAEG@Z) already defined in ParallelPortTest.obj
ParallelPortTest error LNK2005: "unsigned char __cdecl OpenPortTalk(void)" (?OpenPortTalk@@YAEXZ) already defined in ParallelPortTest.obj
ParallelPortTest error LNK2005: "void __cdecl ClosePortTalk(void)" (?ClosePortTalk@@YAXXZ) already defined in ParallelPortTest.obj
Do you know what libraries to include?
|
|
|
|
|
Hey everybody!
I created 2 function.
<br />
void CHelperDlg::UpdateVars(void)
{<br />
CFile fLinkAfter(m_strAppPath+"\\Settings\\LinkAfter.dat", CFile::modeReadWrite);<br />
<br />
ReadFiles(m_clsOptions.m_OptionLinkAfter, fLinkAfter);<br />
MessageBox(m_clsOptions.m_strOptionLinkAfter);<br />
}<br />
<br />
void CHelperDlg::ReadFiles(CString TheVar, CFile ReadedFile)<br />
{<br />
char cBuffer[10];<br />
UINT iRead;<br />
<br />
iRead = ReadedFile.Read(cBuffer, 10);<br />
TheVar = cBuf;<br />
}<br />
now, as far as I understand the var "m_clsOptions.m_OptionLinkAfter"
should get the content of the cBuf, and for some reason, the
"m_clsOptions.m_OptionLinkAfter" still remains empty after the other function is called (checked with the MessageBox).
(TheVar gets m_clsOptions.m_strOptionLinkAfter as its parameter)
shouldn't the ReadFiles function update m_clsOptions.m_strOptionLinkAfter???
THANKS!!!
|
|
|
|
|
Green Fuze wrote:
void CHelperDlg::ReadFiles(CString TheVar, CFile ReadedFile)
Change to:
void CHelperDlg::ReadFiles(CString &TheVar, CFile ReadedFile)
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Perfect!
and I think I just understood something really important!
thanks!
|
|
|
|
|
On top of that, make sure you pass your CFile object by reference or pointer, otherwise the state of the CFile object when returning from the function will be out of sync with the state of the operating system file handle.
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"
|
|
|
|
|
Do anyone know how to encrypt a data into a database in vc++?plz help me!!!
|
|
|
|
|
What do you want to know? The encrypt method, or the encripting with vc++? You can google and find encrypt method.
<italic>Work hard, Work effectively and a bit of luck is the key to success.
|
|
|
|
|
|
Hi,
I am trying to delete a value from my windows registry through VC++ code. Tried using a couple of win API's like RegDeleteValue(), DelRegTree but did'nt really work.
May be I am passing incorrect arguments or I am using the wrong functions. I would appreciate if someone shares his/her views, may be the method to be used or so.
eg.
I have to delete XXX from the registry. This is how my registry looks.
HKEY_CURRENT_USER
Software
Something
ProductV1
ProductV2
XXX
Thanks
|
|
|
|
|
Here is small Source code
#include <atlbase.h>
CRegKey key;
if(key.Open(HKEY_CURRENT_USER,"Software\\Something\\ProductV1\\ProductV2")==ERROR_SUCCEESS)
{
key.DeleteValue("XXX");
key.DeleteSubKey("123");
key.Close();
}
[Vote One Here, Complete my Survey....]
Alok Gupta visit me at http://www.thisisalok.tk
"I Think Believe this Will Help"
|
|
|
|
|
Something has badly changed in .NET compared to vc 6.
I am getting an error
error C2065: 'CRegKey' : undeclared identifier
But I looked at .NET\atlbase.h, I see a class named CRegKey.
Anybody any ideas?
Thanks
|
|
|
|
|
It's going to be hard to show what you did wrong if you don't show us the code that is not working.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|