delphiExcel UDF与变种返回types

我有一个使用ExecuteExcel4Macro注册UDF的加载项。 这工作正常。 只有在当前会话中检测到兼容工作簿时才会注册该加载项。

问题是我想改变当前的UDF从返回只是一个字符,但一个字符或Excel错误。

我发现了一些关于使用types库的文章,但我相信这意味着我的UDF将始终被注册,并且我想在注册时控制它们。

我目前正在注册

ExcelApp.ExecuteExcel4Macro('REGISTER("filepath","add-in-name","AccountDescription","CC","Account Id","My Addin group")'); function AccountDescription ( sAccountId: PChar ) : PChar ; stdcall ; 

我正在使用add-in-express来帮助实现Excel自动化。 CC指示该函数接受一个以空字符结尾的string,并期望返回一个以空字符结尾的string。 我不知道我是否可以指定一个变体,所以我可以返回Excel2000.xlErrNa。

编辑:上面修复了函数调用,我忘记了注册。

编辑(2):注册函数中的第四个参数包含udf参数和返回值types。 我不确定如何表示变体。

编辑(3):该dll /项目被称为DynacViews2和DynacViews2.dll源文件中有:

 exports AccountDescription; 

对不起,如果这是一个小碎片。 我想强调的是,这与目前上面的代码一起工作。 问题是试图改变AccountDescription的签名来返回一个OleVariant而不是一个PChar。

更改的原因是我想返回一个string或一个Excel错误。 在线的其他示例(包括add-in-express)显示使用TypeLibrary添加函数并将返回types指定为variant。 这将使用OleVariant创build一个签名,并且可以返回一个string或Excel错误(Excel2000.xlErrNa)。 问题是我正在使用VBA REGISTER函数只添加UDF的,如果工作簿是兼容的。

我可能会错误地解决这个问题。

编辑4: 注册使用示例 – 此链接显示注册使用情况,但不链接到任何微软站点,所以没有解释如何指定参数。

根据使用CALL和寄存器function ,Variant不在支持的数据types之中。

 Code Description Pass by C Declaration A Logical (FALSE = 0), TRUE = 1) Value short int B IEEE 8-byte floating-point number Value (Windows) double (Windows) Reference (Macintosh) double * (Macintosh) C Null-terminated string Reference char * (maximum length=255) D Byte-counted string (first byte Reference Unsigned char * contains length of string, maximum string length = 255 characters) E IEEE 8-byte floating-point number Reference double * F Null-terminated string (maximum Reference (modify char * string length = 255 characters) in place) G Byte-counted string (first byte Reference (modify contains length of string, maximum in place) unsigned char * string length = 255 characters) H Unsigned 2-byte integer Value unsigned short int I Signed 2-byte integer Value short int J Signed 4-byte integer Value long int K Array Reference FP * L Logical (FALSE = 0, TRUE = 1) Reference short int * M Signed 2-byte integer Reference short int * N Signed 4-byte integer Reference long int * O Array Reference Three arguments are passed: unsigned short int * unsigned short int * double [ ] P Microsoft Excel OPER data structure Reference OPER * R Microsoft Excel XLOPER data structure Reference XLOPER *