Bonjour,

j'ai un programme que je migre vers Lazarus et qui charge dynamiquement une DLL. Le code dephi est celui-ci :

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 LoadExtension(NameOfExt : String) : TProcExt ;
var HandleProc : Integer ;
    proc : TProcExt ;
begin
    HandleProc := LoadLibrary(PChar(NameOfExt + '.dll'));
 
    if HandleProc <> 0
    then
        @proc := GetProcAddress(HandleProc, 'Execute')
    else
        @proc := nil ;
 
    ListOfExtension.Add(NameOfExt, HandleProc, proc) ;
 
    Result := proc ;
end ;
Je l'ai convertie en ceci :
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
21
22
23
24
25
function LoadExtension(NameOfExt : String) : TProcExt ;
var HandleProc : Integer ;
    proc : TProcExt ;
    tmp : String ;
    tmpPchar  : PChar ;
begin
    tmp := NameOfExt + '.dll' ;
 
    { + 1 pour le \0 }
    SetLength(tmpPChar, Length(tmp) + 1) ;
 
    StrPCopy(tmpPChar, tmp) ;
 
    HandleProc := LoadLibrary(tmpPChar);
 
    if HandleProc <> 0
    then
        @proc := GetProcAddress(HandleProc, 'Execute')
    else
        @proc := nil ;
 
    ListOfExtension.Add(NameOfExt, HandleProc, proc) ;
 
    Result := proc ;
end ;
Sauf que ça fonctionne pas SetLength(tmpPChar, Length(tmp) + 1) ; il me dit que PChar est un objet constant.

Mais FPC me dit sur les deux lignes où il y a @proc : xxxx.pas(183,9) Error: Can't assign values to an address

J'ai chercher sur internet et j'ai trouvé ce code qui ne fonctionne pas :
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
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Validate registration data
function CFLicTest(pstrRegSerial, pstrRegKey: String): Boolean;
 
The function that calls confirm_registered looks like this:
{*---------------------------
* Validate registration data
* pstrRegSerial - Serial, user / organization name prefixed by an identifier for the edition folowed by a - e.g. S-OrgName Inc
* pstrKey - Registration key the user got after registering the product
*---------------------------}
function CFLicTest(pstrRegSerial, pstrRegKey: String): Boolean;
var
confirm_registered: Tconfirm_registered;
ptrFunction: TFarProc;
handleDLL: THandle;
intLicValidate: Integer;
 
begin
try
//
// supApp.AppExe = application path
// supApp.AppID = name of the application
//
handleDLL := LoadLibrary(PChar(supApp.AppExe + 'reg' + supApp.AppID + '.DLL'));
ptrFunction := GetProcAddress(handleDLL, 'confirm_registered');
if ptrFunction <> nil
then begin
@confirm_registered := ptrFunction;
intLicValidate := confirm_registered(pstrRegSerial, pstrRegKey);
end
else begin
intLicValidate := 0;
end;
except
intLicValidate := 0;
end;
ptrFunction := nil;
FreeLibrary(handleDLL);
Result := Iff(intLicValidate = 0, false, true);
end;
Quelqu'un a-t-il déjà eu le problème ? Je ne trouve rien sur internet.