var
err:pchar;
begin
GetMem(err,128);
try
GetErrorMsg(ErrCode,err);{此函数是vc编写的dll中的,参数类型为int,unsignedhar*,在delphi定义为integer,pchar,要求调用后err带回字符串。可是调用的时候总是说project mm.exe raised exception class EAccessViolation with message 'Access violation at address 00402342 in modul me.exe.Read of address 3030302c',Process stopped.Use Step or Run to continue.各位给看看到底是什么原因?谢谢了}
finally
FreeMem(err,128);
end;
end;
err:pchar;
begin
GetMem(err,128);
try
GetErrorMsg(ErrCode,err);{此函数是vc编写的dll中的,参数类型为int,unsignedhar*,在delphi定义为integer,pchar,要求调用后err带回字符串。可是调用的时候总是说project mm.exe raised exception class EAccessViolation with message 'Access violation at address 00402342 in modul me.exe.Read of address 3030302c',Process stopped.Use Step or Run to continue.各位给看看到底是什么原因?谢谢了}
finally
FreeMem(err,128);
end;
end;
解决方案 »
- copy,leftstr,pos哪里效率更高
- excelapplication1打开Excel 出错(Access violation at address 00000000.Read of address 00000000)
- delphi2009有推出什么新书吗?
- 用TIdTCPClient读取Server返回数据的问题
- *.ini中如何删除的问题。
- 相求用Delphi编写的由Excel导入到sqlServer里的代码!着急了!!不够分再给!!
- DELPHI中引用计算列出错??
- ApplicationEvents的OnMinimize事件响应的是那个消息
- 关于一个错误,
- sql语句的问题
- 请教各位大哥QUICKREPORT的预览中总页数为什么会不停的增长?
- 关于多文本编辑,即有文本,还能够插入图片及其它控件对象
如果你有VC所写DLL的源代码,则需要重新声明GetErrorMsg函数,象这样:
extern "C" declspec(dllexport) void __stdcall GetErrorMsg(int, unsigned char *); // 好像是这样的,忘了!:(而你为了在Delphi中使用它,你需要声明:
Static call style:
procedure GetErrorMsg(const AErrorCode: Integer; var AErrMsg: PChar); stdcall;
//---------------------------------------------------------------
Dynamic call style:
TGetErrorMsg = procedure GetErrorMsg(const AErrorCode: Integer; var AErrMsg: PChar); stdcall
按照大家的方法,我先试试看,对了如何给这个贴子在加些分数,以分给帮助我的朋友,我觉得20分太少了。 :)
extern "C" void GetErrorMsg(int ErrCode, unsigned char *Error);
在管理功能中加分。
procedure GetErrorMsg(AErrorCode: Integer; AErrMsg: PChar); cdecl;
extern "C" declspec(dllexport) void GetErrorMsg(int, unsigned char *);
在DELPHI中的调用的形式类似于
GetErrorMsgErrCode:integer;varError:pchar):pointer;stdcall;external 'GDHZDSSK.dll' 而且我在DLL中的函数中用了malloc分配地址空间,也定义了释放内存的函数,在DELPHI中使用时,分配地址空间没有问题,但一释放就报错了。
另外在使用DLL中函数生成的链表时,在DELPHI中向其增加一个节点时,在节点生成的那个过程中(使用NEW或GETMEM的过程中),这个链表是正常的,但在其它地方对这个链表操作时,新加的节点的内容发生了变化(我有全局变量记录该链表,而且所加节点前的链表是对的)。我想谁能解释一个在DLL调用时,地址分配是怎么样的,在DLL中分配的空间,在外部可否以一般的方式操作
forza(象风一样):declspec(dllexport) 是什么意思?
Header文件中:
extern "C" void __stdcall GetErrorMsg(int, unsigned char *);CPP文件中:
void __stdcall GetErrorMsg(int ErrorCode, unsigned char *ErrorMsg)
{
// Your code
}.DEF文件中:
EXPORTS
GetErrorMsg;Delphi中静态调用的声明:
procedure GetErrorMsg(const ErrorCode: Integer; var ErrorMsg: PChar); stdcall;
external "SharedDLL.DLL" name "GetErrorMsg";
(其中SharedDLL.DLL是你的VC写的DLL文件名)