在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'))).请这是为什么呢?
还有,那个结构体参数如何使用呢?
希望高手指点!
谢谢!
解决方案 »
- PHP中crypt()加密函数delphi实现
- TIdHTTPWebBrokerBridge在dxe中乱码
- 从TGraphicControl继承写edit控件的问题
- 模式窗口问题
- SocketConnection.Port端口号怎样动态指定???
- 请问"="的用法
- 关于DSPack?
- 我要PDF
- 我的form中有很多label,我如何在for语句中用他们?
- 我是一名菜鸟,请问高手,在Delphi中,IntraWeb 建立三层数据库访问的步骤?~~~急!!!!~~~50分
- 恼人的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中调用,同样也是错误,错误类型是一样的!
不甚感激!!!