The code in your question works fine. Which means that the problem lies elsewhere. Here's the proof:
C++
#include <Windows.h>
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
extern "C" {
__declspec(dllexport) double* SomeMethod(double)
{
double* array = new double[2];
array[0] = 42;
array[1] = 666;
return array;
}
}
Delphi
{$APPTYPE CONSOLE}
uses
Windows, SysUtils;
type
TSomeMethod = function(level : Double): PDouble; cdecl;
var
SomeMethod: TSomeMethod;
arr: PDouble;
lib: HMODULE;
begin
lib := LoadLibrary('MyDll.dll');
Win32Check(lib<>0);
SomeMethod := GetProcAddress(lib, 'SomeMethod');
Win32Check(Assigned(SomeMethod));
arr:= SomeMethod(15);
Writeln(arr^:3:0);
inc(arr);
Writeln(arr^:3:0);
Readln;
end.
Output
42 666