Writing COM accesible objects in Managed C++
-
Im trying to create a Managed C++ object that will be accessible both from Managed Code, as well as through a standard COM interface. I have written the component and have no problems using it from JScript, so I moved on to attempting use through standard COM from Win32 App. When I export the type library from the assembly, it contains the definitions for the classes but not the interfaces?? For example if I built the following overly simplified managed code into an assembly
#include "stdafx.h" #using using namespace System; using namespace System::Reflection; using namespace System::Runtime::InteropServices; [assembly:AssemblyKeyFileAttribute("ComponentTest.snk")]; namespace TestNM { __gc __interface ITestComp { int GetNumber(); void SetNumber(int num); }; __gc public class MyTestComp : public ITestComp { public: MyTestComp() { m_iNumber = 0; } ~MyTestComp() {}; int GetNumber() {return m_iNumber; } void SetNumber(int num) { m_iNumber = num; } private: int m_iNumber; }; }
Then export the type library, and open with oleview, the definition of "ITestComp" interface is no where to be found, in fact it says MyTestComp is an interface??? Anyone have any ideas? Thanks! -
Im trying to create a Managed C++ object that will be accessible both from Managed Code, as well as through a standard COM interface. I have written the component and have no problems using it from JScript, so I moved on to attempting use through standard COM from Win32 App. When I export the type library from the assembly, it contains the definitions for the classes but not the interfaces?? For example if I built the following overly simplified managed code into an assembly
#include "stdafx.h" #using using namespace System; using namespace System::Reflection; using namespace System::Runtime::InteropServices; [assembly:AssemblyKeyFileAttribute("ComponentTest.snk")]; namespace TestNM { __gc __interface ITestComp { int GetNumber(); void SetNumber(int num); }; __gc public class MyTestComp : public ITestComp { public: MyTestComp() { m_iNumber = 0; } ~MyTestComp() {}; int GetNumber() {return m_iNumber; } void SetNumber(int num) { m_iNumber = num; } private: int m_iNumber; }; }
Then export the type library, and open with oleview, the definition of "ITestComp" interface is no where to be found, in fact it says MyTestComp is an interface??? Anyone have any ideas? Thanks!Hi tlemoine, You are right because
MyTestComp
IS an interface too!, what you need to do is tell the type library exporter that it shouldn't create a type library section forMyTestComp
. You need to add the following attribute... can't remember the exact syntax for MC++ though. Regards, Dark Angel -
Hi tlemoine, You are right because
MyTestComp
IS an interface too!, what you need to do is tell the type library exporter that it shouldn't create a type library section forMyTestComp
. You need to add the following attribute... can't remember the exact syntax for MC++ though. Regards, Dark AngelHere is the attribute again.... but visible this time <ClassInterface(ClassInterfaceType.None)>