Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encounter error using DataExplorer.exe to connect to home grown DBX4 driver

I have written my own DBX 4 in Delphi 2010 for Firebird database. The driver is a dynalink driver and it works fine with TSQLConnection.

Recently, I try to use the DataExplorer.exe released with Delphi 2010 and encounter error:

"Attempted to read or write protected memory.
 This is often an indication that other memory is corrupt".

After trace the source code, I found the following export method may be the cause of the problem:

function DBXLoader_GetDriver(Count: TInt32; Names, Values: TWideStringArray;
  ErrorMessage: TDBXWideStringBuilder; out pDriver: TDBXDriverHandle):
  TDBXErrorCode; stdcall;

When debugging this method, the Names and Values parameter contain corrupted value. I don't know what cause the problem. Perhaps there is some memory manager problem with DataExplorer.exe (.net issue?)

After some trial and error, I attempt to change the method to as follow:

type
  TWideStringArray2 = array of PChar;

function DBXLoader_GetDriver(Count: TInt32; Names, Values: TWideStringArray2;
  ErrorMessage: TDBXWideStringBuilder; out pDriver: TDBXDriverHandle):
  TDBXErrorCode; stdcall;

This time, the error is gone and soon after it exit this method, the same error raise again

"Attempted to read or write protected memory.
This is often an indication that other memory is corrupt".

Do you have any ideas what could the the cause of the problem?

like image 963
Chau Chee Yang Avatar asked Nov 24 '10 14:11

Chau Chee Yang


1 Answers

Looks like you have some memory allocation problems. Are you using SimpleShareMem eventualy?

http://docwiki.embarcadero.com/CodeExamples/en/SimpleShareMem_Sample - describes how to use it.

http://www.codexterity.com/memmgr.htm - also contains some insights on memory allocation but with older approachi using FastSharemem module.

like image 131
SPDenver Avatar answered Nov 08 '22 13:11

SPDenver