I am instantiating a .NET class in a VB6 form.
The .NET class calls back to the VB6 form via a COM interface
implemented on the form, and defined in the .NET class's assembly.
This works fine in Windows 2000, but fails on the callback call in NT4.
When my .NET class attempts to call into VB6, I get an
InvalidCastException:
message="QueryInterface for interface ICallback failed."
Here's a summary of the contents of the .NET assembly:
[assembly: Guid(...)]
//Interface to be implemented by COM client that wants to receive
//callbacks (i.e, the VB6 form):
[Guid(...)]
public interface ICallback
{
void Notify(string message, ref string response);
}
// Interface with methods to allow a client to register itself for
//callbacks (the .NET Notifier class, below):
[Guid(...)]
public interface INotifier
{
void SetCallback(ICallback callback);
void ClearCallback();
}
//Notifier: a class that fires callbacks to a registered ICallback
[Guid(...)]
[ClassInterface(ClassInterfaceType.None)]
public class Notifier : INotifier
{
ICallback _callback;
void FireNotification(string message, ref string response)
{
_callback.Notify(message, response);
}
...
}
So, the VB6 form has no problem instantiating the .NET class, and
registering itself. If only fails when the .NET class attempts to call
the passed-in callback interface.
NB:
This only happens in NT4. In Windows 2000 and XP it works fine.
I was using COM Events to communicate from .NET to COM, instead of
registering a callback interface.
This worked fine in Win2000 and failed in NT4, so I moved to using
manual registration of an interface, rather than using connection
points, to see if this would fix the problem - it just resulted in a
different exception being thrown.
Innes - 14 Oct 2004 14:13 GMT
> I am instantiating a .NET class in a VB6 form.
> The .NET class calls back to the VB6 form via a COM interface
> implemented on the form, and defined in the .NET class's assembly.
>
> This works fine in Windows 2000, but fails on the callback call in
> NT4.
The cause was:
I was developing on Win2000, so VS.NET was exporting a TLB
for the .NET assembly, and registering this.
In NT, I was manually registering the assembly, using the command
"regasm <assembly>.dll".
When I changed this to "regasm /tlb <assembly>.dll", the problem
went away.