I have a problem with using dll library made in delphi. I don't have sources for it - only dll and interface. I want to import it in my c++ program. I don't need to use QT for loading (but it would be probably the best option as ) - also standard Windows api is applicable.
First, interface of the dll:
Unit VPInterface;
interface
type
TSignal = array of double;
ShortVector = array[0..11] of double;
function VP(s: TSignal): ShortVector; stdcall;
stdcall external 'VoicePrint.dll' name 'VP';
implementation
End {VPInterface.pas}.
The QT version:
typedef double* (*VPFunct)(double[]);
vector<double> v_double;
// put some values in v_double
QLibrary lib("VoicePrint.dll");
VPFunct vpfunct = (VPFunct) lib.resolve("VP");
if (vpfunct) {
double * res = vpfunct(&v_double[0]);
}
- The function is called and some output is returned but it's rubbish. As you can see I passed internal vector's array (&v_double[0]). I tried with double array on stack but the function haven't finished. Can someone explain it why?
Why I don't see correct results? I have similar code in C# and it works:
namespace WAT_DLL_TEST { public class VoicePrint { [DllImport("VoicePrint.dll", CharSet = CharSet.Ansi, EntryPoint = "VP", CallingConvention = CallingConvention.StdCall)] [return: MarshalAs(UnmanagedType.Struct)] public static extern ShortVector VP(double[] signal); [StructLayout(LayoutKind.Explicit, Size = 48)] public unsafe struct ShortVector { [FieldOffset(0)] public fixed double m_buffer[6]; } } }
May a structure be the actual problem?
And here is my code for running it using windows api:
HINSTANCE hinstDLL;
VPFunct myFunct;
BOOL fFreeDLL;
hinstDLL = LoadLibrary(L"VoicePrint.dll");
if (hinstDLL != NULL)
{
myFunct = (VPFunct) GetProcAddress(hinstDLL, "VP");
if (myFunct != NULL) {
double * dptr = myFunct(&v_double[0]);
for(int i=0; i<11; i++)
cout << dptr[i] << endl;
}
fFreeDLL = FreeLibrary(hinstDLL);
}
Thanks for any help.