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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Accessing Activex control methods from static functions??

Accessing Activex control methods from static functions??

Scheduled Pinned Locked Moved C / C++ / MFC
c++comhelptutorialquestion
11 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.
  • V Offline
    V Offline
    vanip
    wrote on last edited by
    #1

    Hi all, I am using an activex control which is registered under regsvr32. I created an MFC-dialog based aplication.I added activex control to the dialog box. And created a member-variable for the activex control thru class wizard.The member variable is m_myportcontroller.I called the activex method from a non-static member function of the dialog box using the member-variable as follows and worked fine. ex:- void CSampleDlg::process(void) { m_myportcontroller.Close(); } But i need to call the portcontroller methods from a static member function of a dialog based application (MFC). ex:- static void CSampleDlg::process(void) { m_myporcontroller.Close(); // Not accessible because static function } Please send sample code of how to access the methods from static function. Very urgently needed.Early reply is appreciatable. Awaiting for the reply, I had a problem in accessing Activex control methods from a static function

    V N R 3 Replies Last reply
    0
    • V vanip

      Hi all, I am using an activex control which is registered under regsvr32. I created an MFC-dialog based aplication.I added activex control to the dialog box. And created a member-variable for the activex control thru class wizard.The member variable is m_myportcontroller.I called the activex method from a non-static member function of the dialog box using the member-variable as follows and worked fine. ex:- void CSampleDlg::process(void) { m_myportcontroller.Close(); } But i need to call the portcontroller methods from a static member function of a dialog based application (MFC). ex:- static void CSampleDlg::process(void) { m_myporcontroller.Close(); // Not accessible because static function } Please send sample code of how to access the methods from static function. Very urgently needed.Early reply is appreciatable. Awaiting for the reply, I had a problem in accessing Activex control methods from a static function

      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #2

      vanip wrote:

      But i need to call the portcontroller methods from a static member function of a dialog based application (MFC). ex:- static void CSampleDlg::process(void) { m_myporcontroller.Close(); // Not accessible because static function }

      You have to create an instance of portcontroller inside the static method. That is how static methods work since they are not instance methods but class methods. For eg:

      static void CSampleDlg::process(void)
      {
      portcontroller pc;
      pc.Close(); // now accessible
      }

      or

      static void CSampleDlg::process(portcontroller& pc)
      {
      pc.Close(); // now accessible
      }

      vanip wrote:

      Please send sample code of how to access the methods from static function. Very urgently needed.

      No. :)


      Nibu thomas Software Developer

      V 1 Reply Last reply
      0
      • V vanip

        Hi all, I am using an activex control which is registered under regsvr32. I created an MFC-dialog based aplication.I added activex control to the dialog box. And created a member-variable for the activex control thru class wizard.The member variable is m_myportcontroller.I called the activex method from a non-static member function of the dialog box using the member-variable as follows and worked fine. ex:- void CSampleDlg::process(void) { m_myportcontroller.Close(); } But i need to call the portcontroller methods from a static member function of a dialog based application (MFC). ex:- static void CSampleDlg::process(void) { m_myporcontroller.Close(); // Not accessible because static function } Please send sample code of how to access the methods from static function. Very urgently needed.Early reply is appreciatable. Awaiting for the reply, I had a problem in accessing Activex control methods from a static function

        V Offline
        V Offline
        Vinaya
        wrote on last edited by
        #3

        Static member functions do not have the this pointer. So they cannot access nonstatic class member data. In your case m_myportcontroller is declared as a non static data member. Vini

        V 1 Reply Last reply
        0
        • V Vinaya

          Static member functions do not have the this pointer. So they cannot access nonstatic class member data. In your case m_myportcontroller is declared as a non static data member. Vini

          V Offline
          V Offline
          vanip
          wrote on last edited by
          #4

          Thanks vinaya, How to make that static? I tried keeping static keyword in front of CPortController m_myportcontroller. But i am getting linker error. Do you know how to make that member as static??

          V 1 Reply Last reply
          0
          • N Nibu babu thomas

            vanip wrote:

            But i need to call the portcontroller methods from a static member function of a dialog based application (MFC). ex:- static void CSampleDlg::process(void) { m_myporcontroller.Close(); // Not accessible because static function }

            You have to create an instance of portcontroller inside the static method. That is how static methods work since they are not instance methods but class methods. For eg:

            static void CSampleDlg::process(void)
            {
            portcontroller pc;
            pc.Close(); // now accessible
            }

            or

            static void CSampleDlg::process(portcontroller& pc)
            {
            pc.Close(); // now accessible
            }

            vanip wrote:

            Please send sample code of how to access the methods from static function. Very urgently needed.

            No. :)


            Nibu thomas Software Developer

            V Offline
            V Offline
            vanip
            wrote on last edited by
            #5

            Thanks nibu thomas, I tried this way. But getting run time assertion error. Any other way??

            1 Reply Last reply
            0
            • V vanip

              Thanks vinaya, How to make that static? I tried keeping static keyword in front of CPortController m_myportcontroller. But i am getting linker error. Do you know how to make that member as static??

              V Offline
              V Offline
              Vinaya
              wrote on last edited by
              #6

              Static member data need to be defined outside the class declaration. You can declare the CPortController member variable as static. static CPortController m_myportcontroller ; In the CSampleDlg cpp file, define the static variable as

              CPortController CSampleDlg::m_myportcontroller;
              

              Vini

              V 1 Reply Last reply
              0
              • V vanip

                Hi all, I am using an activex control which is registered under regsvr32. I created an MFC-dialog based aplication.I added activex control to the dialog box. And created a member-variable for the activex control thru class wizard.The member variable is m_myportcontroller.I called the activex method from a non-static member function of the dialog box using the member-variable as follows and worked fine. ex:- void CSampleDlg::process(void) { m_myportcontroller.Close(); } But i need to call the portcontroller methods from a static member function of a dialog based application (MFC). ex:- static void CSampleDlg::process(void) { m_myporcontroller.Close(); // Not accessible because static function } Please send sample code of how to access the methods from static function. Very urgently needed.Early reply is appreciatable. Awaiting for the reply, I had a problem in accessing Activex control methods from a static function

                R Offline
                R Offline
                Roger Stoltz
                wrote on last edited by
                #7

                Why does the function have to be static? Some kind of callback? A lot of callbacks takes a LPVOID parameter which can be used to provide the this-pointer and in the static member function type cast it so that it's possible to access non-static member variables and functions. -- Roger


                It's supposed to be hard, otherwise anybody could do it!

                V 1 Reply Last reply
                0
                • V Vinaya

                  Static member data need to be defined outside the class declaration. You can declare the CPortController member variable as static. static CPortController m_myportcontroller ; In the CSampleDlg cpp file, define the static variable as

                  CPortController CSampleDlg::m_myportcontroller;
                  

                  Vini

                  V Offline
                  V Offline
                  vanip
                  wrote on last edited by
                  #8

                  Thanks Vini, i implemented , but getting comple errors. Can u specify in more detail???? please!!!

                  V 1 Reply Last reply
                  0
                  • R Roger Stoltz

                    Why does the function have to be static? Some kind of callback? A lot of callbacks takes a LPVOID parameter which can be used to provide the this-pointer and in the static member function type cast it so that it's possible to access non-static member variables and functions. -- Roger


                    It's supposed to be hard, otherwise anybody could do it!

                    V Offline
                    V Offline
                    vanip
                    wrote on last edited by
                    #9

                    Thanks Roger, The function is to be static because, i am calling this process function in a thread. How to pass the LPVOID parameter to this process function??

                    R 1 Reply Last reply
                    0
                    • V vanip

                      Thanks Roger, The function is to be static because, i am calling this process function in a thread. How to pass the LPVOID parameter to this process function??

                      R Offline
                      R Offline
                      Roger Stoltz
                      wrote on last edited by
                      #10

                      The thread controlling function can be a non-static member of the class. When you spawn the new thread with e.g. AfxbeginThread, you should pass the this-pointer as the LPVOID parameter. Your thread controlling function takes a LPVOID as argument which would now be your this-pointer. Type cast it and you'll be able to access both non-static member variables and functions from your thread. Joe Newcomer has written a very nice article about threading that I strongly recommend everyone who is doing multithreading. You'll find it here[^]. He's got a lot of very useful tips, tricks and how-to's on his site. When you're done with the threading stuff, a new problem may occur depending on how your ActiveX works. If you plan to use COM objects from a thread you have to initialize COM for that thread by a call to ::CoInitialize or similar. This sets up a new apartment. Now you have another problem: you can't cross apartment boundaries without marshalling the COM interface. Have a look at ::CoMarshalInterThreadInterfaceInStream and ::CoGetInterfaceAndReleaseStream for info about how to do that. This is the correct way to do this. You have to marshal the interface. There are no shortcuts. Post again if you have more troubles. If they are COM/ActiveX related, post your query in the COM forum. Hope this helps -- Roger


                      It's supposed to be hard, otherwise anybody could do it!

                      1 Reply Last reply
                      0
                      • V vanip

                        Thanks Vini, i implemented , but getting comple errors. Can u specify in more detail???? please!!!

                        V Offline
                        V Offline
                        Vinaya
                        wrote on last edited by
                        #11

                        What are the compile errors you are getting? Specify the exact error messages, if possible. Vini

                        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