C# .NET User Control inside native app. Resource chain problems

后端 未结 1 1033
旧巷少年郎
旧巷少年郎 2021-02-19 18:37

I am wrapping up an MFC extension DLL (MFCXDLL_2) to make its functionality available for C# programmers.

The wrapper is a “Regular DLL using shared MFC DLL” with “Commo

1条回答
  •  日久生厌
    2021-02-19 19:31

    I think that you may have some confusion here as to what your wrapper is doing.

    You can call unmanaged C++ DLLs from within .NET code using DLLImport statements.

    I would suggest that you create a C# class library project that will be the wrapper DLL for your unmanaged DLL, MFCXDLL.

    You probably wont be able to add the DLL as a referenced resource, but you should create a project folder in which you store it and add it as a project file, set to Copy Local True for when the NET class library is built. You will also want to place any DLLs that MFCXDLL references within the same folder also set to Copy Local.

    You then reference your NET DLL from all NET based code.

    Here's an example of the wrapper process.

    edit

    I've had a check and yes I have used an unmanaged C++ DLL that used MFC as a shared library. Here's a cut down version of the code that I used.(Some class names have been changed due to confidentiality agreement.)

        using System.Collections.Generic;
        using System.Runtime.InteropServices;
    
        public class WrapperClass
        {
            [DllImport("some.dll", EntryPoint = "WriteDataCard", SetLastError = true)]
            [return: MarshalAs(UnmanagedType.VariantBool)]
            public static extern Boolean WriteDataCard(Byte nComPort, bool bInitialize, bool bCardFeeder, [In] Byte[] bytesData, Byte dataSize, bool bTestKey);
    
            [DllImport("some.dll", EntryPoint = "ReadDataCard", SetLastError=true)]
            [return: MarshalAs(UnmanagedType.VariantBool)]
            public static extern Boolean ReadDataCard(Byte nComPort, Boolean bInitialize, Boolean bCardFeeder,  [Out] Byte[] bytesData, Byte dataSize);
    
       }
    

    0 讨论(0)
提交回复
热议问题