|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
我做了不少DLL,以前在VBA下调用都没问题,
最近做个东西,需要在DLL里面回调Excel VBA(和Acad)的处理过程,
系统平台和Excel都是64位的,
----------------VS 2010 旗舰版 --------------------------
C++中回调函数的原型如下:
typedef int (__stdcall * CBDocInfo)(HzemDocInfo * DocInfo);
DLL 入口函数:
#ifdef HZMFC_EXPORTS
#define HZMFC_API __declspec(dllexport)
#else
#define HZMFC_API __declspec(dllimport)
#endif
...........
extern "C" HZMFC_API int __stdcall ProjectManage( CBDocInfo Collect, CBDocInfo Inspect, CBDocInfo Generate, CBDocInfo Update)
{
............
}
.Def 输出
--------------Excel 2013 64位 ------------------------------------
声明:
Declare PtrSafe Function ProjectManage Lib "HZMFC.dll" (ByVal Collect As LongPtr, ByVal Inspect As LongPtr, ByVal Generate As LongPtr, ByVal Update As LongPtr) As Long
回调函数:
Public Function Collect(ByRef DocInfo As HzemDocInfoB) As Long
Dim Rt As Integer
Rt = StringUToA("Collect 回调函数测试", DocInfo.m_Proj.Comment)
Collect = 1
End Function
Public Function Inspect(ByRef DocInfo As HzemDocInfoB) As Long
Dim Rt As Integer
Rt = StringUToA("Inspect 回调函数测试", DocInfo.m_Proj.Comment)
Inspect = 1
End Function
'生成数据表
Public Function Generate(ByRef DocInfo As HzemDocInfoB) As Long
..................................
..................................
End Function
Public Function Update(ByRef DocInfo As HzemDocInfoB) As Long
Dim Rt As Integer
Rt = StringUToA("Update 回调函数测试", DocInfo.m_Proj.Comment)
Update = 1
End Function
VBA调用 DLL 语句:
Private Sub CProjectManage_Click()
...................
Rt = ProjectManage(AddressOf Collect, AddressOf Inspect, AddressOf Generate, AddressOf Update)
...................
End Sub
----------------问题---------------------------------------
进去后无论咋弄,都是只有第一个参数正确,
然后排在后面的参数都不正确,
无论第一个排的是long double 还是自定义类型;
始终只有第一个参数正确
象这样的调用运行就很良好
extern "C" HZMFC_API int __stdcall TestCB( CBDocInfo MakeDoc )
但 假若你 往里面加俩参数,排在后面的立马乱套;
|
|