如何在VBA中声明一个接受XlfOper(LPXLOPER)类型的参数的函数? [英] How do I declare a function in VBA which accepts arguments of type XlfOper (LPXLOPER)?

查看:226
本文介绍了如何在VBA中声明一个接受XlfOper(LPXLOPER)类型的参数的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在以前的问题的答案中找到了一种调用(C ++)定义的函数的方法, xll没有注册。我以前使用XLW提供的注册基础设施,我正在使用XlfOper类型传递VBA和xll之间的参数。

I have found out in the answer to a previous question a way to call a function defined in a (C++) xll without registering it. I was previously using the registering infrastructure provided by XLW and I was using the XlfOper type to pass the arguments between VBA and the xll.

c ++函数如下所示: / p>

The c++ function goes like this:

extern "C" {
LPXLOPER EXCEL_EXPORT a_function(XlfOper arg1, XlfOper arg2);
}

根据我以前的解决方案的答案,我直接声明这个功能,像这样:

Following the answer to my previous solution, I am directly declaring the function, something like that:

Declare Function an_exported_function Lib "MyDrive:\MyPath\myxll.xll"_
          Alias "a_function" (arg1 As Object, arg2 As Object) as Object

通过附加到excel进程,我可以看到该函数正在被调用,但是我在参数中获取垃圾或空数据。这个,我想是来自于我没有告诉VBA如何转换为正确的数据类型。

By attaching to the excel process I can see that the function is being called but I am getting garbage or null data in the arguments. This, I guess, comes from the fact that I have not told to VBA how to convert to the correct data type.

如何正确调用XlfOper参数?我认为调用LPXLOPER应该做这个工作,因为xlw会声明如下:

How can I correctly call an XlfOper argument? I think that calling an LPXLOPER should do the job, since xlw states the following:


重要的是不要添加任何数据成员或虚拟
函数到这个类。 xlw的设计依赖于类
XlfOper与LPXLOPER / LPXLOPER12具有相同大小的事实,这个假设允许从Excel接收的那些类型的
值由库
解释为实例的XlfOper。

It is important not to add any data members or virtual functions to this class. The design of xlw relies on the fact that class XlfOper has the same size as LPXLOPER/LPXLOPER12, this assumption allows values of those types received from Excel to be interpreted by the library as instances of XlfOper.


推荐答案

经过一些研究,我发现它:传递用户定义的类型

After some research i have found it: Passing User-Defined Types

MSDN写道: 许多DLL函数要求您使用预定义的格式传入数据结构。从VBA调用DLL函数时,您传递一个根据函数要求定义的用户定义类型。

所以,你需要定义XlfOper数据结构;)

So, you need to define XlfOper data structure ;)

这篇关于如何在VBA中声明一个接受XlfOper(LPXLOPER)类型的参数的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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