VC中的dll:
// tryt1.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}typedef struct input
{
int iN;
int iM;
double iC_RON[NN];
double iC_TD[NN];
double iC_MT[NN];
double iP_RON[MM];
double iP_MT[MM];
}INPUT;
typedef struct output
{
double chromosome[NN*MM];
double cp[MM];
double fitness[MM];
double value;
}OUTPUT;extern "C"_declspec(dllexport) OUTPUT WINAPI tryt1( INPUT in, OUTPUT *out )
delphi中调用dll:type
input = Record
N:integer;
M:integer;
iC_RON:array [1..NN] of double;
iC_TD:array [1..NN] of double;
iC_MT:array [1..NN] of double;
iP_RON:array [1..MM] of double;
iP_MT:array [1..MM] of double; end; output = Record
chromosome:array[1..NN*MM]of Double;
cp:array[1..MM]of Double;
fitness:array[1..MM]of Double;
value:Double; end; TPoutput = ^output;
function tryt1(inx : input; outx:TPoutput): output; stdcall; external 'tryt1.dll' index 1;procedure TForm1.Button1Click(Sender: TObject);
var
inx : input;
outx : output;
iResult:output;
iResult := tryt1( inx, @outx ); showmessage( floattostr(iResult.value));
为什么编译通过后,出现“Project1.exe raised exception class EInvalidOp with message ''Invalid floating point operation' Process stopped. ”
这是什么原因?
// tryt1.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}typedef struct input
{
int iN;
int iM;
double iC_RON[NN];
double iC_TD[NN];
double iC_MT[NN];
double iP_RON[MM];
double iP_MT[MM];
}INPUT;
typedef struct output
{
double chromosome[NN*MM];
double cp[MM];
double fitness[MM];
double value;
}OUTPUT;extern "C"_declspec(dllexport) OUTPUT WINAPI tryt1( INPUT in, OUTPUT *out )
delphi中调用dll:type
input = Record
N:integer;
M:integer;
iC_RON:array [1..NN] of double;
iC_TD:array [1..NN] of double;
iC_MT:array [1..NN] of double;
iP_RON:array [1..MM] of double;
iP_MT:array [1..MM] of double; end; output = Record
chromosome:array[1..NN*MM]of Double;
cp:array[1..MM]of Double;
fitness:array[1..MM]of Double;
value:Double; end; TPoutput = ^output;
function tryt1(inx : input; outx:TPoutput): output; stdcall; external 'tryt1.dll' index 1;procedure TForm1.Button1Click(Sender: TObject);
var
inx : input;
outx : output;
iResult:output;
iResult := tryt1( inx, @outx ); showmessage( floattostr(iResult.value));
为什么编译通过后,出现“Project1.exe raised exception class EInvalidOp with message ''Invalid floating point operation' Process stopped. ”
这是什么原因?
function tryt1(inx : input; var outx:output): output; stdcall; external 'tryt1.dll' index 1;
//iResult := tryt1( inx, @outx );
iResult := tryt1( inx, outx );
TRYT1_API OUTPUT tryt1( INPUT in, OUTPUT *out )
{
OUTPUT p;
p.value=200;
return p;
}
delphi的结果为200Invalid floating point operation
一般为浮点计算出错,查你的dll的tryt1函数
http://www.agui.googlepages.com
mailto: agui.cn(a)gmail.com
input = Record
N:integer;
M:integer;
iC_RON:array [1..NN] of double;
iC_TD:array [1..NN] of double;
iC_MT:array [1..NN] of double;
iP_RON:array [1..MM] of double;
iP_MT:array [1..MM] of double; end;这结构的对齐方式需要和C里一致
type
input = packed record //<<<
N:integer;
M:integer;
iC_RON:array [0..NN-1] of double;
iC_TD:array [0..NN-1] of double;
iC_MT:array [0..NN-1] of double;
iP_RON:array [0..MM-1] of double;
iP_MT:array [0..MM-1] of double;
end;
//同样
output = packed record
chromosome: array[0..NN*MM - 1]of Double;
cp: array[0..MM-1]of Double;
fitness: array[0..MM-1]of Double;
value: Double;
end;
对的,就是这句showmessage( floattostr(iResult.value)) 出错的,我是刚学delphi的,怎么在调试器中看它的值?
http://www.agui.googlepages.com
mailto: agui.cn(a)gmail.com