none
C# to read C to create DLL under WIN ARM OS and fail RRS feed

  • Question

  • Hi, senior member

         I use C# to read C to create DLL under WIN ARM OS and fail.
         But the same set of procedures can be
         I tried running on Win x86 OS
             1. C DLL build 32/64 / ARM
             2.C# Create x86 and anyCPU
             3. DLL and C# exe are executed in the same folder

    //================================================ =

    C# program

    public partial class Form1 : Form
    {
        private void button1_Click(object sender, EventArgs e)
        {
            CALL_DLL.Messag();
        }
    }

    public class CALL_DLL

    {
        [DllImport("Test.dll")]
        public static extern byte Message();
    }


    // =============================================== ==
    C DLL
    DECLSPEC void __cdecl Message(void){
         MessageBox(NULL,L“DLL call succeeded”,L“ Test_DLL”,MB_OK);
    }

    What is the difference between using API under WIN ARM?

         Other settings are required to perform    



    PS: C++ calling C DLL works fine in Win ARM operating system

    謝謝


    漢斯_科技網





    • Edited by qh_ovo_hp Tuesday, June 16, 2020 1:27 AM
    Saturday, June 13, 2020 3:00 AM

Answers

  • Hi, senior member

    Found the reason~ I searched for a day yesterday, and finally know why it can't be executed under ARM
    the reason:

    Because I previously recommended that C# read the DLL on the Internet and change the Runtime Support to /clr
    And caused the problem that it can not work in ARM

    Now it’s normal to change it back to "No Common Language Runtime Support"
    Thank you for your valuable advice


    Hans_TechNet

    • Marked as answer by qh_ovo_hp Friday, June 19, 2020 2:23 AM
    Friday, June 19, 2020 2:21 AM

All replies

  • "C# Create x86/anyCPU" what do you mean by this? either anyCPU or x86.
    Did you you compile the C dll for ARM64, and the exe as anyCPU and disabled "prefer 32 bit"?
    you copied the correct dll (ARM64 compiled) into the program directory?
    Saturday, June 13, 2020 10:28 AM
  • Remember that a C or C++ DLL is always built to exactly one CPU architecture.  You can build it for ARM, or ARM64, or x86 32, or x86 64, but only one.  A C# DLL built with AnyCPU will adapt itself to whatever processor is running.

    Here's how that can backfire.  Let's say you build a C++ DLL as Win32, so it is 32-bit x86.  Now, let's say you have a C# app that is AnyCPU.  If you run that C# app on a 64-bit system, it will run as a 64-bit process.  That process cannot call a 32-bit DLL.  You'll get the exact error you got, 80070008.

    So, if you need to call from C# to a C++ DLL, you have two choices.  You can build your C# app for Win32, so it matches the DLL.  Or, you can build both 32-bit and 64-bit copies of the DLL, and have your installer install the correct one.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Sunday, June 14, 2020 12:27 AM
  • "C# Create x86/anyCPU" what do you mean by this? either anyCPU or x86.
    Did you you compile the C dll for ARM64, and the exe as anyCPU and disabled "prefer 32 bit"?
    you copied the correct dll (ARM64 compiled) into the program directory?

    good day
    I posted the C# editing environment


    Hans_TechNet

    Tuesday, June 16, 2020 2:16 AM
  • Did you you compile the C dll for ARM64, and the exe as anyCPU and disabled "prefer 32 bit"?

       NO, I now try to run on WOA with x86 compilation environment, is WOA not available for X86?

    Hans_TechNet

    Tuesday, June 16, 2020 2:22 AM
  • Hi,

    The first thing to confirm is whether the dll is x64 or x86.

    If it is x86, the platform target of the C# project should be modified to x86, if it is x64, the platform target should be modified to x64.

    They should correspond.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 16, 2020 9:40 AM
  • Hi,

    The first thing to confirm is whether the dll is x64 or x86.

    If it is x86, the platform target of the C# project should be modified to x86, if it is x64, the platform target should be modified to x64.

    They should correspond.

    Best Regards,

    Timon

    hi thank you for your valuable advice
    I have confirmed that under ARM OS C# is running in x86 mode as shown in the figure
    So my DLL is also running with x86 type


    Hans_TechNet

    Wednesday, June 17, 2020 9:01 AM
  • Hi, senior member

    Found the reason~ I searched for a day yesterday, and finally know why it can't be executed under ARM
    the reason:

    Because I previously recommended that C# read the DLL on the Internet and change the Runtime Support to /clr
    And caused the problem that it can not work in ARM

    Now it’s normal to change it back to "No Common Language Runtime Support"
    Thank you for your valuable advice


    Hans_TechNet

    • Marked as answer by qh_ovo_hp Friday, June 19, 2020 2:23 AM
    Friday, June 19, 2020 2:21 AM
  • HI Eckis

    Thank you for your valuable advice


    Hans_TechNet

    Friday, June 19, 2020 2:21 AM
  • HI Tim

    Thank you for your valuable advice


    Hans_TechNet

    Friday, June 19, 2020 2:21 AM
  • hi Timon

    Thank you for your valuable advice


    Hans_TechNet

    Friday, June 19, 2020 2:22 AM