Assembly --> ActiveX: problem #2

neodatatype

Well-known member
Joined
Aug 18, 2003
Messages
68
Location
Italy
Thanks to VolteFace (and some days of imprecation for the non/not good-documentation about it) I solved the problem #1.

Now the #2 :)

I created in my exported class a property like this:
C#:
	object p_Value;
	public object Value
	{
		get { return p_Value; }
		set { this.p_Value = value; }
	}

As you can see is an object type, that will correctly converted to a Variant COM type.

All works well, but if I do this from VB6
Code:
	myObj.Value = 123

I get the VB error "Object required" 424.

It works if I use this:
C#:
	public void SetValue(object value)
	{
		this.p_Value = value;
	}
Code:
	Call myObj.SetValue(123)

I dont understand why.

Someone can tell me?

Thanks
 
I dont know whats going on at your end, but I cant create an exported property of type Object - it wont let me, and gives me a build error when I attempt it. It may simply be exporting the property as read-only on your end, which might result in the error youre talking about.

If youve got the VS 6.0 Tools installed (theyre in the VS 6.0 Start Menu Folder, under "Visual Studio 6.0 Tools"), run the OLE View tool, and using the "Open Typelib" button, open the TLB that .NET created. Look for the definition of your property.

In my test project, I created an Object called ComObject with an Integer property called ComProperty. The IDL looks like this:
Code:
    interface _ComObject : IDispatch {
        [id(0x00000001), propget]
        HRESULT ComProperty([out, retval] long* pRetVal);
        [id(0x00000001), propput]
        HRESULT ComProperty([in] long pRetVal);
    };
Find the definition of your property, and paste it here.
 
I dont know whats going on at your end, but I cant create an exported property of type Object - it wont let me, and gives me a build error when I attempt it. It may simply be exporting the property as read-only on your end, which might result in the error youre talking about.

I have no errors compiling the C# code, and from VB6 if I do an "object-assignement" like
Code:
Set myObj.Value = Form1
it works!
It doesnt work with non-objects

Here is the TLB of the class:

C#:
    interface _neoVariable : IDispatch {
        [id(0x60020000), propget,
            custom({54FC8F55-38DE-4703-9C4E-250351302B1C}, "1")]
        HRESULT _stdcall ToString([out, retval] BSTR* pRetVal);
        [id(0x60020001)]
        HRESULT _stdcall Equals(
                        [in] VARIANT obj,
                        [out, retval] VARIANT_BOOL* pRetVal);
        [id(0x60020002)]
        HRESULT _stdcall GetHashCode([out, retval] long* pRetVal);
        [id(0x60020003)]
        HRESULT _stdcall GetType([out, retval] _Type** pRetVal);
        [id(0x60020004), propget]
        HRESULT _stdcall Name([out, retval] BSTR* pRetVal);
        [id(00000000), propget]
        HRESULT _stdcall value([out, retval] VARIANT* pRetVal);
        [id(00000000), propputref]
        HRESULT _stdcall value([in] VARIANT pRetVal);
        [id(0x60020007)]
        HRESULT _stdcall SetValue([in] VARIANT value);
        [id(0x60020008)]
        HRESULT _stdcall ToInt32([out, retval] long* pRetVal);
        [id(0x60020009)]
        HRESULT _stdcall ToDouble([out, retval] double* pRetVal);
        [id(0x6002000a)]
        HRESULT _stdcall ToBoolean([out, retval] VARIANT_BOOL* pRetVal);
        [id(0x6002000b)]
        HRESULT _stdcall ToDateTime([out, retval] DATE* pRetVal);
    };
I cannot read this, but as you see the Value property is read/write, also if I doesnt understand why the "out" as a VARIANT* and the "in" a simple VARIANT.

Thanx again!
 
C# probably has less of a problem with exporting objects than VB.NET does for some reason, but that is indeed the way its supposed to look. Im not sure if .NET can automatically export VB6 VARIANTS, but to make it work, youll need to modify the IDL so both of them take VARIANT* (pointers to variants), rather than just the Property Get, and also change the Property Let definition to [in, out] -
Code:
    interface _ComClass : IDispatch {
        [id(0x68030000), propput]
        HRESULT ComProperty([in, out] VARIANT* );
        [id(0x68030000), propget]
        HRESULT ComProperty([out, retval] VARIANT* );
    };
You can use OLE View to save the IDL, where you can edit it. Then use the MIDL compiler located at C:\Program Files\Microsoft Visual Studio .NET\Common7\Tools\Bin\midl.exe to compile the IDL into a TLB. Its a command line program, so youll need the DOS Prompt to use it.
Code:
midl myfile.idl /out C:\
will compile the IDL and output it to C:\

Youll probably have to overwrite the TLB .NET generated with the new one.
 
Last edited by a moderator:
Back
Top