diff --git a/Project/Nuget/Native/MediaInfoLib.Native.nuspec b/Project/Nuget/Native/MediaInfoLib.Native.nuspec new file mode 100644 index 000000000..b5bf3bc17 --- /dev/null +++ b/Project/Nuget/Native/MediaInfoLib.Native.nuspec @@ -0,0 +1,25 @@ + + + + MediaInfoLib.Native + MediaInfoLib DLL and header for native(c++) projects + 18.08.1 + MediaArea.net + Copyright (c) MediaArea.net SARL. + mediainfo mediainfolib libmediainfo native + MediaInfo is a convenient unified display of the most relevant technical and tag data for video and audio files. + en-US + https://mediaarea.net/MediaInfo + https://github.com/MediaArea/MediaInfoLib/blob/master/LICENSE + https://mediaarea.net/_/img/MediaInfo_90x90.png + + + + + + + + + + + diff --git a/Project/Nuget/Native/MediaInfoLib.Native.targets b/Project/Nuget/Native/MediaInfoLib.Native.targets new file mode 100644 index 000000000..e339311e7 --- /dev/null +++ b/Project/Nuget/Native/MediaInfoLib.Native.targets @@ -0,0 +1,33 @@ + + + + + UNICODE;%(PreprocessorDefinitions) + $(MSBuildThisFileDirectory)..\..\build\native\include\;%(AdditionalIncludeDirectories) + + + $(MSBuildThisFileDirectory)..\..\build\native\include\;%(AdditionalIncludeDirectories) + + + + + $(MSBuildThisFileDirectory)..\..\build\native\x64\MediaInfo.lib;%(AdditionalDependencies) + + + + + $(MSBuildThisFileDirectory)..\..\build\native\x86\MediaInfo.lib;%(AdditionalDependencies) + + + + + + + + + + + + + + diff --git a/Project/Nuget/Wrapper/MediaInfoLib.Wrapper.csproj b/Project/Nuget/Wrapper/MediaInfoLib.Wrapper.csproj new file mode 100644 index 000000000..d39acbfa4 --- /dev/null +++ b/Project/Nuget/Wrapper/MediaInfoLib.Wrapper.csproj @@ -0,0 +1,12 @@ + + + + netcoreapp2.1 + MediaInfoLib.Wrapper + + + + + + + diff --git a/Project/Nuget/Wrapper/MediaInfoLib.Wrapper.nuspec b/Project/Nuget/Wrapper/MediaInfoLib.Wrapper.nuspec new file mode 100644 index 000000000..208b8623a --- /dev/null +++ b/Project/Nuget/Wrapper/MediaInfoLib.Wrapper.nuspec @@ -0,0 +1,21 @@ + + + + MediaInfoLib.Wrapper + 18.8.1 + MediaInfoLib DLL wrapper for .NET projects + MediaArea.net + MediaArea.net + false + https://github.com/MediaArea/MediaInfoLib/blob/master/LICENSE + https://mediaarea.net/MediaInfo + https://mediaarea.net/_/img/MediaInfo_90x90.png + MediaInfo is a convenient unified display of the most relevant technical and tag data for video and audio files. + Copyright (c) MediaArea.net SARL. + en-US + mediainfo mediainfolib libmediainfo + + + + + diff --git a/Source/MediaInfoDLL/MediaInfoDLL.cs b/Source/MediaInfoDLL/MediaInfoDLL.cs index 431e077e1..82db9ef29 100644 --- a/Source/MediaInfoDLL/MediaInfoDLL.cs +++ b/Source/MediaInfoDLL/MediaInfoDLL.cs @@ -21,6 +21,22 @@ namespace MediaInfoLib { + internal enum LoadLibraryFlags : uint + { + DEFAULT = 0x00000000, + DONT_RESOLVE_DLL_REFERENCES = 0x00000001, + LOAD_IGNORE_CODE_AUTHZ_LEVEL = 0x00000010, + LOAD_LIBRARY_AS_DATAFILE = 0x00000002, + LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = 0x00000040, + LOAD_LIBRARY_AS_IMAGE_RESOURCE = 0x00000020, + LOAD_LIBRARY_SEARCH_APPLICATION_DIR = 0x00000200, + LOAD_LIBRARY_SEARCH_DEFAULT_DIRS = 0x00001000, + LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR = 0x00000100, + LOAD_LIBRARY_SEARCH_SYSTEM32 = 0x00000800, + LOAD_LIBRARY_SEARCH_USER_DIRS = 0x00000400, + LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008, + } + public enum StreamKind { General, @@ -71,6 +87,13 @@ public enum Status public class MediaInfo { + [DllImport("kernel32.dll", SetLastError = true)] + internal static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hReservedNull, LoadLibraryFlags dwFlags); + + [DllImport("kernel32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static extern bool FreeLibrary(IntPtr hModule); + //Import of DLL functions. DO NOT USE until you know what you do (MediaInfo DLL do NOT use CoTaskMemAlloc to allocate memory) [DllImport("MediaInfo.dll")] private static extern IntPtr MediaInfo_New(); @@ -122,6 +145,12 @@ public class MediaInfo //MediaInfo class public MediaInfo() { + Module = LoadLibraryEx("MediaInfo.dll", IntPtr.Zero, LoadLibraryFlags.DEFAULT | + LoadLibraryFlags.LOAD_LIBRARY_SEARCH_APPLICATION_DIR | + LoadLibraryFlags.LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | + LoadLibraryFlags.LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | + LoadLibraryFlags.LOAD_LIBRARY_SEARCH_SYSTEM32); + try { Handle = MediaInfo_New(); @@ -135,7 +164,18 @@ public MediaInfo() else MustUseAnsi=false; } - ~MediaInfo() { if (Handle == (IntPtr)0) return; MediaInfo_Delete(Handle); } + + ~MediaInfo() + { + if (Module != (IntPtr)0) + FreeLibrary(Module); + + if (Handle == (IntPtr)0) + return; + + MediaInfo_Delete(Handle); + } + public int Open(String FileName) { if (Handle == (IntPtr)0) @@ -218,6 +258,7 @@ public String Option(String Option, String Value) public int State_Get() { if (Handle == (IntPtr)0) return 0; return (int)MediaInfo_State_Get(Handle); } public int Count_Get(StreamKind StreamKind, int StreamNumber) { if (Handle == (IntPtr)0) return 0; return (int)MediaInfo_Count_Get(Handle, (IntPtr)StreamKind, (IntPtr)StreamNumber); } private IntPtr Handle; + private IntPtr Module; private bool MustUseAnsi; //Default values, if you know how to set default values in C#, say me @@ -228,22 +269,6 @@ public String Option(String Option, String Value) public int Count_Get(StreamKind StreamKind) { return Count_Get(StreamKind, -1); } } - - - - - - - - - - - - - - - - public class MediaInfoList { //Import of DLL functions. DO NOT USE until you know what you do (MediaInfo DLL do NOT use CoTaskMemAlloc to allocate memory) @@ -269,8 +294,32 @@ public class MediaInfoList private static extern IntPtr MediaInfoList_Count_Get(IntPtr Handle, IntPtr FilePos, IntPtr StreamKind, IntPtr StreamNumber); //MediaInfo class - public MediaInfoList() { Handle = MediaInfoList_New(); } - ~MediaInfoList() { MediaInfoList_Delete(Handle); } + public MediaInfoList() { + Module = LoadLibraryEx("MediaInfo.dll", IntPtr.Zero, LoadLibraryFlags.DEFAULT | + LoadLibraryFlags.LOAD_LIBRARY_SEARCH_APPLICATION_DIR | + LoadLibraryFlags.LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | + LoadLibraryFlags.LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | + LoadLibraryFlags.LOAD_LIBRARY_SEARCH_SYSTEM32); + + try + { + Handle = MediaInfoList_New(); + } + catch + { + Handle = (IntPtr)0; + } + } + ~MediaInfoList() + { + if (Module != (IntPtr)0) + FreeLibrary(Module); + + if (Handle == (IntPtr)0) + return; + + MediaInfoList_Delete(Handle); + } public int Open(String FileName, InfoFileOptions Options) { return (int)MediaInfoList_Open(Handle, FileName, (IntPtr)Options); } public void Close(int FilePos) { MediaInfoList_Close(Handle, (IntPtr)FilePos); } public String Inform(int FilePos) { return Marshal.PtrToStringUni(MediaInfoList_Inform(Handle, (IntPtr)FilePos, (IntPtr)0)); } @@ -280,6 +329,7 @@ public class MediaInfoList public int State_Get() { return (int)MediaInfoList_State_Get(Handle); } public int Count_Get(int FilePos, StreamKind StreamKind, int StreamNumber) { return (int)MediaInfoList_Count_Get(Handle, (IntPtr)FilePos, (IntPtr)StreamKind, (IntPtr)StreamNumber); } private IntPtr Handle; + private IntPtr Module; //Default values, if you know how to set default values in C#, say me public void Open(String FileName) { Open(FileName, 0); }