public Int32 DLL_CSV_GetCellAsString(IntPtr csvParser, Int32 cellX, Int32 cellY, ref string dest) { var s = new StringBuilder(8192); var result = GetProcAddress <Functions.DLL_CSV_GetCellAsString>()(csvParser, cellX, cellY, s, s.Capacity); if (result > 0) { dest = s.ToString(0, result); } return(result); }
public Int32 DLL_FileSystem_AtList(ref LISTDATA listData, Int32 atNum, ref string dest) { var s = new byte[8192]; var result = GetProcAddress <Functions.DLL_FileSystem_AtList>()(ref listData, atNum, s, 8192); if (result > 0) { dest = Encoding.UTF8.GetString(s, 0, result); } else { dest = ""; } return(result); }
static DynamicLibrary() { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { __loadLibrary = Kernel32.LoadLibrary; __getProcAddress = Kernel32.GetProcAddress; } }
private static TDelegate GetAddress <TDelegate>(string name) where TDelegate : class { IntPtr addr = GetProcAddress.GetOpenGLAddress(name); if (addr == IntPtr.Zero) { return(null); } return((TDelegate)(object)Marshal.GetDelegateForFunctionPointer(addr, typeof(TDelegate))); }
private static IntPtr getAMSILocation() { //GetProcAddress IntPtr pGetProcAddress = GetLibraryAddress("kernel32.dll", "GetProcAddress"); IntPtr pLoadLibrary = GetLibraryAddress("kernel32.dll", "LoadLibraryA"); GetProcAddress fGetProcAddress = (GetProcAddress)Marshal.GetDelegateForFunctionPointer(pGetProcAddress, typeof(GetProcAddress)); LoadLibrary fLoadLibrary = (LoadLibrary)Marshal.GetDelegateForFunctionPointer(pLoadLibrary, typeof(LoadLibrary)); return(fGetProcAddress(fLoadLibrary("amsi.dll"), "AmsiScanBuffer")); }
public void Test_NativeLibrary_GetDelegateGeneric() { using (var lib = new NativeLibrary("kernel32.dll")) { GetProcAddress @delegate = lib.GetDelegate <GetProcAddress>("GetProcAddress"); FreeLibrary @delegate1 = lib.GetDelegate <FreeLibrary>("FreeLibrary"); Assert.NotNull(@delegate); Assert.NotNull(@delegate1); } }
/// <summary> /// 将导出函数封装到对应委托对象中。 /// </summary> /// <typeparam name="T">对应委托类型。</typeparam> /// <param name="func">对应委托对象。</param> /// <param name="getProcAddressFunc">封装GetProcAddress系统API的委托对象。</param> /// <param name="moduleHandle">导出函数所属的DLL模块句柄。</param> /// <param name="funcName">导出函数名称。</param> /// <param name="errorMessage">当无法获取导出函数地址时抛出的异常的信息。</param> /// <exception cref="ArgumentException"> /// <para>泛型类型<typeparamref name="T"/>不是从<see cref="Delegate"/>基类派生而来的委托类型。</para> /// <para>泛型类型<typeparamref name="T"/>是<see cref="Delegate"/>基类自身。</para> /// </exception> /// <exception cref="Win32Exception"> /// <para>无法获取参数<paramref name="funcName"/>指定的导出函数的地址。</para> /// <param>若指定了参数<paramref name="errorMessage"/>的值且不为<see langword="null"/>,则异常的<see cref="Exception.Message"/>属性值为参数<paramref name="errorMessage"/>的值。否则,为默认值。</param> /// </exception> public static void MarshalDelegateFromFunctionPointer <T>(out T func, GetProcAddress getProcAddressFunc, IntPtr moduleHandle, string funcName, string errorMessage = null) where T : class { if (!typeof(Delegate).IsAssignableFrom(typeof(T)) || typeof(T).Equals(typeof(Delegate))) { throw new ArgumentException(string.Format("泛型类型{0}必须为委托类型且不能为{1}", typeof(T).FullName, typeof(Delegate).FullName), nameof(T)); } IntPtr pFunc = getProcAddressFunc(moduleHandle, funcName); if (pFunc == IntPtr.Zero) { throw new Win32Exception(errorMessage ?? string.Format("无法获取导出函数{0}的地址。", funcName)); } Win32Utility.MarshalDelegateFromFunctionPointer(out func, funcName, pFunc); }
public void DLL_FileSystem_CreateFileSystemArchive(ref FSDATA fsdata) { GetProcAddress <Functions.DLL_FileSystem_CreateFileSystemArchive>()(ref fsdata); }
public Int32 DLL_CSV_Open(IntPtr csvParser, IntPtr fileObjPty) { return(GetProcAddress <Functions.DLL_CSV_Open>()(csvParser, fileObjPty)); }
public void DLL_CSV_DeleteCsvParser(IntPtr csvParser) { GetProcAddress <Functions.DLL_CSV_DeleteCsvParser>()(csvParser); }
public bool DLL_File_SetSeek(ref FILEDATA fd, long seek, bool absolute_move) { return(GetProcAddress <Functions.DLL_File_SetSeek>()(ref fd, seek, absolute_move)); }
/// <summary> /// 音声データの領域を開放します。 /// </summary> /// <param name="wav">WAV フォーマットのデータ</param> public void AquesTalk_FreeWave(System.IntPtr wav) { GetProcAddress <Functions.AquesTalk_FreeWave>()(wav); }
public Int32 DLL_CSV_IsCellToExistData(IntPtr csvParser, Int32 cellX, Int32 cellY) { return(GetProcAddress <Functions.DLL_CSV_IsCellToExistData>()(csvParser, cellX, cellY)); }
public Int32 DLL_FileSystem_GetFile(ref FSDATA fsdata, string path, ref FILEDATA dest) { return(GetProcAddress <Functions.DLL_FileSystem_GetFile>()(ref fsdata, stringToNullTerminatedUtf8(path), ref dest)); }
public Int32 DLL_FileSystem_IsExistentFile(ref FSDATA fsdata, string path) { return(GetProcAddress <Functions.DLL_FileSystem_IsExistentFile>()(ref fsdata, stringToNullTerminatedUtf8(path))); }
public void DLL_FileSystem_AddArchive(ref FSDATA fsdata, string path) { GetProcAddress <Functions.DLL_FileSystem_AddArchive>()(ref fsdata, path); }
public Int32 DLL_FileSystem_IsValid(ref FSDATA fsdata) { return(GetProcAddress <Functions.DLL_FileSystem_IsValid>()(ref fsdata)); }
public void DLL_File_CloseFile(ref FILEDATA filedata) { GetProcAddress <Functions.DLL_File_CloseFile>()(ref filedata); }
public long DLL_File_GetSize(ref FILEDATA fd) { return(GetProcAddress <Functions.DLL_File_GetSize>()(ref fd)); }
public long DLL_File_Read(ref FILEDATA fd, IntPtr dest, long read_size) { return(GetProcAddress <Functions.DLL_File_Read>()(ref fd, dest, read_size)); }
public Int32 DLL_CSV_GetCellAsBinary(IntPtr csvParser, Int32 cellX, Int32 cellY, ref byte[] dest, Int32 size) { return(GetProcAddress <Functions.DLL_CSV_GetCellAsBinary>()(csvParser, cellX, cellY, dest, size)); }
public Int32 DLL_CSV_GetDataSizeString(IntPtr csvParser, Int32 cellX, Int32 cellY) { return(GetProcAddress <Functions.DLL_CSV_GetDataSizeString>()(csvParser, cellX, cellY)); }
/// <summary> /// 音声記号列から音声波形を生成します。 /// </summary> /// <param name="koe">音声記号列</param> /// <param name="speed">発話速度(50-300、デフォルトは100)</param> /// <param name="size">生成した音声データのサイズ</param> /// <returns>WAV フォーマットのデータ</returns> public System.IntPtr AquesTalk_Synthe(string koe, int speed, out int size) { return(GetProcAddress <Functions.AquesTalk_Synthe>()(koe, speed, out size)); }
public Int32 DLL_CSV_GetMaxCellY(IntPtr csvParser) { return(GetProcAddress <Functions.DLL_CSV_GetMaxCellY>()(csvParser)); }
public void DLL_FileSystem_DeleteList(ref LISTDATA listData) { GetProcAddress <Functions.DLL_FileSystem_DeleteList>()(ref listData); }
public void DLL_FileSystem_DeleteFileSystem(ref FSDATA fsdata) { GetProcAddress <Functions.DLL_FileSystem_DeleteFileSystem>()(ref fsdata); }
public IntPtr DLL_CSV_CreateCsvParser() { return(GetProcAddress <Functions.DLL_CSV_CreateCsvParser>()()); }
public void DLL_FileSystem_CreateList(ref FSDATA fsdata, string path, Int32 listType, ref LISTDATA listData) { GetProcAddress <Functions.DLL_FileSystem_CreateList>()(ref fsdata, stringToNullTerminatedUtf8(path), listType, ref listData); }
public bool DLL_File_IsValid(ref FILEDATA fd) { return(GetProcAddress <Functions.DLL_File_IsValid>()(ref fd)); }