Intro Download and install Frequently Asked Questions Tips and tricks

Homepage







© J.C. Kessels 2009
MyDefrag Forum
April 19, 2014, 02:57:33 am *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1] 2 3 4
  Print  
Author Topic: Error Use Library In Delphi.  (Read 51949 times)
snowvalley
JkDefrag Junior
**
Posts: 7


View Profile
« on: April 29, 2007, 06:04:36 pm »

I trans the codes to Delphi:

unit DefragAPI;

interface
uses Windows, DataUnit;

type
  TDefragShowStatusCallback=function(Data: PDefragDataStruct): Integer; stdcall;
  TDefragShowMoveCallback = function(Item: PItemStruct; Clusters, FromLcn, ToLcn: ULONG64 ): Integer; stdcall;
  TDefragShowAnalyzeCallback = function(Data: PDefragDataStruct; Item:PItemStruct): Integer; stdcall;
  TDefragShowDebugCallback = function(Level: Integer; Item: PItemStruct; Msg: PChar): Integer; stdcall;
  TDefragDrawClusterCallback= function(Data: PDefragDataStruct; ClusterStart, ClusterEnd: ULONG64; Color: Integer): Integer; stdcall;
  TDefragClearScreenCallback= function(Msg: PChar): Integer; stdcall;

  function RunDefrag(Path: PWChar; Mode, Speed: Integer; FreeSpace: Double;Excludes: PPWChar): Integer; stdcall;
  function StopDefrag(WaitForIt: Integer): Integer; stdcall;
  function DefragInitialize(ShowStatusCallback: Pointer;
                            ShowMoveFunction: Pointer;
                            ShowAnalyzeCallback: Pointer;
                            ShowDebugFunction: Pointer;
                            DrawClusterFunction: Pointer;
                            ClearScreenFunction: Pointer;
                            DebugMessagesArray: array of PChar): Integer; stdcall;
implementation
  function RunDefrag; external 'JkDefrag.dll' name 'RunDefrag';
  function StopDefrag; external 'JkDefrag.dll' name 'StopDefrag';
  function DefragInitialize; external 'JkDefrag.dll' name 'DefragInitialize';
end.


////////////////////////////////////////////////////////////////////////////

unit DataUnit;

interface
uses Windows, Uint64Lib;

const
  NO  = 0;
  YES = 1;
  //MAXULONG64 = 18446744073709551614;
  RUNNING    = 0;
  STOPPING   = 1;
  STOPPED    = 2;


type
  PPWChar= ^PWChar;
  PPChar= ^PChar;
  ULONG64= UINT64;

// List in memory of the fragments of a file. */
  PFragmentListStruct=^TFragmentListStruct;
  TFragmentListStruct=record
    Lcn: ULONG64;             //* Logical cluster number, location on disk. */
    NextVcn: ULONG64;          //* Virtual cluster number of next fragment. */
    Next:PFragmentListStruct;
  end;
  FragmentListStruct=TFragmentListStruct;


 //* List in memory of all the files on disk, sorted by LCN (Logical  Cluster Number).
 PItemStruct=^ TItemStruct;
 TItemStruct= record
   Parent: PItemStruct;                             //* Parent item. */
   Smaller: PItemStruct;                      //* Next smaller item. */
   Bigger: PItemStruct;                        //* Next bigger item. */
   Path: PWChar;                              //* Full path on disk. */
   Bytes: ULONG64;                        //* Total number of bytes. */
   Clusters: ULONG64;                  //* Total number of clusters. */
   Fragments: PFragmentListStruct;            //* List of fragments. */
   Directory: Char;                       //* YES: it's a directory. */
   Unmovalbe: Char;           //* YES: file can't/couldn't be moved. */
   Exclude: Char;    //* YES: file is not to be defragged/optimized. */
 end;
 ItemStruct= TItemStruct;


  //* List of clusters used by the MFT. */
  PExcludesStruct=^TExcludesStruct;
  TExcludesStruct=record
    Start: ULONG64;
    iEnd: ULONG64;
  end;
  ExcludesStruct= TExcludesStruct;

PDefragDataStruct=^TDefragDataStruct;
TDefragDataStruct=record
   Step: Integer;
   
   Path:  PWChar;
   MountPoint: PWChar;
   VolumeName:array[0..50] of WChar;
   VolumeHandle: THandle;
   IsNtfs: BOOL;
   
   FreeSpace: Double;
   
   ItemTree: PItemStruct;
   BalanceCount: Integer;
   Excludes: PPWChar;
   
   MftExcludes: array[0..2] of ExcludesStruct;
   
   TotalClusters: ULONG64;
   BytesPerCluster: ULONG64;
   
   CountFreeClusters: ULONG64;
   CountGaps: ULONG64;
   BiggestGap: ULONG64;
   CountGapsLess16: ULONG64;
   CountClustersLess16: ULONG64;
   
   FreeSpaceTop: ULONG64;
   CountDirectories: ULONG64;
   CountAllFiles: ULONG64;
   CountFragmentedItems: ULONG64;
   CountAllBytes: ULONG64;
   CountFragmentedBytes: ULONG64;
   CountAllClusters: ULONG64;
   CountFragmentedClusters: ULONG64;
   BiggestFile: PItemStruct;
   BiggestDirectory: PItemStruct;
   
   StepToDo: ULONG64;
   StepDone: ULONG64;
   
   Speed: Integer;
   StartTime: Int64;
   RunningTime: Int64;
   LastCheckpoint: Int64;
end;
DefragDataStruct=TDefragDataStruct;
var
  MAXULONG64: UINT64 =0;
  _Running: Integer = STOPPED;         // If not RUNNING then stop defragging. */
  RedrawScreen: Integer = NO;            // If YES the redraw complete screen. */
  DebugMsg : Array[0..48] of PChar = (
     'Looking for perfect-fit %I64d[%I64d]',
     'Looking for best-fit %I64d[%I64d]',
     'Returning perfect fit: %I64d[%I64d]',
     'No files fit the gap.',
     'Returning best fit: %I64d[%I64d]',
     'Partial fit: %I64d[%I64d]',
     'Out of depth.',
     'Out of time.',
     'Returning perfect fit: %I64d[%I64d]',
     'Trying files smaller than %I64d',
     'Analyzing: %s',
     'Extent: Lcn=%I64u, Vcn=%I64u, NextVcn=%I64u',
     'ERROR: could not get volume bitmap: %s',
     'Gap found: LCN=%I64d, Size=%I64d',
     'Could not open: %s',
     'Could not open %s: %s',
     '%I64d clusters at %I64d, %I64d bytes',
     'Special file attribute: Compressed',
     'Special file attribute: Encrypted',
     'Special file attribute: Offline',
     'Special file attribute: Read-only',
     'Special file attribute: Sparse-file',
     'Special file attribute: Temporary',
     'File is bigger than largest free block, cannot defragment.',
     'FreeSpaceTop=%I64d',
     'Cannot move file away because no gap is big enough: %I64d[%I64d]',
     'Don t know which file is at the end of the gap: %I64d[%I64d]',
     'Enlarging gap %I64d[%I64d] by moving %I64d[%I64d]',
     'Skipping gap, cannot fill: %I64d[%I64d]',
     'Opening volume %s at mountpoint %s',
     'Error while opening volume %s at mountpoint %s: %s',
     'Volume %s at mountpoint %s is not mounted.',
     'Cannot defragment volume %s at mountpoint %s',
     'MftStartLcn=%I64d, MftZoneStart=%I64d, MftZoneEnd=%I64d, Mft2StartLcn=%I64d, MftValidDataLength=%I64d',
     'Excludes[%u].Start=%I64d, Excludes[%u].End=%I64d',
     'Ignoring removable disk: %s',
     'Ignoring read-only disk: %s',
     'No directories after the gap',
     'No directories fit the gap',
     'Could not get list of volumes: %s',
     'Cannot find volume name for mountpoint: %s',
     'Disksize = %I64d clusters (%I64d bytes), BytesPerCluster = %I64d bytes',
     'Windows could not move the file, trying alternative method.',
     'Cannot process clustermap of %s: %s',
     'Disk is full, cannot defragment.',
     'Alternative method failed, leaving file where it is.',
     'Cannot get process snapshot: %s',
     'Cannot find my own name in the process list: %s',
     'I am already running: %s'
  );  
implementation

initialization
  MAXULONG64 := StrToUInt64('18446744073709551615');
end.

/////////////////////////////////////////////////////////////
But it will show
---------------------------
Debugger Exception Notification
---------------------------
Project DDM.exe raised exception class EAccessViolation with message 'Access violation at address 0044ED87 in module xc.exe'. Write of address 00000000'. Process stopped. Use Step or Run to continue.
---------------------------
OK   Help  
---------------------------

Error, this exception is show after runing 20 seconds. I am debuging it, the it will crash in some folder.

Please help me, thank you!
Logged
jeroen
Administrator
JkDefrag Hero
*****
Posts: 7182



View Profile WWW
« Reply #1 on: April 29, 2007, 10:35:42 pm »

I think you have to update the strings in your DebugMsg array, they seem to be from an old version. If the defragger tries to use string 46 for example, then the string in your list contains 1 string as a parameter, but the library supplies 2 Int64 numbers. This could very well be the reason why it crashes after 20 seconds.
Logged
snowvalley
JkDefrag Junior
**
Posts: 7


View Profile
« Reply #2 on: May 02, 2007, 08:23:55 am »

DebugMsg : Array[0..46] of PChar = (
  {  0 }   'Looking for perfect-fit %I64d[%I64d]',
  {  1 }   'Looking for best-fit %I64d[%I64d]',
  {  2 }   'Returning perfect fit: %I64d[%I64d]',
  {  3 }   'No files fit the gap.',
  {  4 }   'Returning best fit: %I64d[%I64d]',
  {  5 }   'Partial fit: %I64d[%I64d]',
  {  6 }   'Out of depth.',
  {  7 }   'Out of time.',
  {  8 }   'Returning perfect fit: %I64d[%I64d]',
  {  9 }   'Trying files smaller than %I64d',
  { 10 }   'Getting cluster bitmap: %S',
  { 11 }   'Extent: Lcn=%I64u, Vcn=%I64u, NextVcn=%I64u',
  { 12 }   'ERROR: could not get volume bitmap: %s',
  { 13 }   'Gap found: LCN=%I64d, Size=%I64d',
  { 14 }   'Starting defragmenter for %S',
  { 15 }   'Could not open %S: %s',
  { 16 }   '%I64d clusters at %I64d, %I64d bytes',
  { 17 }   'Special file attribute: Compressed',
  { 18 }   'Special file attribute: Encrypted',
  { 19 }   'Special file attribute: Offline',
  { 20 }   'Special file attribute: Read-only',
  { 21 }   'Special file attribute: Sparse-file',
  { 22 }   'Special file attribute: Temporary',
  { 23 }   'Analyzing: %S',
  { 24 }   'FreeSpaceTop=%I64d',
  { 25 }   'Cannot move file away because no gap is big enough: %I64d[%I64d]',
  { 26 }   'Don not know which file is at the end of the gap: %I64d[%I64d]',
  { 27 }   'Enlarging gap %I64d[%I64d] by moving %I64d[%I64d]',
  { 28 }   'Skipping gap, cannot fill: %I64d[%I64d]',
  { 29 }   'Opening volume %S at mountpoint %S',
  { 30 }   'Error while opening volume %S at mountpoint %S: %s',
  { 31 }   'Volume %S at mountpoint %S is not mounted.',
  { 32 }   'Cannot defragment volume %S at mountpoint %S',
  { 33 }   'MftStartLcn=%I64d, MftZoneStart=%I64d, MftZoneEnd=%I64d, Mft2StartLcn=%I64d, MftValidDataLength=%I64d',
  { 34 }   'MftExcludes[%u].Start=%I64d, MftExcludes[%u].End=%I64d',
  { 35 }   'Ignoring disk %S because it is a removable disk.',
  { 36 }   'Ignoring disk %S because it is read-only.',
  { 37 }   'Analyzing disk %S',
  { 38 }   'Finished.',
  { 39 }   'Could not get list of volumes: %s',
  { 40 }   'Cannot find volume name for mountpoint: %S',
  { 41 }   'Cannot enlarge gap at %I64d[%I64d] because of unmovable data.',
  { 42 }   'Windows could not move the file, trying alternative method.',
  { 43 }   'Cannot process clustermap of %S: %s',
  { 44 }   'Disk is full, cannot defragment.',
  { 45 }   'Alternative method failed, leaving file where it is.',
  { 46 }   'Extent (virtual): Vcn=%I64u, NextVcn=%I64u'
  );  
//--------------------------------------------------------------
Thanks for you replied.

The error is still exists.

It seemed show this error message at  Analyze finished every time.

Can you help me?
Logged
jeroen
Administrator
JkDefrag Hero
*****
Posts: 7182



View Profile WWW
« Reply #3 on: May 02, 2007, 10:39:29 am »

Quote from: "snowvalley"
 { 46 }   'Extent (virtual): Vcn=%I64u, NextVcn=%I64u'

There should be 47 messages.
The problem is probably in the code that you have build. Try adding a line that writes a message to the logfile at the begin and end of every callback function. That way you can see which of your subroutines is crashing.
Logged
snowvalley
JkDefrag Junior
**
Posts: 7


View Profile
« Reply #4 on: May 02, 2007, 03:17:18 pm »

Quote from: "jeroen"
Quote from: "snowvalley"
 { 46 }   'Extent (virtual): Vcn=%I64u, NextVcn=%I64u'

There should be 47 messages.
The problem is probably in the code that you have build. Try adding a line that writes a message to the logfile at the begin and end of every callback function. That way you can see which of your subroutines is crashing.

Thanks for you replied.

Yes, that's 47 messages, because the bounds  is 0 to 46.
Logged
sonykalkan
JkDefrag Senior
****
Posts: 21


View Profile
« Reply #5 on: May 28, 2007, 03:39:26 pm »

Below is the full delphi code of sample defrag usage. But still, when rundefrag is executed in unit1.pas, access violation occurs. I use
JkDefrag v3.8  for the dll and i have modified debugmsg according the newest dll.

What can be the problem ?

Best regards,
Sony Kalkan

Unit1.pas
Code:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,DefragAPI,
  DataUnit,
  UInt64Lib;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;



function TDefragShowStatusCallback(Data: PDefragDataStruct): Integer; stdcall;
function TDefragShowMoveCallback(Item: PItemStruct; Clusters, FromLcn, ToLcn: ULONG64 ): Integer; stdcall;
function TDefragShowAnalyzeCallback(Data: PDefragDataStruct; Item:PItemStruct): Integer; stdcall;
function TDefragShowDebugCallback(Level: Integer; Item: PItemStruct; Msg: PChar): Integer; stdcall;
function TDefragDrawClusterCallback(Data: PDefragDataStruct; ClusterStart, ClusterEnd: ULONG64; Color: Integer): Integer; stdcall;
function TDefragClearScreenCallback(Msg: PChar): Integer; stdcall;

implementation

{$R *.DFM}
function TDefragShowStatusCallback(Data: PDefragDataStruct): Integer; stdcall;
begin
//
end;
function TDefragShowMoveCallback(Item: PItemStruct; Clusters, FromLcn, ToLcn: ULONG64 ): Integer; stdcall;
begin
//
end;

function TDefragShowAnalyzeCallback(Data: PDefragDataStruct; Item:PItemStruct): Integer; stdcall;
begin
//
end;

function TDefragShowDebugCallback(Level: Integer; Item: PItemStruct; Msg: PChar): Integer; stdcall;
begin
//
end;

function TDefragDrawClusterCallback(Data: PDefragDataStruct; ClusterStart, ClusterEnd: ULONG64; Color: Integer): Integer; stdcall;
begin
//
end;

function TDefragClearScreenCallback(Msg: PChar): Integer; stdcall;
begin
//
end;

procedure TForm1.Button1Click(Sender: TObject);

var
vol : PChar;
res : Integer;
mode : LongInt;

begin

GetMem(vol,4 );
vol := 'd:\;

DefragInitialize(@TDefragShowStatusCallback, @TDefragShowMoveCallback,
     @TDefragShowAnalyzeCallback, @TDefragShowDebugCallback,
     @TDefragDrawClusterCallback, @TDefragClearScreenCallback,
     DebugMsg);

res := RunDefrag( pwidechar(vol) ,0,0);

Freemem(vol);
end;

end.


DataUnit.pas

Code:

unit DataUnit;

interface
uses Windows, Uint64Lib;

const
NO = 0;
YES = 1;
//MAXULONG64 = 18446744073709551614;
RUNNING = 0;
STOPPING = 1;
STOPPED = 2;


type
PPWChar= ^PWChar;
PPChar= ^PChar;
ULONG64= UINT64;

// List in memory of the fragments of a file. */
PFragmentListStruct=^TFragmentListStruct;
TFragmentListStruct=record
Lcn: ULONG64; //* Logical cluster number, location on disk. */
NextVcn: ULONG64; //* Virtual cluster number of next fragment. */
Next:PFragmentListStruct;
end;
FragmentListStruct=TFragmentListStruct;


//* List in memory of all the files on disk, sorted by LCN (Logical Cluster Number).
PItemStruct=^ TItemStruct;
TItemStruct= record
Parent: PItemStruct; //* Parent item. */
Smaller: PItemStruct; //* Next smaller item. */
Bigger: PItemStruct; //* Next bigger item. */
Path: PWChar; //* Full path on disk. */
Bytes: ULONG64; //* Total number of bytes. */
Clusters: ULONG64; //* Total number of clusters. */
Fragments: PFragmentListStruct; //* List of fragments. */
Directory: Char; //* YES: it's a directory. */
Unmovalbe: Char; //* YES: file can't/couldn't be moved. */
Exclude: Char; //* YES: file is not to be defragged/optimized. */
end;
ItemStruct= TItemStruct;


//* List of clusters used by the MFT. */
PExcludesStruct=^TExcludesStruct;
TExcludesStruct=record
Start: ULONG64;
iEnd: ULONG64;
end;
ExcludesStruct= TExcludesStruct;

PDefragDataStruct=^TDefragDataStruct;
TDefragDataStruct=record
Step: Integer;

Path: PWChar;
MountPoint: PWChar;
VolumeName:array[0..50] of WChar;
VolumeHandle: THandle;
IsNtfs: BOOL;

FreeSpace: Double;

ItemTree: PItemStruct;
BalanceCount: Integer;
Excludes: PPWChar;

MftExcludes: array[0..2] of ExcludesStruct;

TotalClusters: ULONG64;
BytesPerCluster: ULONG64;

CountFreeClusters: ULONG64;
CountGaps: ULONG64;
BiggestGap: ULONG64;
CountGapsLess16: ULONG64;
CountClustersLess16: ULONG64;

FreeSpaceTop: ULONG64;
CountDirectories: ULONG64;
CountAllFiles: ULONG64;
CountFragmentedItems: ULONG64;
CountAllBytes: ULONG64;
CountFragmentedBytes: ULONG64;
CountAllClusters: ULONG64;
CountFragmentedClusters: ULONG64;
BiggestFile: PItemStruct;
BiggestDirectory: PItemStruct;

StepToDo: ULONG64;
StepDone: ULONG64;

Speed: Integer;
StartTime: Int64;
RunningTime: Int64;
LastCheckpoint: Int64;
end;
DefragDataStruct=TDefragDataStruct;
var
MAXULONG64: UINT64 =0;
_Running: Integer = STOPPED; // If not RUNNING then stop defragging. */
RedrawScreen: Integer = NO; // If YES the redraw complete screen. */
DebugMsg : Array[0..47] of PChar = (
'Looking for perfect-fit %I64d[%I64d]',
'Looking for best-fit %I64d[%I64d]',
'Returning perfect fit: %I64d[%I64d]',
'No files fit the gap.',
'Returning best fit: %I64d[%I64d]',
'Partial fit: %I64d[%I64d]',
'Out of depth.',
'Out of time.',
'Returning perfect fit: %I64d[%I64d]',
'Trying files smaller than %I64d',
'Getting cluster bitmap: %s',
'Extent: Lcn=%I64u, Vcn=%I64u, NextVcn=%I64u',
'ERROR: could not get volume bitmap: %s',
'Gap found: LCN=%I64d, Size=%I64d',
'Starting defragmenter for %s',
'Could not open %s: %s',
'%I64d clusters at %I64d, %I64d bytes',
'Special file attribute: Compressed',
'Special file attribute: Encrypted',
'Special file attribute: Offline',
'Special file attribute: Read-only',
'Special file attribute: Sparse-file',
'Special file attribute: Temporary',
'Analyzing: %s',
'FreeSpaceTop=%I64d',
'Cannot move file away because no gap is big enough: %I64d[%I64d]',
'Don`t know which file is at the end of the gap: %I64d[%I64d]',
'Enlarging gap %I64d[%I64d] by moving %I64d[%I64d]',
'Skipping gap, cannot fill: %I64d[%I64d]',
'Opening volume %s at mountpoint %s',
'Error while opening volume %s at mountpoint %s: %s',
'Volume %s at mountpoint %s is not mounted.',
'Cannot defragment volume %s at mountpoint %s',
'MftStartLcn=%I64d, MftZoneStart=%I64d, MftZoneEnd=%I64d, Mft2StartLcn=%I64d, MftValidDataLength=%I64d',
'MftExcludes[%u].Start=%I64d, MftExcludes[%u].End=%I64d',
'Ignoring disk %s because it is a removable disk.',
'Ignoring disk %s because it is read-only.',
'Analyzing disk %s',
'Finished.',
'Could not get list of volumes: %s',
'Cannot find volume name for mountpoint: %s',
'Cannot enlarge gap at %I64d[%I64d] because of unmovable data.',
'Windows could not move the file, trying alternative method.',
'Cannot process clustermap of %s: %s',
'Disk is full, cannot defragment.',
'Alternative method failed, leaving file where it is.',
'Extent (virtual): Vcn=%I64u, NextVcn=%I64u',
'Ignoring because of exclude mask \"%s\": %s'

);
implementation

initialization
MAXULONG64 := StrToUInt64('18446744073709551615');
end.


DefragApi.pas

Code:

unit DefragApi;

interface
uses Windows, DataUnit;


type


TDefragShowStatusCallback=function(Data: PDefragDataStruct): Integer; stdcall;
TDefragShowMoveCallback = function(Item: PItemStruct; Clusters, FromLcn, ToLcn: ULONG64 ): Integer; stdcall;
TDefragShowAnalyzeCallback = function(Data: PDefragDataStruct; Item:PItemStruct): Integer; stdcall;
TDefragShowDebugCallback = function(Level: Integer; Item: PItemStruct; Msg: PChar): Integer; stdcall;
TDefragDrawClusterCallback= function(Data: PDefragDataStruct; ClusterStart, ClusterEnd: ULONG64; Color: Integer): Integer; stdcall;
TDefragClearScreenCallback= function(Msg: PChar): Integer; stdcall;


function RunDefrag(Path: PWChar; Mode, Speed: Integer): Integer; stdcall;
function StopDefrag(WaitForIt: Integer): Integer; stdcall;
function DefragInitialize(ShowStatusCallback: Pointer;
ShowMoveFunction: Pointer;
ShowAnalyzeCallback: Pointer;
ShowDebugFunction: Pointer;
DrawClusterFunction: Pointer;
ClearScreenFunction: Pointer;
DebugMessagesArray: array of PChar): Integer; stdcall;
implementation



function RunDefrag; external 'JkDefrag.dll' name 'RunDefrag';
function StopDefrag; external 'JkDefrag.dll' name 'StopDefrag';
function DefragInitialize; external 'JkDefrag.dll' name 'DefragInitialize';

end.

Logged
jeroen
Administrator
JkDefrag Hero
*****
Posts: 7182



View Profile WWW
« Reply #6 on: May 28, 2007, 09:30:35 pm »

Take another look at the array of strings. I see that you have changed all the uppercase %S parameters into lowercase %s. In C++ uppercase is used for wchar, and lowercase for char.

p.s. I haven't read all of your code, there is too much and I don't know Delphi.
Logged
sonykalkan
JkDefrag Senior
****
Posts: 21


View Profile
« Reply #7 on: June 02, 2007, 06:40:48 am »

Thank you for your information. I have modified the source accordingly. But now, when i run it a dialog box with microsoft visual c++ debug library appears.

It says:
Debug assertion failed!
Program:Project1.exe File:f:\rtm\vctools\crt_bld\self_x86\crt\src\vswprint.c Line:270
Expression: string != NULL && sizeInWords >0

Press retry to debug the application.

------------
What is weird is that I have no f:\ drive on my machine. Do you have a clue that what happens here ?

Regards,
Sony Kalkan
Logged
sonykalkan
JkDefrag Senior
****
Posts: 21


View Profile
« Reply #8 on: June 02, 2007, 07:24:47 am »

May be this can be clue for us:
When i compile and run standalone windows application jkdefrag (not the dll)
in visual c++ 2005

First the frame appears containing all green and black lines representing disk sectors and suddenly
The following error appears:

DEBUG ASSERTION FAILED!

File: dbgheap.c
Line: 1252
Expression: _CrtIsValidHeapPointer(pUserData)
Logged
jeroen
Administrator
JkDefrag Hero
*****
Posts: 7182



View Profile WWW
« Reply #9 on: June 02, 2007, 01:24:55 pm »

I am about to release JkDefrag version v3.9, it has many changes in the library. It is now possible to run the library without supplying any callback functions and without an array of strings, it will then use built-in defaults. It should make it easier to debug the callback functions and the array. Another change is how the array of strings is used, the library no longer depends on correct strings. Other changes are that the sources are now in standard .cpp and .h files, which can simply be added to a project, and that there is a sample Visual project.
Logged
sonykalkan
JkDefrag Senior
****
Posts: 21


View Profile
« Reply #10 on: June 10, 2007, 05:36:35 pm »

first thank you for the newest version. It is very great.
I am not in expert in Delphi so can somebody convert header files to delphi so we can use the new dll functions in Delphi.

Regards,
Sony
Logged
jeroen
Administrator
JkDefrag Hero
*****
Posts: 7182



View Profile WWW
« Reply #11 on: June 10, 2007, 08:27:14 pm »

I don't use Delphi myself so I cannot help you there. Take a look at this converter that I just found on the internet:HeadConv. It takes the "jkdefrag.h" file and generates a "jkdefrag.pas" file. It looks to me like the converter makes some mistakes translating the definitions of the callback subroutines, but like I said I don't use Delphi myself. Still, the converter might be useful.
Logged
sonykalkan
JkDefrag Senior
****
Posts: 21


View Profile
« Reply #12 on: June 10, 2007, 10:13:37 pm »

Thank you for your help. Finally i have managed to prepare header files. But when i try to run the main project with the line similar:


RunJkDefrag(vol,0,0, 100,excludes,spacehogs,nil,nil,@TDefragShowStatusCallback, @TDefragShowMoveCallback,
     @TDefragShowAnalyzeCallback, @TDefragShowDebugCallback,
     @TDefragDrawClusterCallback, @TDefragClearScreenCallback,
     DebugMessages);


the following error appears:
Exception Processing Message c0000139 parameters 1885c8 ....


When i remove the line RunJkDefrag(...
there is no error.

May be somebody has similar error.


Regards,
Logged
jeroen
Administrator
JkDefrag Hero
*****
Posts: 7182



View Profile WWW
« Reply #13 on: June 11, 2007, 12:24:12 am »

- I see that your FreeSpace parameter is 100. That leaves no room for files...
- Your example does not show the declaration and contents of Excludes, SpaceHogs, and DebugMsg.
- Your example does not show the declaration of RunJkDefrag.
- Set all the callback functions to "nil" and try again.

Try this:
Code:
program JkDefrag;

procedure RunJkDefrag(
  Path: PWideChar;
  Mode: Integer;
  Speed: Integer;
  FreeSpace: Double;
  Excludes: array of PWideChar;
  SpaceHogs: array of PWideChar;
  Running: PInteger;
  RedrawScreen: PInteger;
  ShowStatus, ShowMove, ShowAnalyze, ShowDebug, DrawCluster, ClearScreen: Pointer;
  DebugMsg: array of PWideChar);
  CDECL; external 'JkDefrag' name 'RunJkDefrag';
procedure StopJkDefrag(Running: Pointer; TimeOut: Integer);
  CDECL; external 'JkDefrag' name 'StopJkDefrag';


var
Excludes : Array of PWideChar = nil;
SpaceHogs : Array of PWideChar = nil;
DebugMsg : Array of PWideChar = nil;
Running: Integer;
RedrawScreen: Integer;

begin
  writeln('Starting JkDefrag');
  RunJkDefrag(nil,0,100,1,Excludes,SpaceHogs,@Running,@RedrawScreen,
    nil,nil,nil,nil,nil,nil,DebugMsg);
  writeln('Finished.');
end.
Logged
sonykalkan
JkDefrag Senior
****
Posts: 21


View Profile
« Reply #14 on: June 11, 2007, 07:35:07 am »

Thank you again for your quick help. I have solved the problem thanks to your clue.
The problem was that

CDECL; external 'JkDefrag' name 'RunJkDefrag';

must be stated in the interface section but not implementation section of Delphi code.


Now, when running the code, another exception occurs when debug is on the line:
RunJkDefrag(vol,0,100, 1,excludes,spacehogs,@running,@redrawscreen,nil,nil,nil,nil,nil,nil,     DebugMessages);

I have tried both spacehogs:=nil  and the spacehogs[0]:='DisableDefaults';
But there is an exception there.
I think i have missed somethig.
Thank you in advance.



Code:

var
spacehogs:array[0..1] of pwidechar;
Excludes:array of pwidechar;
DebugMessages:array of pwidechar;
running,redrawscreen:integer;

procedure TForm1.Button1Click(Sender: TObject);
var
vol : PwideChar;
res : Integer;
mode : LongInt;
begin

GetMem(vol,20 );
vol := 'd:\share';
GetMem(spacehogs[0],20 );
spacehogs[0]:='DisableDefaults';
//spacehogs:=nil;
excludes:=nil;
DebugMessages:=nil;

RunJkDefrag(vol,0,0, 10,excludes,spacehogs,@running,@redrawscreen,nil,nil,nil,nil,nil,nil,     DebugMessages);

Freemem(vol);
Freemem(spacehogs[0]);
end;

The error is
Access Violation at address 1004700C in module 'JkDefrag.dll'. Write of address 00000001
Logged
Pages: [1] 2 3 4
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.5 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!