j'utilise une dll ecrite en C++,
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
type
charp=^char;
var
Form1: TForm;
const
NomDLL = 'DefragDll.dll';
1° - declaration static:
--------------------
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Function RunDefrag(MountPoint:pchar;Mode:integer):integer;cdecl; external 'DefragDll.dll' name 'RunDefrag';
-----------------------
implementation
{$R *.dfm}
 
function LierFonction(DLL: String; var HandleDLL: THandle; NomFct: String; IndexFct: Integer = -1): Pointer;
begin
Result := nil;
HandleDLL := 0;
HandleDLL := LoadLibrary(pAnsiChar(DLL));
If HandleDLL = 0 then
Exit;
If IndexFct < 0 then
Result := GetProcAddress(HandleDLL, pAnsiChar(NomFct))
else
Result := GetProcAddress(HandleDLL, pAnsiChar(IndexFct));
end;
2° -declaration denamique.
-------------------------------------------°°°°°°°°°°°°°°°°°°---
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
procedure TForm1.Button1Click(Sender: TObject);
var HandleDLL: THandle;
RunDefrag : function(MountPoint:charp;Mode:integer):integer;cdecl ; //Notre fonction, sous forme de variable.
begin
RunDefrag := LierFonction(NomDLL, HandleDLL, 'RunDefrag');
If assigned(RunDefrag) then
begin
RunDefrag(nil,1);
FreeLibrary(HandleDLL);
end
else
ShowMessage('Erreur de chargement de la fonction "rundefrag"');
end;
//----------------------
 
//Static procedure ..... 
procedure TForm1.Button2Click(Sender: TObject);
begin
RunDefrag(nil,1);
end;
mais toujours rien erreur de compilation ;




le code c++ de DLL.
------------------------
Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <stdio.h>
#include <time.h>
#include <sys/timeb.h>
 
 
 
 
#include "Common1.c" /* Includes and variables. */
 
 
 
 
/* Dll specifics. */
#define DEFRAG_EXPORTS
#include "DefragDll.h"
static PDefragShowMessageCallback ShowMessageCallback;
static PDefragShowMoveCallback ShowMoveCallback;
static PDefragShowAnalyzeCallback ShowAnalyzeCallback;
static PDefragShowDebugCallback ShowDebugCallback;
static PDefragDrawClusterCallback DrawClusterCallback;
static PDefragClearScreenCallback ClearScreenCallback;
static char **DebugMsg;
 
 
 
/* Show a general progress message. */
void ShowMessage(int Message) {
ShowMessageCallback(Message);
}
 
 
 
 
/* Show progress message during defrag/optimization, about moving a file. */
void ShowMove(char *FileName, DWORD Clusters, ULONG64 FromLcn, ULONG64 ToLcn) {
ShowMoveCallback(FileName,Clusters,FromLcn,ToLcn);
}
 
 
 
 
/* Show progress message during analyzing. */
void ShowAnalyze(
struct FileListStruct *File,
ULONG64 CountDirectories,
ULONG64 CountAllFiles, ULONG64 CountFragmentedFiles,
ULONG64 CountAllBytes, ULONG64 CountFragmentedBytes,
ULONG64 CountAllClusters, ULONG64 CountFragmentedClusters) {
if (File != NULL) {
ShowAnalyzeCallback(File->FileName,
CountDirectories,
CountAllFiles,CountFragmentedFiles,
CountAllBytes,CountFragmentedBytes,
CountAllClusters,CountFragmentedClusters);
} else {
ShowAnalyzeCallback(NULL,
CountDirectories,
CountAllFiles,CountFragmentedFiles,
CountAllBytes,CountFragmentedBytes,
CountAllClusters,CountFragmentedClusters);
}
}
 
 
 
 
/* Show a debug message. */
void ShowDebug(int Level, struct FileListStruct *File, char *Message) {
if (File != NULL) {
ShowDebugCallback(Level,File->FileName,Message);
} else {
ShowDebugCallback(Level,NULL,Message);
}
}
 
 
 
 
/* Paint a cluster on the screen in the color. */
void DrawCluster(ULONG64 ClusterStart, ULONG64 ClusterEnd, int Color) {
DrawClusterCallback(ClusterStart,ClusterEnd,MaxLcn,Color);
}
 
 
 
 
/* Clear the screen and show the name of the volume. */
void ClearScreen(char *VolumeDescription) {
ClearScreenCallback(VolumeDescription);
}
 
 
 
 
 
/* Include the subroutines that are common (equal) in all versions. */
#include "Common2.c"
 
 
 
 
 
/* Run the defragger. Execution can be stopped by calling StopDefrag().
If a MountPoint is specified (for example "C:\") then only defrag
that disk, otherwise defrag all fixed disks.
Mode:
0 Analyze only
1 Analyze, Defragment
2 Analyze, Defragment, Fast Optimize
3 Analyze, Defragment, Full Optimize
*/
DEFRAG_API int RunDefrag(char *MountPoint, int Mode) {
if ((MountPoint == NULL) || (*MountPoint == '\0')) {
DefragAllDisks(Mode);
} else {
DefragOneDisk(MountPoint,Mode);
}
return(0);
}
 
 
/* Stop RunDefrag(). */
DEFRAG_API int StopDefrag(int WaitForIt) {
StopProcessing(WaitForIt);
return(0);
}
 
/* Stop the defragger. This function can be called from another thread to
stop the defragger or the analyzer. */
DEFRAG_API int DefragInitialize(
PDefragShowMessageCallback ShowMessageFunction,
PDefragShowMoveCallback ShowMoveFunction,
PDefragShowAnalyzeCallback ShowAnalyzeFunction,
PDefragShowDebugCallback ShowDebugFunction,
PDefragDrawClusterCallback DrawClusterFunction,
PDefragClearScreenCallback ClearScreenFunction,
char **DebugMessagesArray) {
ShowMessageCallback = ShowMessageFunction;
ShowMoveCallback = ShowMoveFunction;
ShowAnalyzeCallback = ShowAnalyzeFunction;
ShowDebugCallback = ShowDebugFunction;
DrawClusterCallback = DrawClusterFunction;
ClearScreenCallback = ClearScreenFunction;
DebugMsg = DebugMessagesArray;
return(0);
}
-------------------------------



et en fin comment declarer function "DefragInitialize".
merci inf

)