How do I implement an interface with VB.Net?

J

Jim

I am using VB.Net 2.0 and I am completely new to the concept of implementing
interfaces. Can anyone explain "implementing interfaces" to me and perhaps
give me an example of implementing an interface that would help me implement
the IIneternetSecurityManager interface mentioned under "Creating a
Customized URL Security Manager" on
http://msdn.microsoft.com/library/d...ity/szone/overview/overview.asp#SecurityZones
and mentioned under "Download Control" on
http://msdn.microsoft.com/library/d...owser/overview/overview.asp#Download_Control?

This would help me a great understand implementing interfaces and I could
then implement a few more for my company's internal webbrowser.

Thanks for your help!
 
W

Willy Denoyette [MVP]

Jim said:
I am using VB.Net 2.0 and I am completely new to the concept of
implementing interfaces. Can anyone explain "implementing interfaces" to
me and perhaps give me an example of implementing an interface that would
help me implement the IIneternetSecurityManager interface mentioned under
"Creating a Customized URL Security Manager" on
http://msdn.microsoft.com/library/d...ity/szone/overview/overview.asp#SecurityZones
and mentioned under "Download Control" on
http://msdn.microsoft.com/library/d...owser/overview/overview.asp#Download_Control?

This would help me a great understand implementing interfaces and I could
then implement a few more for my company's internal webbrowser.

Thanks for your help!


Why cross-post to a bunch of non appropriate NG's, please restrict your
postings to the vb NG only.

Willy.
 
W

W.G. Ryan - MVP

Jim:

In .NET we don't have multiple inheritance but by using interfaces, you can
get to the same place by and large. If I have an interface, then the
compiler knows that each fo the methods and properties must exist in the
class - it can count on them being there. So in it's simplest form,
implementing an interface is simply adding a property and method to your
class for each one in the interface. That way you can do this....

IList myObject = new ObjectThatImplementsIList();
myObject.Item(0) ; //b/c IList has Item

Now, by doing this, you can take an IList object as a paramater and then
pass in anything that implements IList b/c it effectively "is" an IList
object.

Does this help?
 
W

W.G. Ryan - MVP

Jim - if you would, shoot me an email to WilliamRyan at gmail dotcom - I
answered your question briefly below, but I have some material that you will
probably find helpful - it's too much to simply post but if you'll shoot me
a private email, I'll do what I can to help.
 
C

Cor Ligthert [MVP]

Jim,
Thank you for that most informative and helpful response.
I am glad that the help from Willy did help you, I was ready to make a reply
however now I see that it is not needed anymore.

Because of your answer I assume that the most of us think about it this way.

Cor
 
J

Jim

On it's way...

Thanks!

W.G. Ryan - MVP said:
Jim - if you would, shoot me an email to WilliamRyan at gmail dotcom - I
answered your question briefly below, but I have some material that you
will probably find helpful - it's too much to simply post but if you'll
shoot me a private email, I'll do what I can to help.
 
R

RCS

Yikes.

It might be helpful if you stuck to one question at a time and sent it to
one newsgroup. Crossposting is bad.

Interfaces require a bit of explanation. If you are not familiar, just ask.

HOW to implement them in VB (sorry to the other newsgroups), you do
something like this:

Public Class MyClass
Implements System.IFormattable

End Class

in C#, it's something like this:

public class MyClass : System.IFormattable
{
}

You will then obviously need to implement the members that the interface
describes.. hope that helps
 
R

RCS

If I didn't know any better, these look like C++ API's and I couldn't find a
..NET implementation of them.. so I would guess (based on a cursory glance)
that there isn't an easy way to use this functionality in VB without
wrapping it first..
 
J

Jim

Do you mean that you need to write a wrapper in C++ to expose this
functionality in VB.Net?
 
J

Jim

RCS said:
Yikes.

It might be helpful if you stuck to one question at a time and sent it to
one newsgroup. Crossposting is bad.

I only cross-posted because I knew that C/C++/C# programmers may hae the
information that I seek. Posting to the VB.Net ng could work, but since I
am talking about C++ APIs, I thought the groups selected were appropriate.

And, I have been taken to task for posting the same questions in separate
posts to separate groups because it evidentially eats up bandwidth for some
USENET users that pay for bandwidth usage.

In fact, based on those conversations, I thought that I was doing people a
favor by sending the question to several ngs at once rather than posting
separately to the ngs.

I don't know......I am just seeking knowledge wherever I can find it. Sorry
if I stepped on any toes in the process.
 
R

RCS

Well, basically - you'd need to make a .NET assembly that has this
functionality in it, so it will be easily accessible via VB. VB.NET can only
easily/natively see .NET and COM components. It can't see non-.NET or native
Win32 API's, without some coding.

There are almost always ways to use Win32 API's in non-C++ languages, but it
tends to be clumsy. Bottom line, if you know C++ - write a managed/.NET
assembly that exposes this functionality.. or, try to write a VB.NET
assembly that uses these API's directly. There will likely be no
documentation and nowhere to turn, except newsgroups, if you get stuck..

Good luck..
 
W

W.G. Ryan - MVP

Well it depejnds on the interface. If you're in the IDE, you can find out
the methods by hitting Tab after you use the Implements InterfaceName - this
will shell out all the methods for you. To implement the interface,create
your class and then use Implements and then the interface name, when you
hit tab, it will fill in the method stubs for you.
 
W

W.G. Ryan - MVP

Cor - I think it's safe to answer if you want to give it a shot - I suspect
Jim's answer may have been polite sarcasm.
 
C

Cor Ligthert [MVP]

Jim,

I think that we are talking about different interfaces.

As we are talking in VB.Net than an Interface describes a contract what a
class has to consist, which makes it possible to access that class using
that interface.

You have as well all kind of other Interfaces by instance a UI User
Interface what is totaly something different.

An Api Apllication Program Interface is an interface between your program
and the OS, however not seen as that when we talk about interfaces.

I first thought that you was asking for an Interface, now I understand that
you ask it for an API.

http://msdn.microsoft.com/library/d.../en-us/vbcn7/html/vaconCallingWindowsAPIs.asp

Probably it is better to start in one newsgroup (related to your expected
result) and give what you want it right name, if it is than wrong, people
will help you to a better newsgroup.

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top