Everything.Dll Dynamic Library 호출, 32비트 및 64비트 호환

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace Start10
{

    public class Everything
    {
        /// 
        ///   64 
        /// 
        /// 
        public static bool IsSys64bit()
        {
            if (IntPtr.Size == 8)
            {

                return true;
            }
            else
            {

                return false;
            }

        }

        internal class Everything32
        {
            const string LIB_NAME = "Everything32.dll";

            #region     
            const int EVERYTHING_OK = 0;
            const int EVERYTHING_ERROR_MEMORY = 1;
            const int EVERYTHING_ERROR_IPC = 2;
            const int EVERYTHING_ERROR_REGISTERCLASSEX = 3;
            const int EVERYTHING_ERROR_CREATEWINDOW = 4;
            const int EVERYTHING_ERROR_CREATETHREAD = 5;
            const int EVERYTHING_ERROR_INVALIDINDEX = 6;
            const int EVERYTHING_ERROR_INVALIDCALL = 7;

            [DllImport(LIB_NAME)]
            public static extern int Everything_SetSearch(string lpSearchString);
            [DllImport(LIB_NAME)]
            public static extern void Everything_SetMatchPath(bool bEnable);
            [DllImport(LIB_NAME)]
            public static extern void Everything_SetMatchCase(bool bEnable);
            [DllImport(LIB_NAME)]
            public static extern void Everything_SetMatchWholeWord(bool bEnable);
            [DllImport(LIB_NAME)]
            public static extern void Everything_SetRegex(bool bEnable);
            [DllImport(LIB_NAME)]
            public static extern void Everything_SetMax(int dwMax);
            [DllImport(LIB_NAME)]
            public static extern void Everything_SetOffset(int dwOffset);

            [DllImport(LIB_NAME)]
            public static extern bool Everything_GetMatchPath();
            [DllImport(LIB_NAME)]
            public static extern bool Everything_GetMatchCase();
            [DllImport(LIB_NAME)]
            public static extern bool Everything_GetMatchWholeWord();
            [DllImport(LIB_NAME)]
            public static extern bool Everything_GetRegex();
            [DllImport(LIB_NAME)]
            public static extern UInt32 Everything_GetMax();
            [DllImport(LIB_NAME)]
            public static extern UInt32 Everything_GetOffset();
            [DllImport(LIB_NAME)]
            public static extern string Everything_GetSearch();
            [DllImport(LIB_NAME)]
            public static extern int Everything_GetLastError();

            [DllImport(LIB_NAME, CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
            public static extern bool Everything_Query();

            [DllImport(LIB_NAME)]
            public static extern void Everything_SortResultsByPath();

            [DllImport(LIB_NAME)]
            public static extern int Everything_GetNumFileResults();
            [DllImport(LIB_NAME)]
            public static extern int Everything_GetNumFolderResults();
            [DllImport(LIB_NAME)]
            public static extern int Everything_GetNumResults();
            [DllImport(LIB_NAME)]
            public static extern int Everything_GetTotFileResults();
            [DllImport(LIB_NAME)]
            public static extern int Everything_GetTotFolderResults();
            [DllImport(LIB_NAME)]
            public static extern int Everything_GetTotResults();
            [DllImport(LIB_NAME)]
            public static extern bool Everything_IsVolumeResult(int nIndex);
            [DllImport(LIB_NAME)]
            public static extern bool Everything_IsFolderResult(int nIndex);
            [DllImport(LIB_NAME)]
            public static extern bool Everything_IsFileResult(int nIndex);
            [DllImport(LIB_NAME)]
            public static extern void Everything_GetResultFullPathName(int nIndex, StringBuilder lpString, int nMaxCount);
            [DllImport(LIB_NAME)]
            public static extern void Everything_Reset();
            #endregion
        }

        internal class Everything64
        {
            const string LIB_NAME = "Everything64.dll";

            #region     
            const int EVERYTHING_OK = 0;
            const int EVERYTHING_ERROR_MEMORY = 1;
            const int EVERYTHING_ERROR_IPC = 2;
            const int EVERYTHING_ERROR_REGISTERCLASSEX = 3;
            const int EVERYTHING_ERROR_CREATEWINDOW = 4;
            const int EVERYTHING_ERROR_CREATETHREAD = 5;
            const int EVERYTHING_ERROR_INVALIDINDEX = 6;
            const int EVERYTHING_ERROR_INVALIDCALL = 7;

            [DllImport(LIB_NAME)]
            public static extern int Everything_SetSearch(string lpSearchString);
            [DllImport(LIB_NAME)]
            public static extern void Everything_SetMatchPath(bool bEnable);
            [DllImport(LIB_NAME)]
            public static extern void Everything_SetMatchCase(bool bEnable);
            [DllImport(LIB_NAME)]
            public static extern void Everything_SetMatchWholeWord(bool bEnable);
            [DllImport(LIB_NAME)]
            public static extern void Everything_SetRegex(bool bEnable);
            [DllImport(LIB_NAME)]
            public static extern void Everything_SetMax(int dwMax);
            [DllImport(LIB_NAME)]
            public static extern void Everything_SetOffset(int dwOffset);

            [DllImport(LIB_NAME)]
            public static extern bool Everything_GetMatchPath();
            [DllImport(LIB_NAME)]
            public static extern bool Everything_GetMatchCase();
            [DllImport(LIB_NAME)]
            public static extern bool Everything_GetMatchWholeWord();
            [DllImport(LIB_NAME)]
            public static extern bool Everything_GetRegex();
            [DllImport(LIB_NAME)]
            public static extern UInt32 Everything_GetMax();
            [DllImport(LIB_NAME)]
            public static extern UInt32 Everything_GetOffset();
            [DllImport(LIB_NAME)]
            public static extern string Everything_GetSearch();
            [DllImport(LIB_NAME)]
            public static extern int Everything_GetLastError();

            [DllImport(LIB_NAME, CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
            public static extern bool Everything_Query();

            [DllImport(LIB_NAME)]
            public static extern void Everything_SortResultsByPath();

            [DllImport(LIB_NAME)]
            public static extern int Everything_GetNumFileResults();
            [DllImport(LIB_NAME)]
            public static extern int Everything_GetNumFolderResults();
            [DllImport(LIB_NAME)]
            public static extern int Everything_GetNumResults();
            [DllImport(LIB_NAME)]
            public static extern int Everything_GetTotFileResults();
            [DllImport(LIB_NAME)]
            public static extern int Everything_GetTotFolderResults();
            [DllImport(LIB_NAME)]
            public static extern int Everything_GetTotResults();
            [DllImport(LIB_NAME)]
            public static extern bool Everything_IsVolumeResult(int nIndex);
            [DllImport(LIB_NAME)]
            public static extern bool Everything_IsFolderResult(int nIndex);
            [DllImport(LIB_NAME)]
            public static extern bool Everything_IsFileResult(int nIndex);
            [DllImport(LIB_NAME)]
            public static extern void Everything_GetResultFullPathName(int nIndex, StringBuilder lpString, int nMaxCount);
            [DllImport(LIB_NAME)]
            public static extern void Everything_Reset();
            #endregion
        }

        internal static void Everything_SetSearch(string sKeyWord)
        {
            if (IntPtr.Size == 8)
                Everything64.Everything_SetSearch(sKeyWord);
            else
                Everything32.Everything_SetSearch(sKeyWord);
        }

        internal static void Everything_Query()
        {
            if (IntPtr.Size == 8)
                Everything64.Everything_Query();
            else
                Everything32.Everything_Query();

        }

        internal static int Everything_GetNumResults()
        {
            if (IntPtr.Size == 8)
                return Everything64.Everything_GetNumResults();
            else
                return Everything32.Everything_GetNumResults();
        }
        internal static bool Everything_IsFolderResult(int idx)
        {
            if (IntPtr.Size == 8)
                return Everything64.Everything_IsFolderResult(idx);
            else
                return Everything32.Everything_IsFolderResult(idx);
        }
        
        internal static void Everything_SortResultsByPath()
        {
            if (IntPtr.Size == 8)
                Everything64.Everything_SortResultsByPath();
            else
                Everything32.Everything_SortResultsByPath();
        }

        internal static void Everything_GetResultFullPathName(int i, StringBuilder buf, int bufsize)
        {
            if (IntPtr.Size == 8)
                Everything64.Everything_GetResultFullPathName(i, buf, bufsize);
            else
                Everything32.Everything_GetResultFullPathName(i, buf, bufsize);

        }


    }

}

다음과 같은 방법으로 단순화를 정의할 수도 있습니다.
낮은 버전 VS 비상량 초기화는 지원되지 않음
    internal static string LIB_NAME = IsSys64bit() ? "libTestDLL_X64.dll" : "libTestDLL.dll";
 
        [DllImport(LIB_NAME, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr Demo(string input, int cnt);

다른 봉인 방식: 함수 이름이 다르면 같은 EntryPoint 호출 함수 이름을 지정합니다
    //    DLL,  WIN32,  X64
    //         C#   

    static bool is64bit = (IntPtr.Size == 8);
            [DllImport("t64.dll", EntryPoint = "test")]
    static extern int test64(byte[] contextArray);
    [DllImport("t32.dll", EntryPoint = "test")]
    static extern int test32(byte[] contextArray);
    public static int test(byte[] contextArray)
    {
        return is64bit ? test64(contextArray) : test32(contextArray);
    }

좋은 웹페이지 즐겨찾기