problem access com methods - unhandled exception [modified]
-
i am stuck with one kind of problem when using COM . below are the details , i have written a class which has a com object as a member variable. i have different member function one will create the com object other members will access the functions of the com object. the problem comes when i am trying to access function of the com . here is sample example of my code class CMyclass { com variable; public: void createcomobject(); void accessfunctionofcomobject(); }; CMyclass::void createcomobject() { ::CoInitialize() CoCreateInstance(......); // Every this is fine and i was able to create the com object successuflly .. // every thing is fine and successfull. // successfull creates com object using cocreateinstance.. and we can call the memebers function of interface variable->method(); // successfully calls the members } CMYclass::accessfunctionofcomobject() { // application crashes when try to access com object functions variable->method(); // UNHANDLED EXPECTION } CMYclass *ptr; // This is gobal pointer variable.. // fun1 is a gobal function void fun1() { ptr->createcomobject(); } // fun2 is a gobal function void fun2() { ptr->obj.accessfunctionofcomobject(); //calling this funciton makes crash. } void main() { ptr = new CMYclass(); fun1(); // This function calls creates successful com object inside a class object. fun2(); // This function calls makes crash... } i want to know why the unhandled exception is raising
modified on Thursday, November 19, 2009 11:53 PM
-
i am stuck with one kind of problem when using COM . below are the details , i have written a class which has a com object as a member variable. i have different member function one will create the com object other members will access the functions of the com object. the problem comes when i am trying to access function of the com . here is sample example of my code class CMyclass { com variable; public: void createcomobject(); void accessfunctionofcomobject(); }; CMyclass::void createcomobject() { ::CoInitialize() CoCreateInstance(......); // Every this is fine and i was able to create the com object successuflly .. // every thing is fine and successfull. // successfull creates com object using cocreateinstance.. and we can call the memebers function of interface variable->method(); // successfully calls the members } CMYclass::accessfunctionofcomobject() { // application crashes when try to access com object functions variable->method(); // UNHANDLED EXPECTION } CMYclass *ptr; // This is gobal pointer variable.. // fun1 is a gobal function void fun1() { ptr->createcomobject(); } // fun2 is a gobal function void fun2() { ptr->obj.accessfunctionofcomobject(); //calling this funciton makes crash. } void main() { ptr = new CMYclass(); fun1(); // This function calls creates successful com object inside a class object. fun2(); // This function calls makes crash... } i want to know why the unhandled exception is raising
modified on Thursday, November 19, 2009 11:53 PM
Perhaps you are creating the COM object using one interface e.g. IUnknown or IMyInterface1 then, in your method, calling using another interface, say, IMyMethods interface which is not yet initialised? It's a bit hard to say any more without seeing more detail from yourself.
-
i am stuck with one kind of problem when using COM . below are the details , i have written a class which has a com object as a member variable. i have different member function one will create the com object other members will access the functions of the com object. the problem comes when i am trying to access function of the com . here is sample example of my code class CMyclass { com variable; public: void createcomobject(); void accessfunctionofcomobject(); }; CMyclass::void createcomobject() { ::CoInitialize() CoCreateInstance(......); // Every this is fine and i was able to create the com object successuflly .. // every thing is fine and successfull. // successfull creates com object using cocreateinstance.. and we can call the memebers function of interface variable->method(); // successfully calls the members } CMYclass::accessfunctionofcomobject() { // application crashes when try to access com object functions variable->method(); // UNHANDLED EXPECTION } CMYclass *ptr; // This is gobal pointer variable.. // fun1 is a gobal function void fun1() { ptr->createcomobject(); } // fun2 is a gobal function void fun2() { ptr->obj.accessfunctionofcomobject(); //calling this funciton makes crash. } void main() { ptr = new CMYclass(); fun1(); // This function calls creates successful com object inside a class object. fun2(); // This function calls makes crash... } i want to know why the unhandled exception is raising
modified on Thursday, November 19, 2009 11:53 PM
Please, specify what exception has occurred and how was initialized com variable
modified on Friday, November 27, 2009 4:23 PM