Call another function that is in the list of exported functions

I wrote a library that has some functions that are exported. Example:

[DllExport("Test", CallingConvention = CallingConvention.StdCall)] public static void Test() { MessageBox.Show("Test 1"); } [DllExport("Test2", CallingConvention = CallingConvention.StdCall)] public static void TestTwo() { MessageBox.Show("Test 2"); Test(); //TestThree(); } public static void TestThree() { MessageBox.Show("Test 3"); } 

When I call Test from an external application (Delphi), it works fine, and I get a message box.
When I call Test2 , I get an External exception in Delphi. An exception is thrown right away; it doesn't even show me the Test 2 message box. When I call Test2 , which in turn calls TestThree , which is not an exported function, it works fine, and I get both Test 2 and Test 3 message boxes.

Why can't I call other exported functions inside my dll? Is there any way I CAN do this?

EDIT 1:

At this point, I could achieve what I need by doing the following: Create another unexported function Test_Local() , move all the code from Test . Now, instead of calling Test() from TestTwo I call Test_Local() , the Test function also calls Test_Local();

Everything works fine until Test_Local() tries to run any other exported function.

So it’s incorrect to call the exported function inside another exported function, and it doesn’t matter how many layers between them are not exported.

+5
source share
1 answer

One possibility that arises for me is that the export name and the local method name are the same. Have you tried to change the local method name?

 [DllExport("Test", CallingConvention = CallingConvention.StdCall)] public static void TestOne() { MessageBox.Show("Test 1"); } [DllExport("Test2", CallingConvention = CallingConvention.StdCall)] public static void TestTwo() { MessageBox.Show("Test 2"); TestOne(); //TestThree(); } public static void TestThree() { MessageBox.Show("Test 3"); } 

I have not tested this.

0
source

Source: https://habr.com/ru/post/1203479/


All Articles