Unzip the contents of an Excel.XLL file built using Excel-DNA

I donโ€™t know if you know the excel-dna project, it is a project that helps integrate the .net assembly and language into excel add-ons.

My problem is that I want to unpack dll from xll file (excel-dna can pack resources inside xll).

I downloaded excel-dna sources and already wrote this base in the source code:

string xlllib = @"C:\pathtomyxllfile\myaddin.xll"; string xlloutput = @"C:\pathtomyxllfile\myaddin.dll"; var hModule = ResourceHelper.LoadLibrary(xlllib); var content = ResourceHelper.LoadResourceBytes(hModule, "ASSEMBLY_LZMA", "MYASSEMBLYNAME"); using (BinaryWriter binWriter = new BinaryWriter(File.Open(xlloutput, FileMode.Create))) { binWriter.Write(content); } 

but that will not work. Anyone have an idea to unzip a dll from xll?

thanks in advance,

+4
source share
2 answers

I think you are trying to load an x86 x86 file into an x64-bit process. It is not possible to combine x86 and x64-bit. Instead, use the LoadLibraryEx function to load your .xll file into a data file.

Here is a small code example:

 [Flags] enum LoadLibraryFlags : uint { 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_WITH_ALTERED_SEARCH_PATH = 0x00000008 } internal unsafe static class ResourceHelper { [DllImport("kernel32.dll")] public static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hFile, LoadLibraryFlags dwFlags); // other methods such as LoadResourceBytes go here... } string xlllib = @"C:\pathtomyxllfile\myaddin.xll"; string xlloutput = @"C:\pathtomyxllfile\myaddin.dll"; var hModule = ResourceHelper.LoadLibraryEx(xlllib, IntPtr.Zero, LoadLibraryFlags.LOAD_LIBRARY_AS_DATAFILE | LoadLibraryFlags.LOAD_LIBRARY_AS_IMAGE_RESOURCE); var content = ResourceHelper.LoadResourceBytes(hModule, "ASSEMBLY_LZMA", "YOUR_ASSEMBLY_NAME_WITHOUT_EXTENSION"); using (BinaryWriter binWriter = new BinaryWriter(File.Open(xlloutput, FileMode.Create))) { binWriter.Write(content); } 

Hope this helps.

+2
source

If you want to extract .NET assemblies from an Excel-DNA add-in, I wrote a small utility called ExcelDnaUnpack . The source code is on GitHub: https://github.com/caioproiete/ExcelDnaUnpack

ExcelDnaUnpack - command line utility for extracting the contents of ExcelDna add-ins packaged in ExcelDnaPack

 Usage: ExcelDnaUnpack.exe [<options>] Where [<options>] is any of: --xllFile=VALUE The XLL file to be unpacked; eg MyAddIn-packed.xll --outFolder=VALUE [Optional] The folder into which the extracted files will be written; defaults to '.\unpacked' --overwrite [Optional] Allow existing files of the same name to be overwritten Example: ExcelDnaUnpack.exe --xllFile=MyAddins\FirstAddin-packed.xll The extracted files will be saved to MyAddins\unpacked 
+3
source

All Articles