GetIDispatchForObject / exposing an object to a scripting client

M

mclp

I have an object created within a C++/CLI class library that I want to
expose to a VBScript client. The class is declared as:
[ClassInterface(ClassInterfaceType::AutoDispatch)]
public ref class Foo
{
public:
// some methods...
};

The object is constructed using
Foo^ foo = gcnew Foo;

Then I try to get the COM/IDispatch interface to expose to Windows
Scripting Host, using:
Object^ my_obj = foo;
IntPtr aDisp = Marshal::GetIDispatchForObject(my_obj); //
InvalidCastException here!

This results in System.InvalidCastException. Any ideas why?
 
M

mclp

It's working now.. Seems I also needed to set attribute (I thought it
was the default):
[ComVisible(true)]
 
P

PLS

It's working now.. Seems I also needed to set attribute (I thought it
was the default):
[ComVisible(true)]
It WAS the default. It's not in VS2005. This is an improvement, IMHO,
although nasty if you didn't happen to read the section on breaking
changes.

++PLS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top