发布从excel VBA调用的C ++ DLL [英] Releasing C++ DLL called from excel VBA

查看:168
本文介绍了发布从excel VBA调用的C ++ DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我用EXCEL VBA中创建的宏成功调用了用c ++编写的dll函数。



使用Declare语句调用该函数:



Hi everyone,

I call successfully a dll function written in c++ from a macro created in EXCEL VBA.

the function is called with a Declare statement:

Private Declare PtrSafe Function FourierSerieCoeffs Lib "D:\OutBin\ISLib.dll" (ByVal T As Double, ByVal n As Long, ByVal nEq As Long, ByRef x As Double, ByRef fx As Double, ByRef outC As Double) As Long





第一次执行宏后,我无法重建dll,因为Excel似乎仍在使用它。



打开excel文件重建dll项目的唯一方法是在宏的末尾添加这些行:





After the first execution of the macro it is impossible for me to rebuild the dll because it seems that Excel is still using it.

The only way to rebuild the dll project with the excel file opened is to add at the end of the macro these lines:

hMod = GetModuleHandle("ISLib.dll")
Do Until FreeLibrary(hMod) = 0
   
Loop





使用这些行我可以编译c ++项目但是如果我再次执行宏excel崩溃。



任何建议在下一次执行中没有make excel崩溃的情况下释放dll吗?



谢谢



我尝试了什么:





with these lines i can compile the c++ project but if I execute again the macro excel crashes.

Any suggestion to release the dll without make excel crash in the next executions?

Thanks

What I have tried:

I tried calling the library again with LoadLibrary at the beginning of the macro but it doesn't work.

推荐答案

我不确定这是否有所帮助,因为我使用的是VBA,但是可能试一试。



当你不关闭Excel并重新启动宏时,它不一定完全编译(生成的字节代码仍然在内存中)并执行)。



要检查这一点,请在更新DLL后编辑宏源或在VBA编辑器的调试菜单中选择编译以确保它是编译。



旧的Office版本有一个按需编译选项,它也可以确保在关闭时重新编译。
I'm not sure if this helps and it's is along time ago since I have used VBA but you might give it a try.

When you don't close Excel and restart the macro, it is not necessarily compiled completely again (the generated byte code is still in memory and executed).

To check this, edit the macro source or choose "Compile" in the Debug menu of the VBA editor after updating the DLL to ensure that it is compiled.

With old Office versions there was a "Compile on Demand" option which may also ensure re-compilation when turned off.


谷歌就是你朋友:发布从excel VBA调用的C DLL - Google搜索 [ ^ ]
Google is your friend: Releasing C DLL called from excel VBA - Google Search[^]


这篇关于发布从excel VBA调用的C ++ DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆