|
I am in need of a practical example of forward declaring a class. I have written a couple of mini programs using forward declare but am unable to access or modify member variables.
When the programs run I get to the classes ok,
but when I try to access a variable in the class I get a page fault.
|
|
|
|
|
That has nothing to do with forward declaration. If it compiles, then the compiler is properly resolving the forward declarations. It sounds more like you forgot to create an instance of the object--you're accessing it before it's instantiated:
wrong:
Foo* foo;
foo->data=1;
right:
Foo* foo=new Foo();
foo->data=1;
If that doesn't help, can you give an example of your class and your usage?
Marc
Help! I'm an AI running around in someone's f*cked up universe simulator.
|
|
|
|
|
Thanks, I was missing Foo* foo=new Foo();
All of the examples I viewed, except yours, showed how to
Forward Declare, but not how to use it.
|
|
|
|
|
I suspect you have the classical pointer problem - you have a pointer that does not point to a valid object. Assuming we have two classes A and B and both must know of each other. Assume also that class A will own an instance of class B and class B will hold a reference (a pointer) to A then this would work:
#include <B.h>
class A
{
public:
A( );
void DoStuff( );
private:
B m_B;
};
class A;
class B
{
public:
B( A* pA );
void DoOtherStuff( );
private:
A* m_pA;
};
#include <B.h>
#include <A.h>
B::B( A* pA )
: m_pA( pA )
{
}
void B::DoOtherStuff( )
{
}
#include <A.h>
A::A( )
: m_B( this )
{
}
void A::DoStuff( )
{
m_B.DoOtherStuff( );
}
Of course this might not be the design that you want - you might have a design where two otherwise unrelated objects (i.e. class A does not own an instance of class B) have to be able to communicate to each other. As always you must think more in terms of instances of classes rather than classes themselves. I.e. it is technically not the class A that wants to talk to B but rather an instance of class A that wants to talk to a specific instance of class B.
Hope this helps somewhat.
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
Hi,
I have a CListView where I want to change the style for the CHeaderCtrl.
How do I do that? I've tried to add styles in PreCreateWindow but it doesn't work. For example:
BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs) <br />
{<br />
cs.style &= ~HDS_FULLDRAG;<br />
return CListView::PreCreateWindow(cs);<br />
}<br />
Is this the right way to set create styles for the header control?
/P
|
|
|
|
|
Call CListCtrl::GetHeaderCtrl(), then modify the header control itself.
Know Jesus, no peace. No Jesus, know peace.
|
|
|
|
|
Does anybody know how to achieve desktop resizing effect similar for example to what infogate or netzero do?
JRN
|
|
|
|
|
I'm not sure what netzero does, but I do know that creating an AppBar (like the taskbar) can change the size of the Work Area of the desktop.
Chris Richardson
|
|
|
|
|
Thanks a lot!. Here's a link to an article on how to create AppBars:
http://www.microsoft.com/msj/defaulttop.asp?page=/msj/archive/s274.htm
|
|
|
|
|
Hi,
I wanna load some overloeded function exported from a dll by using LoadLibrary and GetProcAddress.
This is the way the exported function is declared in the dll:
BOOL CDllClass::CoolFunction(const char* pszChar,DWORD dwProperty)
{
...
}
BOOL CDllClass::CoolFunction(LPCWSTR pszChar,DWORD dwProperty)
{
...
}
The CDllClass is exported with __declspec(dllexport)
I try to load CoolFunction in this way:
typedef BOOL (CALLBACK* LPFNFUNC)(const char*,DWORD);
...
HMODULE m_hDll = LoadLibrary("mydll.dll");
if (!m_hDll)
{
AfxMessageBox("Error: Cannot find mydll.dll");
return;
}
LPFNFUNC fnMyFunc = (LPFNFUNC)GetProcAddress(m_hDll,"CoolFunction");
if (fnMyFunc == NULL)
{
AfxMessageBox("Error: fnMyFunc == NULL");
return;
}
Problem: GetProcAddress returns NULL.
Question: How does GetProcAddress know which overloeded function to load? Is there some other problem in this code snippet?
Thanks
R.
|
|
|
|
|
Hi, you should use the CDllClass ( why export it otherwise ) or you should make the Coolfunctions static. ( Right now they only have CDllClass scope ).
|
|
|
|
|
If you check out the exported functions (dumpbin /exports for instance), you'll probably see mangling around the export function names. You have to reproduce this mangling in your GetProcAddress call.
The easiest way to export classes however is to dynamically link with the dll instead of using loadlibrary+getprocaddress. In order to do so, you have to include the class header file, and use __declspec(dllimport) instead of __declspc(dllexport). Usually people use a macro :
#ifdef __EXPORTS_DLL__
#define EXPORTED __declspec(dllexport)
#else
#define EXPORTED __declspec(dllimport)
#endif
void EXPORTED DllClass::methodname(...)
{
}
Back to real work : D-23.
|
|
|
|
|
hi
i like to get the default printer name on windowsNT/2000/xp systems. how can i acheive it
actually i am using EnumPrinters() like below
"EnumPrinters(PRINTER_ENUM_DEFAULT,NULL,5,(LPBYTE)pinfo5,dwBytesNeeded,&dwBytesNeeded,&dwReturned);"
but the above function is working on win95/98
its not supporting please help how can i achieve.
thank you
from
venu
|
|
|
|
|
I think in 95/98/Me, you have to monkey with the WIN.INI file to get the info you need. Try something like this:
TCHAR buffer[MAX_PATH];
::GetProfileString("Windows", "device", "", buffer, MAX_PATH);
(Look up GetProfileString on MSDN for more info.)
The printer info should be in that buffer, although I think it also contains some additional stuff (like the port name) so you may have to parse it a little.
Hope this gets you on the right track.
Even a broken clock is right twice a day.
|
|
|
|
|
Look up the ::PrintDlg Win 32 API Function. There is a flag you can set to retrieve the default information. If you are using MFC, CPrintDlg offers the same functionality. You can get the information without displaying the dialog in either case.
|
|
|
|
|
I need to avoid that a dialog get the focus when it's called.
How can I make this ??
[]'s
Cris.
|
|
|
|
|
do not pass WM_SETFOCUS to default window process.
i.e. in MFC
MyCls::OnSetFocus(*)
{
//cancel this line
//CWnd::OnSetFocus(*);
}
includeh10
|
|
|
|
|
In the ClassWizard don't have the WM_SETFOCUS event. But I did write the event and it's not trigged. Do you know why ??
[]'s
|
|
|
|
|
goto last page, select window, it will appear.
includeh10
|
|
|
|
|
What ??
Last page ??
The WM_SETFOCUS don't appear int the MCF Class Wizard dialg.
[]'s
|
|
|
|
|
What ??
Last page ??
Last page of Class wizard!
if still don't understand, let me know with no hesitate!
includeh10
|
|
|
|
|
Ok, thanks for your help ...
[]'s
Cris.
|
|
|
|
|
'ello,
I have a problem with a CListView derived class, it refuses to show the Header control when in report view. I've tried a few things including commenting out all except
GetListCtrl().MofifyStyle(LVS_TYPEMASK,LVS_REPORT);<br />
GetListCtrl().InsertColumn(0,"Test",LVCFMT_LEFT,100);
in OnInitalUpdate().
The app is a appwizard produced SDI app with the "Windows Explorer" option enabled" and has the Listview view options buttons on the toolbar, the selected mode shows as the Details mode when the app starts but the CHeaderCtrl() is never created ( GetListCtrl()->GetHeaderCtrl() returns NULL ).
Another appwizard produced app with all the same modes works ok, anyone else as confused as me?
[EDIT]
Never mInd i forgot to delete the defualt (empty) implmentation of OnStyleChanged [/EDIT]
Richard Green
|
|
|
|
|
Does anyone knows how can i capture mouse movements from the driver of the mouse and not by capturing WM_MOUSEMOVE.
I need somethig like "LowLevelMouseProc" for all windows and not only for 2000 and XP.
Thanks.
|
|
|
|
|
::GetCursorPos
Back to real work : D-23.
|
|
|
|