|
How do i make a pointer to point to a function.
and i hope to have this pointer to be able to point to several type of functions?
like
CString getDate();
CString getMonth(int i);
how can make a pointer to point either to these two functions??
thanxs in advance
|
|
|
|
|
aldeba wrote:
how can make a pointer to point either to these two functions??
You can't. The signatures of functions are different - getDate doesn't have arguments, while getMonth takes one integer argument.
Why would you like to have one pointer which can point to either of these functions?
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
you can use a void * pointer to point at either function:
void *p = getDate;
p = getMonth;
-c
WWJD? JWRTFM. found on /.
|
|
|
|
|
just tak ein to a void pointer .after that cast them in to appropriate funtion type..
Renjith-CPian.
|
|
|
|
|
Hi,
On the dialog-based application, I put the Hide Dialog button, and the code for : OnHideDialog() is like:
ModifyStyle(WS_SHOWWINDOW, 0,0);
When I click the Hide Dialog button, it seems like the dialog is like a ghost, it's there but the window behind it receives the focus.
Can anyone explain me why and how to fix it ?
Thanks
|
|
|
|
|
Try with ShowWindow(SW_HIDE) instead.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Like someone else said you should use ShowWindow. But, to be precise, it's the WS_VISIBLE style you'd want to remove: ModifyStyle( WS_VISIBLE, 0, 0 );
Joel Lucsy (jjlucsy@ameritech.net)
|
|
|
|
|
I keep receiving an error when i am working with my .rc and resource.h saying that they have been modified outside of visual studio, and asking if i want to reload them.. i am the only person using the software, or editing the files, and it just asked me the same thing and reloaded them a few minutes ago.. i keep getting this error about reloading the resource, what could cause this? i think this may somehow be related to my other main problem i posted last night.
which can be found here:
http://www.codeproject.com/script/comments/forums.asp?forumid=1647&fr=26#xx252677xx[^]
any ideas on either thing? .net is actin real screwy..
-dz
|
|
|
|
|
Chances are it is your AV software getting in the way. This has been a problem long before .NET.
Tim Smith
"Programmers are always surrounded by complexity; we can not avoid it... If our basic tool, the language in which we design and code our programs, is also complicated, the language itself becomes part of the problem rather that part of the solution."
Hoare - 1980 ACM Turing Award Lecture
|
|
|
|
|
welp i've disabled it, but how could this cause the problem? does NAV actually scan .h or .rc files?
thanks for the suggestion, hopefully thats it..
-dz
|
|
|
|
|
I get this in VS.NET occasionally and I don't run AV software... I'll see if I can dupe it.
I'd tell all my friends
But they'd never believe me
They'd think that I'd finally lost it completely.
|
|
|
|
|
I try to scroll a MFC rich edit control to the last line but it seems that i don't understand the LineScroll method's behaviour.
Do you know how to properly use it?
rechi
|
|
|
|
|
Hi,
I have a class
class CTestDlg : public CDialog , public D360::CController
{
which I want to respond to messages like
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
ON_MESSAGE(OLDA_WM_BUFFER_DONE, OnBufferDone)
END_MESSAGE_MAP()
This worked when the CTestDlg class only inherited from CDialog, but now I get the following compilation error
error C2440: 'type cast' : cannot convert from 'int (__thiscall CTestDlg::*)(unsigned int,long)' to 'long (__thiscall CWnd::*)(unsigned int,long)'
Pointers to members have different representations; cannot cast between them
I don't know much about the D360::CController class, it was supplied with some hardware.
Any suggestions would be appreciated.
Will
|
|
|
|
|
Do you really have to derive from D360::CController? Are there any CController virtual functions you are overriding?
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
As far as I can tell, yes I do have to derive from D360::CController - it is doing something I don't understand with ATL to interface with the hardware. The only example code the company sent me used multiple inheritance.
Is this a general problem with ON_MESSAGE and multiple inheritance, or just a strange quirk of the classes I am trying to inherit from?
Will
|
|
|
|
|
Will Woods wrote:
Is this a general problem with ON_MESSAGE and multiple inheritance, or just a strange quirk of the classes I am trying to inherit from?
Well, the MFC wasn't designed with multiple inheritance in mind. This means that you can't have your object derived from CCoolWnd and COtherWnd. OTOH, you can derive your object from CWnd (or CView, CDialog, or any other MFC window class) and non-MFC class[es]. In such case you just have to make sure that MFC class is first in the base classes list. I've used this approach in many MFC-based projects.
So one possible reason for your problems would be CController deriving from some MFC class. Can you have a look on the D360 docs?
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Problem solved - I had declared the callback functions to return bool (as 'required' by some other hardware drivers) - changing the return type to LRESULT fixed the problem.
I wonder why this compiled ok (I just checked it, it does) before I added the second inheritance??
Thanks for your help.
Will
|
|
|
|
|
I am reading a book on the GDI and have noticed that the author deletes an object before reusing it but do not delete it before restoring the 'Old Object'. Why is this? Is it good practise to delete the object anyway, after reselecting the 'Old Object'?
|
|
|
|
|
If object is selected into device context, the call to DeleteObject fails.
So, if you don't select 'old' object or any other existing object of given type, you'll get GDI memory leak.
Your other option is to destroy DC first; this will release all objects. However, this isn't always possible. For example, CView::OnDraw method gets the DC as parameter and you shouldn't destroy this context.
Another solution could be using SaveDC and RestoreDC functions.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
But is there a good reason why the author is not deleting his objects after reselecting the 'OldObject'(by this I mean the windows pen or font that was being used before my program started creating objects)? Does selecting the 'OldObject' automatically delete the existing object? Or is he a nitwit ?;P and I do have to delete any object I create regardless of whether I Reselect the 'OldObject'
|
|
|
|
|
Anonymous wrote:
But is there a good reason why the author is not deleting his objects after reselecting the 'OldObject'
It depends. If he's using MFC, then CPen/CBrush/CFont destructor will call DeleteObject. Since object isn't selected anymore, the DeleteObject will succeed.
He also may be using global variables or class members with lifetime longer than piece of code in which he's using GDI objects
But - if he's running on raw Win32 API and there are no DeleteObject calls for local objects created with CreatePen/Brush/Font etc., then he is a nitwit indeed. BTW: who's 'the author'?
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
He is using MFC and since chances that I'm the nitwit is rather big, and he has a great sense of humour, I will refrain from mentioning any names. Thanks for the answer it was just what I needed to know
|
|
|
|
|
I want to use CreateThread() function, and i have created a ThreadFunc. The problem is, that i want this ThreadFunc to be placed within a calss (i don't want it to be a global function).
member function is defined as follows:
<br />
unsigned long __stdcall ThreadFunc(void * Parameter);<br />
And i try to do a conversion to:
<br />
LPTHREAD_START_ROUTINE TS;<br />
Both:
<br />
TS=ThreadFunc;<br />
And:
<br />
TS=CMyDialog::ThreadFunc;<br />
Report as follows:
error C2440: '=' : cannot convert from
'unsigned long (__stdcall CMyDialog::*)(void *)'
to
'unsigned long (__stdcall *)(void *)'
First conversion works when ThreadFunc is not a class member, but both fails when it is a class member.
How to make this conversion?
Railgun is like a Gilette Mach 3 - it does the job with one, easy stroke.
|
|
|
|
|
If you insist on member function, you must make it a static one. Also, if you use CreateThread, you may hit problems with C++ runtime. Use _beginthread[ex]; these functions call CreateThread for you.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Adding to what Tomasz said, use only the _beginthreadex(do not use _beginthread or CreateThread) or AfxBeginThread in MFC, these 2 functions create the necessary TIB(Thread Information Block) that is necessary to the C/C++ runtime could correctly dispose and control the Thread specific data.
Cheers,
Joao Vaz
And if your dream is to care for your family, to put food on the table, to provide them with an education and a good home, then maybe suffering through an endless, pointless, boring job will seem to have purpose. And you will realize how even a rock can change the world, simply by remaining obstinately stationary. - Shog9
|
|
|
|