Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excel 调用 DLL #49

Open
topcss opened this issue Oct 25, 2019 · 0 comments
Open

Excel 调用 DLL #49

topcss opened this issue Oct 25, 2019 · 0 comments
Labels

Comments

@topcss
Copy link
Owner

topcss commented Oct 25, 2019

这篇帖子[1]可读性极差,图片不清晰,排版让人恼火。将就一下,我们重点是看内容。下面我来复述一遍:

一、分成 2 步来实现:

  1. 在 vs 中创建一个 c++ 项目,用来生成 DLL
  2. 在 Excel 中如何引用这个 DLL 提供的方法

二、踩过的坑:

  1. Excel 报错很迷惑人,明明文件存在,报错说文件不存在。
  2. Excel 的版本和你 DLL 的版本不一致,x86/x64。
  3. 没有设置 模块定义文件 def 文件。
  4. def 文件的内容不对,包括项目名称 LIBRARY ,导出的函数名 EXPORTS 不一致 。
  5. Excel 引用的方法不对,要参照我这样写。
  6. 在 vs 不要用选项目生成,要按 F5。虽然无法用F5调试,但 F5 会生成正确的 DLL(这条非常重要)
Private Declare PtrSafe Function Add Lib "C:\Users\Jack\source\repos\cppDll1\x64\Debug\cppDll.dll" (ByVal x As Long,ByVal y As Long) As Long

参考文章:

[1] EXCEL调用C++生成的DLL文件

@topcss topcss added the C++ label Oct 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant