Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / October 2004

Tip: Looking for answers? Try searching our database.

Problem with Interop: .NET calling COM (works in Win2K, fails in NT4)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Innes - 14 Oct 2004 13:45 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.

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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.