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);
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
ThinkPHP5 - 로그텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.