Re: Visual C Cdialog.DoModal()
From: Joseph M. Newcomer (newcomer_at_flounder.com)
Date: 07/02/04
- Next message: Joseph M. Newcomer: "Re: RUNTIME_CLASS type checking with a template class from CObject"
- Previous message: Joseph M. Newcomer: "Re: Visual C Cdialog.DoModal()"
- In reply to: Dirk Mohr: "Re: Visual C Cdialog.DoModal()"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 01 Jul 2004 21:00:02 -0400
Even if the functions are global (usually a bad idea unless they need to be shared across
classes and are defined entirely by their input parameters), or static class functions
(usually not needed either). The fast solution is to simply declare the dialog in the
routine where it is invoked, since I can't see any reason to store its object in a class
anywhere.
The message is pretty obvious. It is trying to convert a pointer to a static function to
be a pointer to a method, and that won't work. You need an object by which to invoke it.
You would need a Class variable:
Class A;
A.Func(1, 2, 3);
would work. But unless this function needs access to class member variables (in which case
you need the actual class instance to invoke it whose variables are to be used), you
should declare it static.
Your choices are either the above, or having an instance of a Class object, e.g.,
Class * A;
A = ...some computation that gives you the object
A->Func(1, 2, 3);
If you don't have a specific object, you don't need access to the class members, and
therefore you should declare Func as static. Then you can write
Class::Func(1, 2, 3);
Essentially, there is no need, as far as I can tell, to have the dialog member in the
class, so you could easily write
void SomeGlobalFunction()
{
CMyDialog dlg;
dlg.DoModal();
}
and it should work in the usual way.
<If there are two posts, it is because I hit a key which apparently sent the post. This is
what I was about to type>
If the purpose is to retain in value variables the results of the last invocation of the
dialog, so it is re-invoked, you have a more serious problem. First, you MUST have a
reference to the object containing the dialog, because otherwise how will you know which
member variable in which instance is going to be used, so then the problem is again
trivial; you will have a reference to the object, and hence its dialog member. If you
don't need to retain this state, then there is no reason not to do the much simpler code
above. You can't just "reach into" the class and pick up "the" member variable, because
without a class instance there simply isn't ANY member variable you can talk about. But if
there is only one dialog, then you could declare it as a static class member, and write
Class::whateverdlg.DoModal();
and that will work also.
joe
joe
On 1 Jul 2004 01:11:00 -0700, dirk.mohr@fh-bochum.de (Dirk Mohr) wrote:
>Hello Joseph,
>
>I think your right !! I have got this programm from another
>programmer. In future I will take the global functions to member
>functions. But in the moment I havent's enough time. It's an
>industrial project and I have to found a fast solution. First I try to
>make this with one function and there I get the next problem. The
>situation :
>
>I need the adress of a member function. I do so :
>
>member function : long MFTYPE Class::Func(long,long,void*)
>function pointer : long (Class::*fp)(long,long,void*)
>
>When I try fp = &Class::Func I get the compiler error message
>
>long(__stdcall Class::*)(long,long,void*) can not converted to
>long(__thiscall Class::*)(long,long,void*)
>
>What is the meaning of this ? What can I do to handle ?
>
>Thank'S for your help !!
>
>Dirk
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
- Next message: Joseph M. Newcomer: "Re: RUNTIME_CLASS type checking with a template class from CObject"
- Previous message: Joseph M. Newcomer: "Re: Visual C Cdialog.DoModal()"
- In reply to: Dirk Mohr: "Re: Visual C Cdialog.DoModal()"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|