Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

COM object access

This has probably been covered already but I have a "legacy" COM object that
connects to a remote server using standard TCP/IP sockets. I don't know
enough C# to recode the object in C# so I would like to call the interfaces
and methods from an ASP+ page using C#. Right now I can use JScript or
VBScript like:

set avo = GetObject("Foo.1:system!user!password")
set avd = avo.Directory(".")
for each item in avd
out item.Name
next
set avo = nothing
set avd = nothing

How would I do the same thing with C#? Sorry of it is in the documentation
somewhere, I just could not find it.

Thank you.

Kevin Burton
kevin.burton@inewsroom.com
[717 byte] By [Kevin Burton] at [2007-11-9 18:22:24]
# 1 Re: COM object access
In the VS7 IDE, you just add a reference to your COM DLL or EXE, add the
namespace,
and use new to create an object. What this does is create a .NET wrapper
for your COM object.
The wrapper will do things like encapsulate HRESULT return values into
exceptions. You should
see the wrapper's method signatures become active in CodeSense when you add
a using statement
for the namespace that gets generated.

You'll also see a new DLL in your bin\Debug or bin\Release folder, which is
the .NET wrapper.
You can run "ildasm.exe FooLib.dll" to see the metadata for the wrapper, so
you know what the
namespace is that you'll need to import, and so on (although the namespace
will usually be the same
as the reference name that is added to your project).

If you are doing this from the command line, run "tlbimp.exe myComLib.dll",
which will generate the
wrapper assembly, which you can add as a reference to VS7 projects or to C#
command lines just
like any other assembly.

The objects can then be used as if they were .NET objects, ie. use new to
create them.

Gordon Hogenson
Visual C++/C# Team
Microsoft

"Kevin Burton" <kevin.burton@avstarnews.com> wrote in message
news:39d3d7c4$1@news.dev-archive.com...
> This has probably been covered already but I have a "legacy" COM object
that
> connects to a remote server using standard TCP/IP sockets. I don't know
> enough C# to recode the object in C# so I would like to call the
interfaces
> and methods from an ASP+ page using C#. Right now I can use JScript or
> VBScript like:
>
> set avo = GetObject("Foo.1:system!user!password")
> set avd = avo.Directory(".")
> for each item in avd
> out item.Name
> next
> set avo = nothing
> set avd = nothing
>
> How would I do the same thing with C#? Sorry of it is in the documentation
> somewhere, I just could not find it.
>
> Thank you.
>
> Kevin Burton
> kevin.burton@inewsroom.com
>
>
Gordon Hogenson at 2007-11-11 22:27:45 >