CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2002
    Location
    Atlanta, GA
    Posts
    97

    Implementing an external DLL's functionality

    I have only created my own DLLs and implemented them into my own solutions up to this point...I have not utilized external ones. I downloaded a DLL (and .lib file that came with it) which has a lot of functionality I want to use in my project. However, I have NO idea how to place it into my solution/project to access it. I've went through the few books I've got, which mention using "[DllImport("TheDLLFileName.dll"]" and including the "using System.Runtime.InteropServices", but that doesn't seem to be working. Am I missing something?

    Thanks

  2. #2
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    in your original dll you need to specify those functions as
    dllexport

    and in your C# project you need to do something like this...

    public class yourWrapper
    {

    [ DllImport( "your.dll", EntryPoint="MyFunctionName", CharSet=CharSet.Auto )]
    public static extern int MyFunctionName( int hWnd, String text, String caption, uint type );

    // Here hWnd and other data type conversions you need to know

    }


    public class MyClass
    {
    public static void Main()
    {
    try
    {
    yourWrapper.MyFunctionName( 0, "Function Execution", "Sample", 0 ); // method invocation
    }
    catch( EntryPointNotFoundException )
    {
    Console.WriteLine( "EntryPointNotFoundException thrown as expected!" ); //throws if method not exists or something
    }

    }
    }

    It works great.
    additionally, you have to check all the possiblities .. like dll should be in the path etc..

    hope this will help you
    Paresh Gheewala

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