vc下的数组在delphi中调用(50分)

  • 主题发起人 johnathon
  • 开始时间
J

johnathon

Unregistered / Unconfirmed
GUEST, unregistred user!
自己试了好久都没有结果。
在vc中是用Win32 Dynamic-link Library 建立的dll,导出函数的形式是:
extern "C"
_declspec(dllexport) __stdcall int curves(int n, float a[], float b[])
就是想问在delphi6里面怎么调用curves这个函数
谢了~
 
根据DLL中函数导出的定义来做
最简单的是在delphi单元中申明一下
function curves(n:Integer;
a,b:array of Float) : Integer;
external 'dllname.dll'
name 'curves';
就可以啦~
当然也可以用动态调用,稍微麻烦点了
 
为什么不用 array of single?
 
可是,这样了:
[Error] uvcdllPoint.pas(26): Undeclared identifier: 'Float'
应该说是没有float这个类型吧。
之前,我用的是array of single,老是报:
Access violation at address 10001d71 in Module 'dll.dll'.Write of address 000063.
 
只要类型一致就可以了
还有就是不同语言之间会有些差别
Float类型应该是有的啊,可能我记错了吧
single应该是一样的吧,你调试一下看看呢?在delphi里跟踪~
 
不行啊。如果是:
function arr(n:Integer;
a,b:array of single):Integer;
external 'dll.dll';
可以调用,但返回的是类似没有赋值情况下的随机结果。
如果加入 stdcall:
function arr(n:Integer;
a,b:array of single): Integer;stdcall;
external 'dll.dll';
就会报错:
Access violation at address 10001d71 in Module 'dll.dll'.Write of address 000063.
 
stdcall需要增加,因为vc是按照标准调用生成执行程序的。
跟踪的情况是不是进不到函数里呢?
你用vc调试一下吧。不知道你会不会dll调试的设置?
 
可是我不会跟踪啊。
在vc下的函数很简单,只是作为一个测试函数:
extern "C"
_declspec(dllexport) __stdcall int arr(int n, float a[], float b[])
{
for(int i=0;i<n;i++)
{
a=i;
b=10.0 + i;
}
return n;
}
不管怎样只要能在delphi下面调用就可以了,问题是怎样调用?
vc不是用的很多,delphi还用的比较多~
 
在vc的调试中使用attach进程的方式,
今天下班了,不能在帮你了,抱歉~
 
啊,神啊,救救我吧~
 
解决了没有啊?
 
没有~
如果是使用一个数组就没有问题。
如果是两个数组就不行了,问了,说是压栈的问题。
现在还不知道怎么办。
 
type
PFloat = ^Single;
function arr(n:Integer;
a,b:pFloat): Integer;stdcall;
external 'dll.dll';
 
按照楼上的搞掂了没有?
还不行把代码发过来看看吧,要调试下才知道(好多东西忘记了,要回想下子)。
 
顶部