Compiler error C2440: 'type cast' 
Author Message
 Compiler error C2440: 'type cast'

I get the following compiler error

error C2440: 'type cast' : cannot convert from 'long (__thiscall
CHookControlCtrl::*)(int,unsigned int,long)' to 'long *'

when I try to compile this MFC Control:

(...)
LRESULT CHookControlCtrl::JournalRecordHookProc(int nCode, WPARAM wParam,
LPARAM lParam)
{
    switch (nCode)
 {
 case HC_ACTION :
  {
   EVENTMSG * lpEM = (EVENTMSG *) lParam;

   FireJournalEvent(lpEM->paramL, lpEM->paramH, lpEM->time);

  }
  break;
 }
    return CallNextHookEx (ghJournalRecordHook, nCode, wParam, lParam);

Quote:
}

BOOL CHookControlCtrl::SetJournalRecordHook(const char *fn)
{
 if (ghInstanceCount++ == 0)

     ghJournalRecordHook = SetWindowsHookEx (WH_JOURNALRECORD,
JournalRecordHookProc, ghInst, 0);

// ^--Here is the error
  ghFileHandle = CreateFile (fn, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);

  return ghJournalRecordHook != (HHOOK) NULL && ghFileHandle != (HANDLE)
NULL;
 }
 else
 {
  return FALSE;
 }

Quote:
}

(...)

How do I fix that? Is it possible to use a member function as a callback
function at all?

Regards

Thomas - www.inova.dk



Wed, 26 Jun 2002 03:00:00 GMT  
 Compiler error C2440: 'type cast'
Thomas,

Quote:
> I get the following compiler error

> error C2440: 'type cast' : cannot convert from 'long (__thiscall
> CHookControlCtrl::*)(int,unsigned int,long)' to 'long *'
<code snipped>
> How do I fix that? Is it possible to use a member function as a callback
> function at all?

Not directly: You have to use a static member function instead.

--
Tomas Restrepo
http://members.xoom.com/trestrep/



Thu, 27 Jun 2002 03:00:00 GMT  
 Compiler error C2440: 'type cast'
That's ok - but now I can't fire an event from that static function - how do
I fire an event from a static function?


Quote:
> Thomas,
> > I get the following compiler error

> > error C2440: 'type cast' : cannot convert from 'long (__thiscall
> > CHookControlCtrl::*)(int,unsigned int,long)' to 'long *'
> <code snipped>
> > How do I fix that? Is it possible to use a member function as a callback
> > function at all?

> Not directly: You have to use a static member function instead.

> --
> Tomas Restrepo
> http://members.xoom.com/trestrep/



Fri, 28 Jun 2002 03:00:00 GMT  
 Compiler error C2440: 'type cast'
Thomas,

Quote:
> That's ok - but now I can't fire an event from that static function - how
do
> I fire an event from a static function?

What kind of event? A normal window message? Well, in any case, unless you
need to keep multiple simultanious hooks (which is not the normal case), you
can add a static member variable to the class and save the instance pointer
there, where the static callback can access it....

--
Tomas Restrepo
http://members.xoom.com/trestrep/



Fri, 28 Jun 2002 03:00:00 GMT  
 Compiler error C2440: 'type cast'
A MFC Control Event:

////////////////////////////////////////////////////////////////////////////
/
// CHookControlCtrl message handlers

LRESULT CHookControlCtrl::JournalRecordHookProc(int nCode, WPARAM wParam,
LPARAM lParam)
{
    switch (nCode)
 {
 case HC_ACTION :
  {
   EVENTMSG * lpEM = (EVENTMSG *) lParam;

   FireJournalEvent(lpEM->paramL, lpEM->paramH, lpEM->time);

  }
  break;
 }
    return CallNextHookEx (ghJournalRecordHook, nCode, wParam, lParam);

Quote:
}





Fri, 28 Jun 2002 03:00:00 GMT  
 Compiler error C2440: 'type cast'
Thomas,

Quote:
> A MFC Control Event:

Not much of a COM guru, so I might miss the point here, but under some
circumstances, if your callback gets invoked under a different thread's
context, you might have trouble if you try to fire the event from that
thread, instead of the main thread. In that case I'd prefer to signal the
main thread the control is running on to fire the event....

--
Tomas Restrepo
http://members.xoom.com/trestrep/



Fri, 28 Jun 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. error C2440: 'type cast' :

2. Error error C2440: '=' : cannot convert from

3. Type Cast error C2440?

4. error C2440: 'static_cast' for ON_MESSAGE

5. array issue 'type cast warning'

6. C1001: INTERNAL COMPILER ERROR (compiler files 'msc1.cpp', line 2844)

7. C1001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp', line 1794)

8. INTERNAL COMPILER ERROR - compiler file 'msc1.cpp', line 1794)

9. Why can't overload type cast to base type (object)

10. Compiler Error CS0013 -- 'Unspecified error'

11. 'incompatble types error'- help needed

12. Runtime Error '13': Type Mismatch

 

 
Powered by phpBB® Forum Software