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. using externally defined function pointers

using externally defined function pointers

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
4 Posts 3 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.
  • E Offline
    E Offline
    erkanina
    wrote on last edited by
    #1

    Dear Programmers, I am working on an MFC/Dialog based project. I defined a function pointer in a class's header file as a static like below; ... typedef BOOL (WINAPI *blTagHCWDOGEnable)(DWORD IN_dwSecTime); static blTagHCWDOGEnable blHCWDOGEnable; ... Then I initialised this function pointer from a dll with ordinary function (LoadLibrary(...) , GetProcAddress(...)) Everything is working OK in this class. I am able to use this function but when I try to use this function from another class I am encountering errors. As if something modifying content of function pointer and it is equaling to NULL. What may cause this? Thanks and best regards

    R 1 Reply Last reply
    0
    • E erkanina

      Dear Programmers, I am working on an MFC/Dialog based project. I defined a function pointer in a class's header file as a static like below; ... typedef BOOL (WINAPI *blTagHCWDOGEnable)(DWORD IN_dwSecTime); static blTagHCWDOGEnable blHCWDOGEnable; ... Then I initialised this function pointer from a dll with ordinary function (LoadLibrary(...) , GetProcAddress(...)) Everything is working OK in this class. I am able to use this function but when I try to use this function from another class I am encountering errors. As if something modifying content of function pointer and it is equaling to NULL. What may cause this? Thanks and best regards

      R Offline
      R Offline
      Ryan Binns
      wrote on last edited by
      #2

      Erkan Ermis wrote: What may cause this? The static keyword. Each file that uses your header file will get its own copy of the variable, so if you set it from one file, other files won't see the change. Change static to extern and define the variable in one of the .cpp files without the extern keyword. That should help it to work.

      Ryan

      "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

      E 1 Reply Last reply
      0
      • R Ryan Binns

        Erkan Ermis wrote: What may cause this? The static keyword. Each file that uses your header file will get its own copy of the variable, so if you set it from one file, other files won't see the change. Change static to extern and define the variable in one of the .cpp files without the extern keyword. That should help it to work.

        Ryan

        "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

        E Offline
        E Offline
        erkanina
        wrote on last edited by
        #3

        I have not applied yet but I am sure it will work. Thanks for your clear explanation.

        G 1 Reply Last reply
        0
        • E erkanina

          I have not applied yet but I am sure it will work. Thanks for your clear explanation.

          G Offline
          G Offline
          gamitech
          wrote on last edited by
          #4

          or you can use typedef VOID (CALLBACK* PROCEDURE)(VOID);//or any parameter PROCEDURE procedure; dllhinst=LoadLibrary("x"); if (dllhinst!=NULL) { procedure=(PROCEDURE)GetProcAddress(dllhinst, "Function"); } I can assure this will work very well gabby

          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