Click to See Complete Forum and Search --> : Implementing an external DLL's functionality


dfb78
January 7th, 2003, 04:34 PM
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

pareshgh
January 7th, 2003, 05:34 PM
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