CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2009
    Posts
    12

    VC++ 6.0 -> .net 2003 conversion issue

    Hi all,

    I'm having an issue converting some code that compiled in VC++ 6.0 fine, but is not in .net 2003.

    I've scoured the internet, and found a lot of solutions to problems were related to this error, but nothing for this particular issue.

    The error I'm receiving from the compiler is:

    filename.cpp(88): error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall ClassName::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
    The offending line of code is:

    Code:
    BEGIN_MESSAGE_MAP(ClassName, CWinApp)
    .
    .
    .
         ON_MESSAGE(WM_USER,SaveAllModDBTF)
    The function's prototype:

    Code:
    afx_msg LRESULT SaveAllModDBTF(WPARAM, LPARAM);
    The function's header:

    Code:
    LRESULT ClassName::SaveAllModDBTF(WPARAM	wParam,LPARAM	lParam)
    Does anyone have any ideas about what the issue could be? Let me know if any additional information is required.
    Last edited by snikeris; May 27th, 2009 at 07:05 AM.

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: VC++ 6.0 -> .net 2003 conversion issue

    Only WM_COMMAND messages are routed to CWinApp class. user defined messages (WM_USER, WM_APP, register Windows messages and many others) - not!
    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2009
    Posts
    57

    Re: VC++ 6.0 -> .net 2003 conversion issue

    Hmm,

    What is ClassName derived from?


    ... what happens if you cast it to a CWnd? It appears that the compiler wants a CWnd derived class.

  4. #4
    Join Date
    May 2009
    Posts
    12

    Re: VC++ 6.0 -> .net 2003 conversion issue

    Quote Originally Posted by VictorN View Post
    Only WM_COMMAND messages are routed to CWinApp class. user defined messages (WM_USER, WM_APP, register Windows messages and many others) - not!
    Is this something that changed w/ .NET 2003?

    If not, are you saying that this application has never received those messages, and therefore has never called the corresponding handling functions?

  5. #5
    Join Date
    May 2009
    Posts
    12

    Re: VC++ 6.0 -> .net 2003 conversion issue

    Quote Originally Posted by CNemo View Post
    Hmm,

    What is ClassName derived from?


    ... what happens if you cast it to a CWnd? It appears that the compiler wants a CWnd derived class.
    It is derived from CWinApp.

    I'm not sure what you mean by cast it. If, in the header file I change:

    Code:
    class ClassName : public CWinApp
    {
    to

    Code:
    class ClassName : public CWnd
    {
    The error appears to go away, but I get a bunch of new errors since members of CWinApp are no longer available.

    Is this what you meant by casting it?

  6. #6
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: VC++ 6.0 -> .net 2003 conversion issue

    Quote Originally Posted by snikeris View Post
    Is this something that changed w/ .NET 2003?
    No!

    Quote Originally Posted by snikeris View Post
    If not, are you saying that this application has never received those messages, and therefore has never called the corresponding handling functions?
    All window messagescan only be sent/posted to some window.
    In MFC you can send/post messages to any CWnd derived class object as lon as this object has already created its window (m_hWnd member).
    CWinApp class is NOT derived from CWnd and it does NOT have any window to which you could sent/post message.
    However, MFC extends the message routing behaviour for some messages (such as WM_COMMAND), so the message sent to the CMainFrame window might be also handled in one of the CView, CDocument or CWinApp derived classes, if is were not handled in CMainFrame derived class.
    Have a look at TN021: Command and Message Routing
    Victor Nijegorodov

  7. #7
    Join Date
    Apr 2009
    Posts
    57

    Re: VC++ 6.0 -> .net 2003 conversion issue

    Hmmm, it sounds like you changed the code somehow when you converted it to 2003.

    What Victor is trying to tell you is that the type of message you are trying to send is only works for CWnd derive classes and the message you are using is in a CWinApp.


    I believe your code worked in V6 but you changed something.

    Try the following:


    Create an Empty Project in 2003 and just copy the files from your working V6 project without changing any code. The should work.


    If not let us know. But if it worked in V6 then creating an empty project and copying the project files over should work.

    You probobly moved that function over from a Wnd derived class or made some other file modes when you went to 2003, again create an empty project and just copy the V6 FILES over.


    ...other wise you are going to have to rewrite your function to be CWinApp compatible(which you shouldn't have to if it worked in V6)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured