How to call non-COM legacy dll from ASP.NET -OR- write COM wrapper in C#

Discussion in 'ASP .Net' started by Chris Bordeman, Apr 10, 2008.

  1. Using VS2008.

    Have an old straight C style dll, need to call it from ASP.NET. This
    normally works easily using DllImport but ASP.NET apparently doesn't let you
    call C dlls directly.

    So I heard you can call COM dlls by just adding a reference. So I created a
    C# class library with a single class that wraps and calls my C dll through
    DllImport. I checked the 'Make COM Visibile' option and compiled. Used
    regasm.exe to register the dll w/ COM, which reported success.

    But I do 'add reference' on the ASP.NET app and the object is not to be
    found on the COM list.

    Isn't it supposed to show up?

    Is there a better way? Or a way to avoid COM altogether?
    Chris Bordeman, Apr 10, 2008
    #1
    1. Advertising

  2. http://www.java2s.com/Code/CSharp/Language-Basics/CallingNativeDLLFunctions.htm

    --
    Gregory A. Beamer
    MVP, MCP: +I, SE, SD, DBA

    Subscribe to my blog
    http://gregorybeamer.spaces.live.com/lists/feed.rss

    or just read it:
    http://gregorybeamer.spaces.live.com/

    *************************************************
    | Think outside the box!
    |
    *************************************************
    "Chris Bordeman"
    <>
    wrote in message news:...
    > Using VS2008.
    >
    > Have an old straight C style dll, need to call it from ASP.NET. This
    > normally works easily using DllImport but ASP.NET apparently doesn't let
    > you call C dlls directly.
    >
    > So I heard you can call COM dlls by just adding a reference. So I created
    > a C# class library with a single class that wraps and calls my C dll
    > through DllImport. I checked the 'Make COM Visibile' option and compiled.
    > Used regasm.exe to register the dll w/ COM, which reported success.
    >
    > But I do 'add reference' on the ASP.NET app and the object is not to be
    > found on the COM list.
    >
    > Isn't it supposed to show up?
    >
    > Is there a better way? Or a way to avoid COM altogether?
    >
    Cowboy \(Gregory A. Beamer\), Apr 10, 2008
    #2
    1. Advertising

  3. OK I though I was really clear I *know* how to do basic native DLL calls.
    ASP.NET doesn't allow DllImport and can only call .Net code directly.
    THAT'S the problem.

    I appreciate your response, but please read the question in it's entirety
    before answering.

    (I knew someone would do this <g>)


    "Cowboy (Gregory A. Beamer)" <> wrote in
    message news:...
    > http://www.java2s.com/Code/CSharp/Language-Basics/CallingNativeDLLFunctions.htm
    >
    > --
    > Gregory A. Beamer
    > MVP, MCP: +I, SE, SD, DBA
    >
    > Subscribe to my blog
    > http://gregorybeamer.spaces.live.com/lists/feed.rss
    >
    > or just read it:
    > http://gregorybeamer.spaces.live.com/
    >
    > *************************************************
    > | Think outside the box! |
    > *************************************************
    > "Chris Bordeman"
    > <>
    > wrote in message news:...
    >> Using VS2008.
    >>
    >> Have an old straight C style dll, need to call it from ASP.NET. This
    >> normally works easily using DllImport but ASP.NET apparently doesn't let
    >> you call C dlls directly.
    >>
    >> So I heard you can call COM dlls by just adding a reference. So I
    >> created a C# class library with a single class that wraps and calls my C
    >> dll through DllImport. I checked the 'Make COM Visibile' option and
    >> compiled. Used regasm.exe to register the dll w/ COM, which reported
    >> success.
    >>
    >> But I do 'add reference' on the ASP.NET app and the object is not to be
    >> found on the COM list.
    >>
    >> Isn't it supposed to show up?
    >>
    >> Is there a better way? Or a way to avoid COM altogether?
    >>

    >
    >
    Chris Bordeman, Apr 10, 2008
    #3
  4. Chris Bordeman

    Jeff Dillon Guest

    Add a direct reference (Browse, locate the COM dll, etc)

    Jeff
    "Chris Bordeman"
    <>
    wrote in message news:...
    > Using VS2008.
    >
    > Have an old straight C style dll, need to call it from ASP.NET. This
    > normally works easily using DllImport but ASP.NET apparently doesn't let
    > you call C dlls directly.
    >
    > So I heard you can call COM dlls by just adding a reference. So I created
    > a C# class library with a single class that wraps and calls my C dll
    > through DllImport. I checked the 'Make COM Visibile' option and compiled.
    > Used regasm.exe to register the dll w/ COM, which reported success.
    >
    > But I do 'add reference' on the ASP.NET app and the object is not to be
    > found on the COM list.
    >
    > Isn't it supposed to show up?
    >
    > Is there a better way? Or a way to avoid COM altogether?
    >
    Jeff Dillon, Apr 10, 2008
    #4
  5. As I said, I tried to create one and then registered it using regasm.exe
    (which supposedly succeeded) but for whatever reason now I don't see jack on
    the COM list on the 'Add Reference' window.


    "Jeff Dillon" <> wrote in message
    news:...
    > Add a direct reference (Browse, locate the COM dll, etc)
    >
    > Jeff
    > "Chris Bordeman"
    > <>
    > wrote in message news:...
    >> Using VS2008.
    >>
    >> Have an old straight C style dll, need to call it from ASP.NET. This
    >> normally works easily using DllImport but ASP.NET apparently doesn't let
    >> you call C dlls directly.
    >>
    >> So I heard you can call COM dlls by just adding a reference. So I
    >> created a C# class library with a single class that wraps and calls my C
    >> dll through DllImport. I checked the 'Make COM Visibile' option and
    >> compiled. Used regasm.exe to register the dll w/ COM, which reported
    >> success.
    >>
    >> But I do 'add reference' on the ASP.NET app and the object is not to be
    >> found on the COM list.
    >>
    >> Isn't it supposed to show up?
    >>
    >> Is there a better way? Or a way to avoid COM altogether?
    >>

    >
    >
    Chris Bordeman, Apr 11, 2008
    #5
  6. Chris Bordeman

    Jeff Dillon Guest

    Now YOU didn't read my message. You need to Browse for it...it might not
    show in the list

    Jeff
    "Chris Bordeman"
    <>
    wrote in message news:...
    > As I said, I tried to create one and then registered it using regasm.exe
    > (which supposedly succeeded) but for whatever reason now I don't see jack
    > on the COM list on the 'Add Reference' window.
    >
    >
    > "Jeff Dillon" <> wrote in message
    > news:...
    >> Add a direct reference (Browse, locate the COM dll, etc)
    >>
    >> Jeff
    >> "Chris Bordeman"
    >> <>
    >> wrote in message news:...
    >>> Using VS2008.
    >>>
    >>> Have an old straight C style dll, need to call it from ASP.NET. This
    >>> normally works easily using DllImport but ASP.NET apparently doesn't let
    >>> you call C dlls directly.
    >>>
    >>> So I heard you can call COM dlls by just adding a reference. So I
    >>> created a C# class library with a single class that wraps and calls my C
    >>> dll through DllImport. I checked the 'Make COM Visibile' option and
    >>> compiled. Used regasm.exe to register the dll w/ COM, which reported
    >>> success.
    >>>
    >>> But I do 'add reference' on the ASP.NET app and the object is not to be
    >>> found on the COM list.
    >>>
    >>> Isn't it supposed to show up?
    >>>
    >>> Is there a better way? Or a way to avoid COM altogether?
    >>>

    >>
    >>

    >
    >
    Jeff Dillon, Apr 11, 2008
    #6
  7. I read that, but remember this is a .Net DLL with COM interfaces so loading
    it by file just gets you a .Net reference. If it's gonna be seen by VS as
    COM, it needs to be loaded via the COM list.

    I've abandoned the COM route, looking for a a way to do this via remoting.

    Thanks for your help.

    "Jeff Dillon" <> wrote in message
    news:...
    > Now YOU didn't read my message. You need to Browse for it...it might not
    > show in the list
    >
    > Jeff
    > "Chris Bordeman"
    > <>
    > wrote in message news:...
    >> As I said, I tried to create one and then registered it using regasm.exe
    >> (which supposedly succeeded) but for whatever reason now I don't see jack
    >> on the COM list on the 'Add Reference' window.
    >>
    >>
    >> "Jeff Dillon" <> wrote in message
    >> news:...
    >>> Add a direct reference (Browse, locate the COM dll, etc)
    >>>
    >>> Jeff
    >>> "Chris Bordeman"
    >>> <>
    >>> wrote in message news:...
    >>>> Using VS2008.
    >>>>
    >>>> Have an old straight C style dll, need to call it from ASP.NET. This
    >>>> normally works easily using DllImport but ASP.NET apparently doesn't
    >>>> let you call C dlls directly.
    >>>>
    >>>> So I heard you can call COM dlls by just adding a reference. So I
    >>>> created a C# class library with a single class that wraps and calls my
    >>>> C dll through DllImport. I checked the 'Make COM Visibile' option and
    >>>> compiled. Used regasm.exe to register the dll w/ COM, which reported
    >>>> success.
    >>>>
    >>>> But I do 'add reference' on the ASP.NET app and the object is not to be
    >>>> found on the COM list.
    >>>>
    >>>> Isn't it supposed to show up?
    >>>>
    >>>> Is there a better way? Or a way to avoid COM altogether?
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
    Chris Bordeman, Apr 11, 2008
    #7
  8. Chris Bordeman

    Jeff Dillon Guest

    Does this help?

    http://support.microsoft.com/kb/306158


    "Chris Bordeman"
    <>
    wrote in message news:eph$...
    >I read that, but remember this is a .Net DLL with COM interfaces so loading
    >it by file just gets you a .Net reference. If it's gonna be seen by VS as
    >COM, it needs to be loaded via the COM list.
    >
    > I've abandoned the COM route, looking for a a way to do this via remoting.
    >
    > Thanks for your help.
    >
    > "Jeff Dillon" <> wrote in message
    > news:...
    >> Now YOU didn't read my message. You need to Browse for it...it might not
    >> show in the list
    >>
    >> Jeff
    >> "Chris Bordeman"
    >> <>
    >> wrote in message news:...
    >>> As I said, I tried to create one and then registered it using regasm.exe
    >>> (which supposedly succeeded) but for whatever reason now I don't see
    >>> jack on the COM list on the 'Add Reference' window.
    >>>
    >>>
    >>> "Jeff Dillon" <> wrote in message
    >>> news:...
    >>>> Add a direct reference (Browse, locate the COM dll, etc)
    >>>>
    >>>> Jeff
    >>>> "Chris Bordeman"
    >>>> <>
    >>>> wrote in message news:...
    >>>>> Using VS2008.
    >>>>>
    >>>>> Have an old straight C style dll, need to call it from ASP.NET. This
    >>>>> normally works easily using DllImport but ASP.NET apparently doesn't
    >>>>> let you call C dlls directly.
    >>>>>
    >>>>> So I heard you can call COM dlls by just adding a reference. So I
    >>>>> created a C# class library with a single class that wraps and calls my
    >>>>> C dll through DllImport. I checked the 'Make COM Visibile' option and
    >>>>> compiled. Used regasm.exe to register the dll w/ COM, which reported
    >>>>> success.
    >>>>>
    >>>>> But I do 'add reference' on the ASP.NET app and the object is not to
    >>>>> be found on the COM list.
    >>>>>
    >>>>> Isn't it supposed to show up?
    >>>>>
    >>>>> Is there a better way? Or a way to avoid COM altogether?
    >>>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
    Jeff Dillon, Apr 11, 2008
    #8
  9. Let me see if I have it right.

    DLL in question is C.
    You need to call it from ASP.NET.

    If so the article is correct. You may have to wrap the DLL in a .NET
    library, but it should work. WIth ASP.NET it should also be able to be
    called from a ASP.NET web application instead of a ASP.NET web site. If it
    does not work, wrap it.

    I see no reason to wrap in .NET and then create a COM callable wrapper and
    then call that. It creates something twice removed instead of something once
    removed.

    Am I still missing something?

    --
    Gregory A. Beamer
    MVP, MCP: +I, SE, SD, DBA

    Subscribe to my blog
    http://gregorybeamer.spaces.live.com/lists/feed.rss

    or just read it:
    http://gregorybeamer.spaces.live.com/

    *************************************************
    | Think outside the box!
    |
    *************************************************
    "Chris Bordeman"
    <>
    wrote in message news:...
    > OK I though I was really clear I *know* how to do basic native DLL calls.
    > ASP.NET doesn't allow DllImport and can only call .Net code directly.
    > THAT'S the problem.
    >
    > I appreciate your response, but please read the question in it's entirety
    > before answering.
    >
    > (I knew someone would do this <g>)
    >
    >
    > "Cowboy (Gregory A. Beamer)" <> wrote in
    > message news:...
    >> http://www.java2s.com/Code/CSharp/Language-Basics/CallingNativeDLLFunctions.htm
    >>
    >> --
    >> Gregory A. Beamer
    >> MVP, MCP: +I, SE, SD, DBA
    >>
    >> Subscribe to my blog
    >> http://gregorybeamer.spaces.live.com/lists/feed.rss
    >>
    >> or just read it:
    >> http://gregorybeamer.spaces.live.com/
    >>
    >> *************************************************
    >> | Think outside the box! |
    >> *************************************************
    >> "Chris Bordeman"
    >> <>
    >> wrote in message news:...
    >>> Using VS2008.
    >>>
    >>> Have an old straight C style dll, need to call it from ASP.NET. This
    >>> normally works easily using DllImport but ASP.NET apparently doesn't let
    >>> you call C dlls directly.
    >>>
    >>> So I heard you can call COM dlls by just adding a reference. So I
    >>> created a C# class library with a single class that wraps and calls my C
    >>> dll through DllImport. I checked the 'Make COM Visibile' option and
    >>> compiled. Used regasm.exe to register the dll w/ COM, which reported
    >>> success.
    >>>
    >>> But I do 'add reference' on the ASP.NET app and the object is not to be
    >>> found on the COM list.
    >>>
    >>> Isn't it supposed to show up?
    >>>
    >>> Is there a better way? Or a way to avoid COM altogether?
    >>>

    >>
    >>

    >
    >
    Cowboy \(Gregory A. Beamer\), Apr 11, 2008
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Laszlo Szijarto
    Replies:
    0
    Views:
    410
    Laszlo Szijarto
    Jul 2, 2003
  2. Patrick Steele [MVP]
    Replies:
    1
    Views:
    500
    John Timney \(Microsoft MVP\)
    Jul 14, 2003
  3. Andy Sutorius via DotNetMonster.com

    ASP.NET (c# code behind) will not load legacy C++ dll

    Andy Sutorius via DotNetMonster.com, Jan 18, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    4,959
    Andy Sutorius via DotNetMonster.com
    Jan 18, 2006
  4. Sergey V
    Replies:
    0
    Views:
    371
    Sergey V
    Aug 10, 2006
  5. Sergey V
    Replies:
    0
    Views:
    125
    Sergey V
    Aug 10, 2006
Loading...

Share This Page