Dear All,
Now I'm trying to receive the string return value from DLL to VBA.
"C-DLL code "
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 = "buff";
return 0;
}
and the below is the VBA code
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
Dim str As String
Dim s As String, intChars As Long
s = Space$(128)
Sub useSquareInVBA()
Cells(8, 8).Value = pll_dll(3, 4, d1, d2, s) ' s is not working ( it can't get it well)
End Sub
when I ran above code, I've got receive well the d1 and d2 data but the problem is that "s" I can't get it.
Is it possible to directly return the resulting string from the DLL? Or is there any other way to dynamically allocate a string object depending on the length of the result and return it to a VB caller?
I tried different approaches, for example like this (ugly, just examples), but I can't get exactly the string value what I want.
Bookmarks