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 / March 2005

Tip: Looking for answers? Try searching our database.

Using calling .NET dll from VB6

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michael--J - 23 Mar 2005 08:13 GMT
Hi,

We have a legacy application (which is quite complex and large) written in
VB6. We are currently upgrading it and enhancing its functionalities. We have
also adopted .NET as our new development evironment. As a result of this, the
upgraded version of our application contains code which calls .NET dlls. This
was quite a challenge for us because we had never used interop abilities from
COM->.NET... it was usually the other way around.

The application at the moment has this really strange bug that occurs once
in a blue moon it's happened about 3 times in the past 2 weeks). A 3rd party
component written in C# is being used by the VB6 application to access a
keyboard smart card reader. It usually works most of the time, however, on
rare occassions, the application is unable to connect to the keyboard by
calling the C# dll's Connect() method. It comes up with this exception (of
which i cannot remember). We wrote a little test app in C# that uses the 3rd
party dll to connect to the keyboard and it works fine, suggesting to us that
it is an Interop issue. We're thinking that some resources or objects
accessed form the .NET dll may have not been disposed or something....??

As a general question, is it recommended for developers to exploit the
advantages of COM Interop during the migration from unmanaged to managed
code? Would it be ideal for us to start from scratch and write everything in
.NET? I understand that this would depend greatly on the size of the
application and the available time, but what would you do? What suggestions
do the more experienced developers have for the less experienced? Thanks.

Michael--J.
Mike Jansen - 23 Mar 2005 22:49 GMT
From everything I have read and even attempted, hosting controls written in
.NET as ActiveX controls is NOT supported by Microsoft, so its interesting
to hear that you are using a commercial product that does this.  I would ask
the developer of that product to document that what they are doing is
supported by Microsoft.

I have been researching and experimenting with creating a .NET ActiveX
control myself which is why I am fairly familiar with it being unsupported.
If in your research you find otherwise, I would be very happy to hear about
it.  I've currently got a control working except that events fired from the
control are: 1) not being received in VB6, and 2) causing an
NotImplementedException to be thrown in Visual FoxPro (I'm assuming the same
thing is happening in VB except that VB handles the exception differently).
Michael--J - 23 Mar 2005 23:41 GMT
Hi Mike,

If you check this site:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/c
allnetfrcom.asp
,
i believe that it is supported and was intended to allow developers to slowly
migrate from COM to .NET. Thanks.

> From everything I have read and even attempted, hosting controls written in
> ..NET as ActiveX controls is NOT supported by Microsoft, so its interesting
[quoted text clipped - 9 lines]
> NotImplementedException to be thrown in Visual FoxPro (I'm assuming the same
> thing is happening in VB except that VB handles the exception differently).
Mike Jansen - 24 Mar 2005 14:29 GMT
Calling .NET _components_ (akin to ActiveX/COM .DLLs or .EXEs) via COM
wrappers is supported through interop.  Using visual .NET _user controls_
(akin to ActiveX .OCX) with a COM wrapper is NOT supported, from what I
understand.  I skimmed that article you linked to and nowhere is there a
user control used as the example.  The ActiveX Control (an OCX vs just a
.DLL or .EXE) seems to be a superset of plain old COM component
functionality.  The "extra" stuff required to make a visual control work
does not seem to be fully supported in .NET interop.  The only place it
seems to be supported is when hosting the control in Internet Explorer.

Here's a few links to support what I'm saying:

http://www.ondotnet.com/pub/a/dotnet/2003/01/20/winformshosting.html
http://www.c-sharpcorner.com/Code/2003/March/ActiveXInNet.asp
http://www.eggheadcafe.com/ng/microsoft.public.dotnet.framework.interop/post2022
8888.asp


Here's a killer link on a post from Microsoft (its 2001, but I haven't heard
anything different from MS since then):
http://discuss.develop.com/archives/wa.exe?A2=ind0107b&L=dotnet&F=&S=&P=16992

I have this same problem.  It's probably describing some of the
programmability issues Microsoft mentioned in the previous link:
http://www.dotnet247.com/247reference/msgs/30/150026.aspx

> Hi Mike,
>
> If you check this site:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/c
allnetfrcom.asp
,
> i believe that it is supported and was intended to allow developers to slowly
> migrate from COM to .NET. Thanks.
[quoted text clipped - 12 lines]
> > NotImplementedException to be thrown in Visual FoxPro (I'm assuming the same
> > thing is happening in VB except that VB handles the exception differently).
Michael--J - 29 Mar 2005 02:55 GMT
I see what you mean Mike: User Controls created in .NET cannot be "called"
from VB6 using COM. Ok. Fortunately that is not what we are trying to
achieve. We are only calling a .NET dll from VB6 using COM.

Would you have any idea as to what causes the problem i mentioned in my
fisrt post - given that we are calling a .NET dll rather than a .NET User
Control? Thanks.

Michael--J.

> Calling .NET _components_ (akin to ActiveX/COM .DLLs or .EXEs) via COM
> wrappers is supported through interop.  Using visual .NET _user controls_
[quoted text clipped - 50 lines]
> > > thing is happening in VB except that VB handles the exception
> differently).
EggHead - 29 Mar 2005 19:28 GMT
haha, how can we help you if you do not remember the exception.
It seems that the dll can not get the handle of the KB at that moment or you
do not dispose the ref first. In addition, how can you know the test app in
C# works in a blue moon night as well :)
haha, M$ would like you to do everything in .Net

Egghead

> Hi,
>
[quoted text clipped - 33 lines]
>
> Michael--J.
Michael--J - 30 Mar 2005 01:17 GMT
Well the reason why i can't remember the exception is because i'm not the one
actually writing the app - one of my colleagues simply asked me to help him
out about a particular problem he'd been having, and he could not actually
recall the exact exception message, but he described to me what was happening.

I told him, next time the exception takes place, make sure you get the
exception message. The exception happened again, and this time he only got a
portion of the message - the string was apparently incomplete. This was it:

"System.InvalidOperationException: Operation is not valid due to the current
state of the object.
  at Subsembly.SmartCard.PcSc.SCardComm.Connect(String sReader,
SCardAccessMode nAccessMode, SCardProtocolIdentifiers nPreferredProtocols)
  at PCSC_O"

Apart from the C# test app, we also have another C# app realesed
commercially that uses the same .NET dll. We have had no problems with that
at all. Thanks.

Michael--J.

> haha, how can we help you if you do not remember the exception.
> It seems that the dll can not get the handle of the KB at that moment or you
[quoted text clipped - 41 lines]
> >
> > Michael--J.

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.