如何从VBA(Excel Visual Basic)中的DLL接收“char * d”?

现在我试图得到一个string作为下面的c函数。

这是DLL的C函数,

char _stdcall *fmt_hex(long long num, int nbits, char *d) { sprintf(d, "0x%0*llX", (nbits - 1) / 4 + 1, num); return (d); } 

下面是Excel VBAfunction。

 Option Explicit Private Declare PtrSafe Function pll_dll Lib "F:\work\pll_dll\x64\Debug\pll_dll.dll" (ByVal num As LongLong, ByVal nbits As Integer, ByRef d As String) Dim d As String Sub useSquareInVBA() Cells(4, 4).Text = pll_dll(3, 4, d) End Sub 

但是当我运行这个代码时,程序暂停了。 你能给我怎么解决这个问题?

UPDATE2

当我运行这个代码“C”

 #include <stdio.h> #include <stdlib.h> #include <math.h> double _stdcall pll_dll(double* datain0, double* datain1, double* dataout0, double* dataout1, char * str) { dataout0[0] = datain0[0] + 10; dataout1[0] = datain1[0] + 10; str ="c"; return 0; } 

“VBA”

 Option Explicit Private Declare PtrSafe Function pll_dll Lib "F:\work\pll_dll\x64\Debug\pll_dll.dll" _ (ByRef x_in As Double, ByRef y_in As Double, ByRef x_out As Double, ByRef y_out As Double, ByRef str As String) As Double Dim Error As Integer Dim d1 As Double Dim d2 As Double Dim d3 As Double Dim d4 As Double Dim sometext As String Function pll_dll_excel(data1 As Double, data2 As Double, data3 As Double, data4 As Double, text As String) As Double pll_dll_excel = pll_dll(data1, data2, data3, data4, text) End Function Sub useSquareInVBA() MsgBox pll_dll_excel(3, 4, d1, d2, sometext) Cells(5, 5).Value = d1 Cells(6, 6).Value = d2 Cells(7, 7).Value = sometext End Sub 

不,程序暂停,但有些文本总是空的“价值”。

你能帮我吗?

UPDATE3

我从这里检查了这篇文章。

如何从DLL中返回一个未知大小的string到Visual Basic

当我按照这篇文章,我意识到这不是“C”。 我如何制作一个“C”?