Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Callbacks

Callbacks

Scheduled Pinned Locked Moved C / C++ / MFC
helpperformancequestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    halblonious
    wrote on last edited by
    #1

    In a function, I create a font chooer dialog for my user, for which I'm trying to add a callback function, like so: //create the pointer LPCFHOOKPROC FontHook; //create the font chooser dialog CFontDialog dlg(&LogFont,CF_ENABLEHOOK|CF_EFFECTS|CF_BOTH|CF_NOVECTORFONTS|CF_NOSCRIPTSEL|CF_INITTOLOGFONTSTRUCT,NULL,NULL); //tell it to hook to the function dlg.m_cf.lpfnHook = FontHook; //display the font dialog if(dlg.DoModal() == IDOK) { //blah blah } Then, elsewhere in the view I added the actual callback function, like so: UINT CALLBACK FontHook(HWND hdlg,UINT uiMsg,WPARAM wParam,LPARAM lParam) { //blah blah return TRUE; } It compiles fine, but when I try to use the font dialog is gives me an application error: "The instruction at '0xcccccccc' referenced memory at '0xcccccccc'. The memory could not be 'read'." It desplays this three times, before quitting out. I figured out it's on the .DoModal line where it's having the issue, I think. It gives me this error when debugging: "Unhandled exception in Application.exe: 0xC0000005: Access violation." Can anyone please tell me what I'm doing wrong or forgetting to do? halblonious

    U P D 3 Replies Last reply
    0
    • H halblonious

      In a function, I create a font chooer dialog for my user, for which I'm trying to add a callback function, like so: //create the pointer LPCFHOOKPROC FontHook; //create the font chooser dialog CFontDialog dlg(&LogFont,CF_ENABLEHOOK|CF_EFFECTS|CF_BOTH|CF_NOVECTORFONTS|CF_NOSCRIPTSEL|CF_INITTOLOGFONTSTRUCT,NULL,NULL); //tell it to hook to the function dlg.m_cf.lpfnHook = FontHook; //display the font dialog if(dlg.DoModal() == IDOK) { //blah blah } Then, elsewhere in the view I added the actual callback function, like so: UINT CALLBACK FontHook(HWND hdlg,UINT uiMsg,WPARAM wParam,LPARAM lParam) { //blah blah return TRUE; } It compiles fine, but when I try to use the font dialog is gives me an application error: "The instruction at '0xcccccccc' referenced memory at '0xcccccccc'. The memory could not be 'read'." It desplays this three times, before quitting out. I figured out it's on the .DoModal line where it's having the issue, I think. It gives me this error when debugging: "Unhandled exception in Application.exe: 0xC0000005: Access violation." Can anyone please tell me what I'm doing wrong or forgetting to do? halblonious

      P Offline
      P Offline
      Phil Speller
      wrote on last edited by
      #2

      The problem is to do with your FontHook pointer. To get this working you need to remove the following from your code: //create the pointer LPCFHOOKPROC FontHook; Then ensure that you have a prototype for the callback fn somewhere before where you create your dialog. Prototype will look something like: UINT CALLBACK FontHook( HWND, UINT, WPARAM, LPARAM ); What you are doing wrong is creating an uninitialised local pointer in your dialog creation fn and you specify this pointer as the address of the callback fn. In debug mode, items such as un-initialised pointers always get set to 0xCCCCCCCC so that it's easy to recognise them as such. Phil

      H 1 Reply Last reply
      0
      • H halblonious

        In a function, I create a font chooer dialog for my user, for which I'm trying to add a callback function, like so: //create the pointer LPCFHOOKPROC FontHook; //create the font chooser dialog CFontDialog dlg(&LogFont,CF_ENABLEHOOK|CF_EFFECTS|CF_BOTH|CF_NOVECTORFONTS|CF_NOSCRIPTSEL|CF_INITTOLOGFONTSTRUCT,NULL,NULL); //tell it to hook to the function dlg.m_cf.lpfnHook = FontHook; //display the font dialog if(dlg.DoModal() == IDOK) { //blah blah } Then, elsewhere in the view I added the actual callback function, like so: UINT CALLBACK FontHook(HWND hdlg,UINT uiMsg,WPARAM wParam,LPARAM lParam) { //blah blah return TRUE; } It compiles fine, but when I try to use the font dialog is gives me an application error: "The instruction at '0xcccccccc' referenced memory at '0xcccccccc'. The memory could not be 'read'." It desplays this three times, before quitting out. I figured out it's on the .DoModal line where it's having the issue, I think. It gives me this error when debugging: "Unhandled exception in Application.exe: 0xC0000005: Access violation." Can anyone please tell me what I'm doing wrong or forgetting to do? halblonious

        U Offline
        U Offline
        User 423850
        wrote on last edited by
        #3

        Try this instead of ur function write UINT_PTR CALLBACK CFHookProc( HWND hdlg, // handle to dialog box UINT uiMsg, // message identifier WPARAM wParam, // message parameter LPARAM lParam // message parameter ); and then try out if not write back Thanx TAKE CARE

        H 1 Reply Last reply
        0
        • H halblonious

          In a function, I create a font chooer dialog for my user, for which I'm trying to add a callback function, like so: //create the pointer LPCFHOOKPROC FontHook; //create the font chooser dialog CFontDialog dlg(&LogFont,CF_ENABLEHOOK|CF_EFFECTS|CF_BOTH|CF_NOVECTORFONTS|CF_NOSCRIPTSEL|CF_INITTOLOGFONTSTRUCT,NULL,NULL); //tell it to hook to the function dlg.m_cf.lpfnHook = FontHook; //display the font dialog if(dlg.DoModal() == IDOK) { //blah blah } Then, elsewhere in the view I added the actual callback function, like so: UINT CALLBACK FontHook(HWND hdlg,UINT uiMsg,WPARAM wParam,LPARAM lParam) { //blah blah return TRUE; } It compiles fine, but when I try to use the font dialog is gives me an application error: "The instruction at '0xcccccccc' referenced memory at '0xcccccccc'. The memory could not be 'read'." It desplays this three times, before quitting out. I figured out it's on the .DoModal line where it's having the issue, I think. It gives me this error when debugging: "Unhandled exception in Application.exe: 0xC0000005: Access violation." Can anyone please tell me what I'm doing wrong or forgetting to do? halblonious

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          In addition to what Phil has already pointed out, by using CF_BOTH, I believe that the hDC member of your LOGFONT structure must also be initialized. Are the other members properly initialized?


          Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

          H 1 Reply Last reply
          0
          • P Phil Speller

            The problem is to do with your FontHook pointer. To get this working you need to remove the following from your code: //create the pointer LPCFHOOKPROC FontHook; Then ensure that you have a prototype for the callback fn somewhere before where you create your dialog. Prototype will look something like: UINT CALLBACK FontHook( HWND, UINT, WPARAM, LPARAM ); What you are doing wrong is creating an uninitialised local pointer in your dialog creation fn and you specify this pointer as the address of the callback fn. In debug mode, items such as un-initialised pointers always get set to 0xCCCCCCCC so that it's easy to recognise them as such. Phil

            H Offline
            H Offline
            halblonious
            wrote on last edited by
            #5

            Thank you very much, that seemed to work. Now, I'm off to figure out how to make do what I want... halblonious

            1 Reply Last reply
            0
            • D David Crow

              In addition to what Phil has already pointed out, by using CF_BOTH, I believe that the hDC member of your LOGFONT structure must also be initialized. Are the other members properly initialized?


              Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

              H Offline
              H Offline
              halblonious
              wrote on last edited by
              #6

              They must be, because it seems to work now that I changed that line. Thank you. halblonious

              1 Reply Last reply
              0
              • U User 423850

                Try this instead of ur function write UINT_PTR CALLBACK CFHookProc( HWND hdlg, // handle to dialog box UINT uiMsg, // message identifier WPARAM wParam, // message parameter LPARAM lParam // message parameter ); and then try out if not write back Thanx TAKE CARE

                H Offline
                H Offline
                halblonious
                wrote on last edited by
                #7

                I've got it working now. Thank you for your comment. halblonious

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups