我不知道你是否知道excel-dna项目,它是一个帮助在excel插件中集成.net汇编和语言的项目。
我的问题是,我想从xll文件中解压一个dll (excel-dna能够将资源打包到xll中)。
我没有加载excel-dna源代码,并且已经在源代码上编写了这个基础:
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);
}但它不起作用。谁有办法从xll中解压一个dll?
提前谢谢你,
发布于 2011-09-17 23:44:15
我认为您正在尝试将x86 .xll文件加载到x64位进程中。不能混合使用x86和x64位码。相反,请使用LoadLibraryEx函数将.xll文件作为数据文件加载。
下面是一个小的代码示例:
[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);
}霍普,这有帮助。
发布于 2015-11-30 10:50:21
如果您希望从Excel-DNA外接程序中提取.NET程序集,我编写了一个名为的小实用程序。源代码在GitHub上:https://github.com/augustoproiete/exceldna-unpack
是一个命令行实用程序,用于提取与ExcelDnaPack打包的ExcelDna加载项的内容

Usage: ExcelDna-Unpack.exe [<options>]
Where [<options>] is any of:
--xllFile=VALUE The XLL file to be unpacked; e.g. 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: ExcelDna-Unpack.exe --xllFile=MyAddIns\FirstAddin-packed.xll
The extracted files will be saved to MyAddIns\unpackedhttps://stackoverflow.com/questions/7402209
复制相似问题