|
-
Jul 9th, 2010, 11:00 AM
#1
Thread Starter
Fanatic Member
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'...
-
Jul 9th, 2010, 11:17 AM
#2
Re: Call unmanaged class in C#
Is this method exported from the DLL? If not then you can't call it using DllImport.
-
Jul 9th, 2010, 11:24 AM
#3
Thread Starter
Fanatic Member
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.
-
Jul 9th, 2010, 11:40 AM
#4
New Member
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")]
-
Jul 9th, 2010, 11:40 AM
#5
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.
-
Jul 9th, 2010, 11:46 AM
#6
New Member
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
-
Jul 9th, 2010, 01:26 PM
#7
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
-
Jul 9th, 2010, 03:50 PM
#8
New Member
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?
-
Jul 9th, 2010, 04:22 PM
#9
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|