3

我正在尝试创建一个简单的 xll 文件,但我不能按照 msdn 站点 http://support.microsoft.com/kb/178474中的教程进行操作, 但本教程适用于 Microsoft Excel 97 Developer's Kit,我只有 2007 版和 Visual Studio 2005,所以这可能是导致错误的原因:

1>------ Build started: Project: Anewxll, Configuration: Debug Win32 ------
1>Compiling...
1>Anewxll.cpp
1>c:\nam\test\anewxll\anewxll\anewxll.cpp(97) : error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types
1>        c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(5031): could be 'int AfxMessageBox(LPCTSTR,UINT,UINT)'
1>        c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(5033): or 'int AfxMessageBox(UINT,UINT,UINT)'
1>        while trying to match the argument list '(const char [21], long)'
1>c:\nam\test\anewxll\anewxll\anewxll.cpp(140) : error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types
1>        c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(5031): could be 'int AfxMessageBox(LPCTSTR,UINT,UINT)'
1>        c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(5033): or 'int AfxMessageBox(UINT,UINT,UINT)'
1>        while trying to match the argument list '(char [8192], long)'
1>c:\nam\test\anewxll\anewxll\anewxll.cpp(174) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [14]' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
4

2 回答 2

3

您收到的错误消息与 Excel 或 Excel SDK 无关。前 2 个错误是由于您使用了 AfxMessageBox(一个 MFC API),而第 3 个错误是因为参数与 Win32 消息框 API 不匹配。这些错误是因为您的项目是一个 Unicode 应用程序(导致 TCHAR 计算为 wchar_t 而宏如 MessageBox 计算为 MessageBoxW 而不是 MessageBoxA)。最简单的解决方法是将应用程序从 Unicode 更改为 MBCS。

但是 - 如果我可以提出建议 - 考虑使用 Add-in express 或 ExcelDNA 来创建您的 UDF/RTD。我猜你对 Win32 C++ 编程不是很满意。如果是这种情况,使用纯 C++ 和 Excel SDK 创建 UDF/RTD/Addins 将面临很多麻烦。

相反,如果您使用 add-in express 或 excel dna - 他们会处理将 xlopers 转换为直观的 .net 类型和其他各种管道的所有麻烦,让您可以自由地专注于您的业务逻辑。

免责声明:我与加载项 express 或 excel dna 没有任何关系。我只是碰巧打开和关闭使用它们。

于 2013-02-05T18:12:48.157 回答
2

如果您可以安装 MSVC++ 2010 Express,那么http://xll.codeplex.com将为您省去很多麻烦。

于 2012-05-28T16:43:27.620 回答