Hi Jerry,
Thank you for sharing the two article links about COM interop.
As you already discovered, the first interface will be the default
interface, and VB6 intellisense only works for the default interface.
I think manually use the attributes instead of ComClass attribute is
preferred if you're concerned about the version compatibility issue that
the ComClass may suffer; since ComClass attribute still generates the
interface on your behalf, explicitly control the interface and DispId
certainly put everything under your control.
In case you haven't read following article, it's worth reading:
http://www.dotnetinterop.com/faq/?q=ClassInterface
Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Walter Wang [MSFT] - 29 Jan 2007 09:20 GMT
Hi Jerry,
As for the exception handling, the COM client will get the error message
when an exception is thrown from a method exposed from .NET COM component.
For example:
<Guid("542FA6CF-F2C8-46d3-8601-EF370BBEF146")> _
<InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _
Public Interface ILogging
Property LogToFile() As Boolean
Sub Log(ByVal text As String)
End Interface
Public Sub Log(ByVal text As String) Implements ILogging.Log
If String.IsNullOrEmpty(text) Then
Throw New ArgumentException("text cannot be empty")
End If
End Sub
Calling this Log method from VB6 with .Log("") will correctly capture the
error message "text cannot be empty" in Err.
However, this mechanism does have a caveat as described here:
#Interop: Get Seamless .NET Exception Logging From COM Clients Without
Modifying Your Code -- MSDN Magazine, January 2005
http://msdn.microsoft.com/msdnmag/issues/05/01/ExceptionLogging/default.aspx
Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
JerryWEC - 30 Jan 2007 19:17 GMT
Hi all!
I have another question related to COM InterOp...
I have this one event that was originally designed to sent back an exception
object. Is there anyway to MarshalAs as string the execption object or some
way to send back the ex.Message concatinated with the ex.stacktrace? Or do
I have to change my .net code to accomadate COM?
TIA, JerryM
Walter Wang [MSFT] - 31 Jan 2007 03:41 GMT
Hi Jerry,
MarshalAs attribute will be used to help the marshaler understand what the
native memory layout is supposed to look like. It will not be used to help
concat two strings. Also, the article I mentioned in my last reply clearly
states that getting the stack trace from .NET is tricky.
Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.