calling Activex methods from a static function--Dialog-based application

i am using an Activex control in a dialog based applicaton(VC++). i created an member variable for that(myportcontroller). In an non-static function i am able to call the Activex control methods using the member variable and worked fine. But i need to call the activex control methods in an static function. Here i cannot use the member variable as it is a static function. So, i declared an object for Activex control class. Using that object i called the methods. I had no compile time error. But i am getting run time assertion error as "winocc.cpp line:345". Can anybody help I need very urgently. i will be very much thankful for the helper. Waiting for the solution.


Answer this question

calling Activex methods from a static function--Dialog-based application

  • Exiton

    Looks like you are invoking a method on the ActiveX object without creating it.

    vani paruchuri wrote:

    Thank q mr. martin Ritcher,

    The project is created as an dialog-based MFC appl. I am using a thread which invokes a static function of that dialog box. In the static function i need to call activex control method. During compile time no errors. But during run time i got assertion error from the activex control method call statement.

    ex: static UINT CSampleDlg::thread1(LPVOID param);

    static void CSampleDlg::process(..);

    UINT CSampleDlg::thread1(LPVOID param)

    {

    process(.....);

    return 0;

    }

    void CSampleDlg::process(....);

    {

    ActivexClass ac;

    ac.Method();//---i am getting assertion error from this statement during run time as "File:winocc.cpp,Line:345"

    }

    Please help me in solving this. If any information is needed i will provide.

    Awaiting for the reply,

    Thanks.



  • Green Bird

    Thank q mr. martin Ritcher,

    The project is created as an dialog-based MFC appl. I am using a thread which invokes a static function of that dialog box. In the static function i need to call activex control method. During compile time no errors. But during run time i got assertion error from the activex control method call statement.

    ex: static UINT CSampleDlg::thread1(LPVOID param);

    static void CSampleDlg::process(..);

    UINT CSampleDlg::thread1(LPVOID param)

    {

    process(.....);

    return 0;

    }

    void CSampleDlg::process(....);

    {

    ActivexClass ac;

    ac.Method();//---i am getting assertion error from this statement during run time as "File:winocc.cpp,Line:345"

    }

    Please help me in solving this. If any information is needed i will provide.

    Awaiting for the reply,

    Thanks.


  • George R.

    100% ACK to Nishant's comment

  • siwel_nerrad

    Thanks for nishant and martin,

    Does the statement ,

    ActivexClass ac; create object for my activex class in the above sample code

    Please help how to create ,if not

    Awaiting for the solution.


  • henniman

    If done correctly. The ActiveX control is created by the MFC code after creation of the dialog.

  • cheryl Scott

    Hello Mr.Martin,

    I tried this way to get the pointer in the process function of above code.

    CSampleDlg* m=(CSampleDlg*)AfxGetMainWnd();

    m->m_myportcontroller.Close();

    Where m_myportcontroller is a member variable for activex control.

    I didn't used any CreateInstance function for activex control.

    If i made the process function as non-static,

    m_myportcontroller.Close(); worked without any problem.

    This is an MFC dialog based application. I just placed the activex control on to the dialog box. Created an member variable for that control using class-wizard.

    Is the pointer creation wrong If so, please specify how to get pointer for that activex control object.


  • Carflo

    ASSERT's are warning that point you to inconsistencies in the code that might lead into more and greater problems.

    In Release mode there is no debug code, and no asserts! So the problem is still existant!

    Tell us more about your program, as I wrote.



  • sz2080

    You always need a pointer to a dialog instance! You can never access a non-static member of a class without having a pointer/reference to it.

    Why is there need to do this I see a design problem in your ideas without knowing it

    Don't post duplicates!!!



  • guyfe

    It worked when i runned the application in win32 release mode. I didn't get the error , without any change in my code. But how is that possible Anybody know
  • citykid

    No it does not create the object. It is an instance of the class. But the active X Control usually needs CreateInstance. But this is not your problem as far as I understand your problem.

    You already have an instance of this class. You need th epointer to the existing one.



  • ablack

    Whats the wrong here Can u please specify

    We are using portcontroller control in vc++. IF i call portcontroller methods thru member variable (m_myportcontroller) there was no problem. The activex control is derived from CWnd class.

    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 calling from static function , Compilation error
    CPortController cp;
    cp.Close(); //Getting run time assertion error , file:winocc.cpp,Line:345
    CSampleDlg* m=(CSampleDlg*)AfxGetMainWnd();
    m->m_myportcontroller.Close();//Getting run time Assertion error file:wincrl.cpp Line:980
    }
    Please specify sample code of how to access the methods from static function.


  • calling Activex methods from a static function--Dialog-based application