c# - Confused over DLL entry points (entry point not found exception) -
I'm learning how to use DLL in C #. I have a very simple DLL to do my basic test.
// using the MainForm.cs system; Using System.Collections.Generic; Using System.ComponentModel; Using System.Data; Using System.Drawing; Using System.Linq; Using System.Text; Using System.Windows.Forms; Using System.Runtime.InteropServices; Namespace DLL_Test {public partial class} Form 1: Form {{DllImport ("TestDLL.dll", EntryPoint = "? @ @ YGHHH Add @, Accurate Spelling = True, Calling Communication = Calling Conference. STCL}] Add public static extern int ( Int a, int b); public form 1 () {initialization ();} private zeros button 1_Click (object sender, eventArgs e) {int num; try {num = add (2, 3); RichTextBox1.AppendText (num. ToString () + "\ n");} Hold (DllNotFoundException Pre) {Message Box.Show (ex.ToString ());} Hold (EntryPointNotFoundException Pre) {Message Box.Show (ex.ToString ())}} }} more DLL code:
// TestDLL.cpp __declspec (dllexport) Add int __stdcall (int a, int b) {return (a + b);} < P> The dump bin gives the following: successive hint RVA name 1 00011005? Add @@ YGHHH @ z = ILT + 0 (? Add @ @ (YGHHH @ Z) < / Pre> This (and other attempts listed below) has all returned the same exception:
System.EntryPointException: Unable to find entry point name "..." < / Code> So I'm at a loss to solve it, maybe I do not know that DA L C # entry point as DllMain function how it works. TestDLL.dll works when I check it in C ++ application.
After searching for help, I have tried the following changes:
// Exclude TestDLL.cpp extern "C" __DoubleSPEC (DLEXPort) Int __StDColC ( Int a, int b) {returns (a + b); } This is the result of DumpBin
successive hints RVA name 0 00011005 _ad @ 8 = @ ILT + 135 (_ad @ 8) In this way, I have changed my C # code:
// MainForm.cs ... [DllImport ("TestDLL.dll", EntryPoint = " _ Add ", ExactSpelling = true, Calling Convention = Calling Conference. StCel)] Add public static extern int (int a, int b); ... I have also tried __ cdecl : // testDLL.cpp extern "c" __declspec (Dllexport) Add Int __cdecl (int a, int b) {return (a + b); } .
. <...> [DllImport ("TestDLL.dll", EntryPoint = "_ add", ExactSpelling = true, calling communication = calling communicationCDEcl)] add public static extern int (Int one, int b); ... Perhaps I am misunderstood in calling conferences Any help would be very appreciated. Thank you.
use
extern "c" __declspec (dllexport) Int __stdcall (Int a, int b) {...} and
[DllImport ("TestDLL.dll", Calling Communication = Calling Conference.Stdcall) ] Add public statational extern int (int one, int b); extern "c" parameter and return type such as ? With @ @ yghhh @ z will stop engaging in the name. __stdcall will be included in a _ and add @ 8 : _Add @ 8 (where is the total size of 8 arguments). Note that it is also affected if the parameter is pushed onto the stack. In your DLLImport statement, when you call calling conferences. STCL specifies that name is not required to be confused with name only ( add ) and renaming of .net name ( _Add @ 8 ). Note that you
Comments
Post a Comment