为Windows 7/64位创建XLL Excel外接程序(在Windows XP/32上交叉编译)

时间:2023-01-26 21:48:06

I'm not a skilled Windows programmer, but I created and have been maintaining an XLL add-in for 32-bit Windows XP / Excel for many years. I'd now like to create a Windows 7/64 bit version and am having trouble - I can't even get the Generic.xll example to work.

我不是一个熟练的Windows程序员,但我创建并维护一个XLL插件的32位Windows XP / Excel多年。我现在想创建一个Windows 7/64位的版本,但是遇到了麻烦——我甚至不能获得通用的版本。xll工作示例。

Here's the simpliest version of what I've done - sorry this is long and pedantic.

这是我所做的最简单的一个版本——抱歉,这是一个冗长而迂腐的版本。

On my Windows XP/32 machine, where I have Visual Studio 2010 Professional installed:

在我的Windows XP/32机器上,我有Visual Studio 2010专业安装:

  • Downloaded & installed the Microsoft Excel 2013 SDK.

    下载安装微软Excel 2013 SDK。

  • Start Menu - "Open Visual Studio x64 Cross Tools Command Prompt (2010)"

    开始菜单-“打开Visual Studio x64十字工具命令提示符(2010)”

  • SET TYPE=RELEASE

    设置类型=释放

  • SET PLATFORM=x64 // I think this was preset anyway

    SET PLATFORM=x64 //我想这是预设好的

  • cd C:\2013 Office System Developer Resources\Excel2013XLLSDK\SAMPLES\FRAMEWRK

    cd C:\2013办公系统开发者资源\Excel2013XLLSDK\示例FRAMEWRK

  • nmake // no errors

    nmake / /没有错误

  • cd C:\2013 Office System Developer Resources\Excel2013XLLSDK\SAMPLES\GENERIC

    cd C:\2013 Office System Developer Resources\Excel2013XLLSDK\SAMPLES\GENERIC。

  • nmake // no errors

    nmake / /没有错误

  • copy the resulting C:\2013 Office System Developer Resources\Excel2013XLLSDK\SAMPLES\GENERIC\x64\RELEASE\GENERIC.xll to a network folder accessible by the Windows 7/64 computer

    复制结果C:\2013办公系统开发人员资源\Excel2013XLLSDK\样本\通用\x64\RELEASE\GENERIC。xll到一个由Windows 7/64计算机访问的网络文件夹。

On Windows 7/64 computer:

在Windows电脑:7/64

  • Start Excel 2013

    启动Excel 2013

  • File - Options - Add-ins - Manage Excel Add-ins - Browse, go to the network folder containing Generic.xll, click it.

    文件-选项-外接程序-管理Excel外接程序-浏览,到包含泛型的网络文件夹。xll,点击它。

  • Allow Excel to copy Generic.xll to the standard folder. It loads silently, no messages (including no message saying it loaded Generic.xll)

    允许Excel复制泛型。xll到标准文件夹。它无声地加载,没有消息(包括没有消息说它加载了Generic.xll)

  • No functionality from Generic.xll appears.

    没有从通用功能。xll出现。

  • Close and reopen Excel - upon reopening, I get a message box saying "The file format and extension of 'GENERIC.xll' don't match. The file could be corrupted or unsafe..." (If I say "Yes" it loads it like a text file, showing me binary code in the XLL in the spreadsheet.)

    关闭并重新打开Excel——重新打开后,我得到一个消息框,上面写着“文件格式和‘GENERIC’的扩展名”。xll”不匹配。文件可能被损坏或不安全…(如果我说“是”,它就像一个文本文件一样加载它,在电子表格的XLL中显示二进制代码。)

Based on previous (Windows XP/32) XLL experience, this message can mean almost anything - including a lack of required DLLs. So,

基于以前的(Windows XP/32) XLL体验,这条消息可以意味着几乎任何事情——包括缺少所需的dll。所以,

On Windows 7/64 computer:

在Windows电脑:7/64

  • Install Microsoft Visual C++ 2010 x64 Redistributable - 10.0.30319. No impact.

    安装Microsoft Visual c++ 2010 x64可再发行版- 10.0.30319。没有影响。

  • Install Microsoft Visual C++ 2012 Redistributable (x64) - 11.0.51106. No impact.

    安装微软Visual c++ 2012 Redistributable (x64) - 11.0.51106。没有影响。

  • Run "Dependency Walker for Win64(x64) Version 2.2.600, Developed by Steve P. Miller"

    运行“Win64(x64)版本2.2.600的依赖Walker,由Steve P. Miller开发”

  • File - Open - Generic.xll

    文件-打开- Generic.xll

  • It shows it can't find:
    -- XLCALL32.DLL // Typical from my Windows XP experience on working XLLs
    -- API-MS-WIN-CORE-COM-L1-1-0.DLL
    -- API-MS-WIN-CORE-WINRT-ERROR-L1-1-0.DLL
    -- API-MS-WIN-CORE-WINRT-L1-1-0.DLL
    -- API-MS-WIN-CORE-WINRT-ROBUFFER-L1-1-0.DLL
    -- API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL
    -- API-MS-WIN-SHCORE-SCALING-L1-1-0.DLL
    -- DCOMP.DLL
    -- IESHIMS.DLL // Typical from my Windows XP experience on working XLLs

    它显示它找不到:——XLCALL32。DLL //典型的Windows XP操作DLL的经验——API-MS-WIN-CORE-COM-L1-1-0。DLL,API-MS-WIN-CORE-WINRT-ERROR-L1-1-0。DLL,API-MS-WIN-CORE-WINRT-L1-1-0。DLL,API-MS-WIN-CORE-WINRT-ROBUFFER-L1-1-0。DLL,API-MS-WIN-CORE-WINRT-STRING-L1-1-0。DLL,API-MS-WIN-SHCORE-SCALING-L1-1-0。DLL,DCOMP。DLL,IESHIMS。DLL //典型的从我的Windows XP经验的工作XLLs。

So, now I'm stumped. I thought I had a 64-bit problem, but I'm beginning to wonder if I have a Windows 7 problem.

所以,现在我难住了。我以为我有64位的问题,但我开始怀疑我是否有Windows 7的问题。

Help?

帮助吗?

Thanks,

谢谢,

Tim

蒂姆

2 个解决方案

#1


1  

Sounds like you know a few things about this. XLCALL32 and IESHIMS in depends are not your problem.

听起来你知道一些关于这个的事情。XLCALL32和IESHIMS依赖不是你的问题。

My guess is that it is a 64-bit issue. I finally managed to get 64-bit builds working with http://xll.codeplex.com. Maybe you can find something there that you will find useful.

我猜这是一个64位的问题。我最终成功地获得了使用http://xll.codeplex.com的64位版本。也许你可以在那里找到一些有用的东西。

#2


0  

Watch out for the XLL load process. It's not the simple DLL load that we expect when we're writing code to be loaded by a normal process.

注意XLL加载过程。这并不是我们在编写由正常进程加载的代码时所期望的简单的DLL加载。

If you have a test program that runs perfectly - but then you add the working code to your Excel Add-in and get the "This file could be corrupted or unsafe" message... I suggest you:

如果您有一个运行完美的测试程序,但是您可以将工作代码添加到您的Excel插件中,并获得“该文件可能被损坏或不安全”的消息……我建议你:

  • check your initialization code for calls that Excel does not allow during the load process.
  • 检查您的初始化代码,寻找Excel在加载过程中不允许的调用。

If, during initialization, your code executes a call that Excel doesn't like you will get the meaningless error message and your add-in will be re-loaded as a text document. Unfortunately I haven't done my homework on the details regarding the restrictions imposed by Excel; in general, though, I've found that:

如果在初始化过程中,您的代码执行了一个Excel不喜欢的调用,您将得到无意义的错误消息,您的外接程序将作为文本文档重新加载。不幸的是,我没有做关于Excel强加限制的细节的作业;但总的来说,我发现:

  • The problem can be solved, very simply, by delaying the initialization.
  • 通过延迟初始化,可以非常简单地解决这个问题。

So far I've found the AutoOpen event has been handy (though there may be a better way - let me know if you find one.) I've used the following concept successfully to avoid this problem:

到目前为止,我发现AutoOpen事件很方便(尽管可能有更好的方法——如果你找到的话,请告诉我)。我已经成功地使用了以下概念来避免这个问题:

// within the AutoLoad event handler
static bool init_completed = false;
if ( init_completed == false )
{
   initialize_all();    
   init_completed = true;
}

This allows Excel to load the XLL successfully. By the time the AutoLoad event is called it seems that Excel does not impose any restrictions on the code - allowing the initialization code to execute.

这允许Excel成功加载XLL。在调用AutoLoad事件时,似乎Excel没有对代码施加任何限制——允许执行初始化代码。

Again, though, the AutoLoad event might not be the best place - YMMV - so please update this page if you find something better.

同样的,AutoLoad事件可能不是最好的地方- YMMV -所以如果你找到更好的东西,请更新这个页面。

I seriously hope I find this page quickly next time I make this mistake!

我真的希望下次犯这个错误的时候能尽快找到这个页面!

#1


1  

Sounds like you know a few things about this. XLCALL32 and IESHIMS in depends are not your problem.

听起来你知道一些关于这个的事情。XLCALL32和IESHIMS依赖不是你的问题。

My guess is that it is a 64-bit issue. I finally managed to get 64-bit builds working with http://xll.codeplex.com. Maybe you can find something there that you will find useful.

我猜这是一个64位的问题。我最终成功地获得了使用http://xll.codeplex.com的64位版本。也许你可以在那里找到一些有用的东西。

#2


0  

Watch out for the XLL load process. It's not the simple DLL load that we expect when we're writing code to be loaded by a normal process.

注意XLL加载过程。这并不是我们在编写由正常进程加载的代码时所期望的简单的DLL加载。

If you have a test program that runs perfectly - but then you add the working code to your Excel Add-in and get the "This file could be corrupted or unsafe" message... I suggest you:

如果您有一个运行完美的测试程序,但是您可以将工作代码添加到您的Excel插件中,并获得“该文件可能被损坏或不安全”的消息……我建议你:

  • check your initialization code for calls that Excel does not allow during the load process.
  • 检查您的初始化代码,寻找Excel在加载过程中不允许的调用。

If, during initialization, your code executes a call that Excel doesn't like you will get the meaningless error message and your add-in will be re-loaded as a text document. Unfortunately I haven't done my homework on the details regarding the restrictions imposed by Excel; in general, though, I've found that:

如果在初始化过程中,您的代码执行了一个Excel不喜欢的调用,您将得到无意义的错误消息,您的外接程序将作为文本文档重新加载。不幸的是,我没有做关于Excel强加限制的细节的作业;但总的来说,我发现:

  • The problem can be solved, very simply, by delaying the initialization.
  • 通过延迟初始化,可以非常简单地解决这个问题。

So far I've found the AutoOpen event has been handy (though there may be a better way - let me know if you find one.) I've used the following concept successfully to avoid this problem:

到目前为止,我发现AutoOpen事件很方便(尽管可能有更好的方法——如果你找到的话,请告诉我)。我已经成功地使用了以下概念来避免这个问题:

// within the AutoLoad event handler
static bool init_completed = false;
if ( init_completed == false )
{
   initialize_all();    
   init_completed = true;
}

This allows Excel to load the XLL successfully. By the time the AutoLoad event is called it seems that Excel does not impose any restrictions on the code - allowing the initialization code to execute.

这允许Excel成功加载XLL。在调用AutoLoad事件时,似乎Excel没有对代码施加任何限制——允许执行初始化代码。

Again, though, the AutoLoad event might not be the best place - YMMV - so please update this page if you find something better.

同样的,AutoLoad事件可能不是最好的地方- YMMV -所以如果你找到更好的东西,请更新这个页面。

I seriously hope I find this page quickly next time I make this mistake!

我真的希望下次犯这个错误的时候能尽快找到这个页面!