CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2004
    Location
    NH
    Posts
    3

    Question How do I use a DLL with C#?

    I am trying to use a DLL created with Visual Studio 6.0 from my C# application created with Visual Studio.NET 2003. As soon as I go to add a reference I get "A reference could not be added...Not a valid assembly or COM component..."

    If you can help me, please reply.

    Thanks,
    Jim Mason

  2. #2
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    Re: How do I use a DLL with C#?

    1. register it w/ com
    2. wrap it in C++ w/ .net
    3. use system.runtime.interopservices to do a DllImport for each function you need.

    ex: Playsound

    [DllImport("winmm.dll")]
    public static extern bool PlaySound(string sound, IntPtr module, int soundFlags);
    Last edited by MadHatter; February 10th, 2006 at 03:30 PM.

  3. #3
    Join Date
    Mar 2004
    Location
    NH
    Posts
    3

    Re: How do I use a DLL with C#?

    Thanks MadHatter. I'll give it a shot. I have a lot to learn here.
    Thanks Again,
    Jim

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured