在C++的动态库中,有几个函数,C++中申明如下:
int Init();
int Release();
int Send(const char *sDest);
int Recv(RECV *pRecv, int nLen);RECV为结构体,定义如下:
typedef struct recv
{
char sDest[10];
char sSource[10];
}RECV;
申明头文件前面内容为:
#ifdef __cplusplus
extern "C"{
#endif#ifndef _WIN32
#define _WIN32
#endif#ifdef _WIN32
#define IMAPI_API __declspec(dllexport)
#endif在Delphi下,我写的调用代码为:
type
TRECV = record
sSourceNo: array[0..10] of char;
sDestNo: array[0..10] of char;
end;
pRECV = ^TRECV;TInit = function():integer; stdcall;
TRelease = function () :integer; stdcall;
// TSend = function (const sOrder: array of char): integer; stdcall;
TSend = function (const sOrder: PChar): integer; stdcall;
TRecvSm = function (pRecv : pRECV; nLen : integer) :integer; stdcall;
var
Init: TInit;
Release: TRelease;
Send: Tend;
Recv: TRecv;加载动态库后(LoadLibrary,GetProcAddress),调用函数,调用Init()时,返回正确值,但是调用Send()时,就出错了,说是地址无效(Send(PChar('123'))).请这是为什么呢?
还有,那个结构体参数如何使用呢?
希望高手指点!
谢谢!
int Init();
int Release();
int Send(const char *sDest);
int Recv(RECV *pRecv, int nLen);RECV为结构体,定义如下:
typedef struct recv
{
char sDest[10];
char sSource[10];
}RECV;
申明头文件前面内容为:
#ifdef __cplusplus
extern "C"{
#endif#ifndef _WIN32
#define _WIN32
#endif#ifdef _WIN32
#define IMAPI_API __declspec(dllexport)
#endif在Delphi下,我写的调用代码为:
type
TRECV = record
sSourceNo: array[0..10] of char;
sDestNo: array[0..10] of char;
end;
pRECV = ^TRECV;TInit = function():integer; stdcall;
TRelease = function () :integer; stdcall;
// TSend = function (const sOrder: array of char): integer; stdcall;
TSend = function (const sOrder: PChar): integer; stdcall;
TRecvSm = function (pRecv : pRECV; nLen : integer) :integer; stdcall;
var
Init: TInit;
Release: TRelease;
Send: Tend;
Recv: TRecv;加载动态库后(LoadLibrary,GetProcAddress),调用函数,调用Init()时,返回正确值,但是调用Send()时,就出错了,说是地址无效(Send(PChar('123'))).请这是为什么呢?
还有,那个结构体参数如何使用呢?
希望高手指点!
谢谢!
解决方案 »
- 窗口标题栏高难度编程,放分
- 怎样在DBGrid中显示MS Access中的memo数据?
- 请问Delphi7有没有像D6中的CorbaConnection和Corba Data Module那样的控件及向导?
- 如何读取和改写注册表里REG_MULTI_SZ类型的值???,100百分相送,答案正案可再开一贴!!!在线等!
- adoquery1奇怪问题
- delphi中有對數值進行四舍五入的函數嗎﹖
- 如何修改RichEdit控件某一行的背景颜色
- 如何更改选中DBGrid记录的高亮颜色? >>>>
- 请问:在DELPHI中如何使用Pipe???(有例程最好:)
- 请教用DELPHI该如何创建和调用DLL工程文件?
- 恼人的MessageBox
- 怎么用DElPHI语言控制SQl SERVER 的运行状态.(关闭SQL SERVER 和打开SQL SERVER 服务器)
用如下試下:
var p:pcahr;
begin
GetMem(p, 1024);
copy(p..
send ...
FreeMem(p);
end;還有:
TRECV = packed record //這行
sSourceNo: array[0..10] of char;
sDestNo: array[0..10] of char;
end;
sSourceNo: array[0..10] of char;
sDestNo: array[0..10] of char;
end;改成 TRECV =packed record
sSourceNo: array[0..10] of char;
sDestNo: array[0..10] of char;
end;试试
在Delphi中调用,同样也是错误,错误类型是一样的!
不甚感激!!!