2011-04-21 102 views
3

我試圖創建只是一個簡單的XLL文件,但我不能 我已經按照在MSDN網站 http://support.microsoft.com/kb/178474 的教程,但本教程是爲Microsoft Excel 97開發工具包,我只是有版本2007 的Visual Studio 2005中,所以這也許是什麼導致錯誤:如何爲excel創建一個xll?

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 
+2

更新的文檔和SDK http://msdn.microsoft.com/en-us/library/aa730920%28v=office.12%29.aspx – 2011-04-21 15:55:30

回答

3

您擁有的錯誤消息與Excel或Excel SDK無關。前兩個錯誤是由於您使用了AfxMessageBox(一個MFC API),第三個錯誤是因爲與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會遇到很多麻煩。

如果您使用附加的express或excel dna,他們會將所有令人頭疼的問題轉化爲直觀的.net類型和其他各種管道,讓您可以專注於業務邏輯。

免責聲明:我與加載項快遞或excel dna沒有任何關係。我剛剛碰巧使用過它們。