Results 1 to 9 of 9

Thread: Call unmanaged class in C#

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Call unmanaged class in C#

    I need help with calling an unmanaged class in my C# code. Let's say I have a SomeClass.SomeFunction. How do I call the SomeFunction method via DLLImport? I have something like

    Code:
    [DllImport("Some.dll", EntryPoint = "SomeClass.SomeFunction", CallingConvention = CallingConvention.StdCall)]
    		public static extern string SomeFunction();
    but it says

    System.EntryPointNotFoundException : Unable to find an entry point named 'SomeClass.SomeFunctio' in DLL 'Some.dll'...

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Call unmanaged class in C#

    Is this method exported from the DLL? If not then you can't call it using DllImport.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: Call unmanaged class in C#

    Thanks for the reply, JM. What do you mean by "exported"? It's a dll created with Delphi and is copied to system32 directory.

  4. #4
    New Member
    Join Date
    Jul 2010
    Posts
    4

    Re: Call unmanaged class in C#

    Need help using unmanaged dll with a class and methods in my C# code. Problem how can I call the method inside the class? using the [DllImport("example.dl")]

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Call unmanaged class in C#

    Only functions expressly exported from the library they are declared in can be imported into a .NET app using the DllImport attribute. C++ has an 'export' keyword for the purpose. Delphi, I don't know. Are you sure that this library isn't a COM component? If it is then you reference it just like a .NET assembly and treat the types it contains much like .NET types.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    New Member
    Join Date
    Jul 2010
    Posts
    4

    Re: Call unmanaged class in C#

    Need help using unmanaged dll with a class and methods in my C# code. Problem how can I call the method inside the class? using the [DllImport("example.dll")] for my COM interface but if try to use it as reference it will display an error message after release(build and compile) the error display type initialize

  7. #7
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611

    Re: Call unmanaged class in C#

    If it is a COM DLL you don't need the DLLImport.This link explains how to do this
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

  8. #8
    New Member
    Join Date
    Jul 2010
    Posts
    4

    Re: Call unmanaged class in C#

    Need help here with regards to importing DLL due to the fact if it is being used as reference when build and compiled it will display an error type initialize so I try to used the unmanaged DLL example as follows:
    the Example DLL has a class an a method

    Icomlib.dll
    -ComInterfaceClass ---> class
    -ComInterfaceClass() --->constructor
    -GetData(): string --->trying to call this method
    -GetLogin(): Boolean

    so getting the GetData method using dllimport:
    [ DllImport( "icomlib.dll", EntryPoint="?GetData@ComInterfaceClass@@QAEHH@Z",
    CallingConvention=CallingConvention.ThisCall )]
    public static extern IntPtr ComInterfaceClass();

    in the main:

    public static void Main()
    {
    ComInterfaceClass x= new ComInterfaceClass();
    string y = x.GetData();
    MessageBox.show(y);
    }

    is this correct?
    can someone help me with this code here?

  9. #9
    New Member
    Join Date
    Jul 2010
    Posts
    4

    Re: Call unmanaged class in C#

    Displying an Error System.EntryPointnotFoundException: Unable to find an entry point named GetData in icomlib.dll

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