Incompatible types: Pwidechar and Tcaption

Asked

Viewed 802 times

1

need to resolve this and can not, I have a variable that loads a DLL with LOADLIBRARY, when I put the path that is the DLL (that is inside an Edit) it gives the error above the topic.

ERROR: Incompatible types: Pwidechar and Tcaption

I’m using it this way:

libw := LoadLibrary(Edit5.Text + 'teste.dll');

Where Edit5.Text (is the path where the DLL is). Any ideas ?

Grateful!

  • try with libw := LoadLibrary(StringToWideChar(Edit5.Text + 'teste.dll'));

  • @Marcosregis, gave this error: E2035 Not enough current Parameters

  • libw is a variable of what type ?

  • @Juniors of the type "cardinal".

  • @user7605, is there any reason why libw is Cardial ? Take advantage and test this: libw := Loadlibrary(Stringtoolestr(Edit1.Text + 'Project1.dll'));

  • @Júniormoreira, perfect worked out rs. About the CARDIAL was searching on the internet anyway, nothing in particular pq ? Put it as an answer so I can score you.

Show 1 more comment

4 answers

2

According to the documentation, the correct way to do this is as follows:

LoadLibrary(PChar(Edit5.Text + 'teste.dll'));

2


Enjoy and test this:

libw := LoadLibrary(StringToOleStr(Edit1.Text + 'Project1.dll'));

1

An example : Imagine that in dll has the following function:

function Somar(a, b: Integer): Integer; stdcall;
begin
 Result := a + b; // retorna a soma
end;
//fazendo a leitura de uma dll

procedure TForm1.Button1Click(Sender: TObject);
type
 // vamos declarar um tipo function
  TSomarFuncao = function(a, b: Integer): Integer; stdcall;
var
  Somar: TSomarFuncao; // uma variável que representará a função
  DLLHandle: THandle; // este é o handle para a DLL
begin
  // vamos carregar a DLL
  DLLHandle := LoadLibrary('ItamarMinhaDLL.dll');
  try
    // vamos obter o endereço da função na DLL
    Somar := GetProcAddress(DLLHandle, 'Somar');

    // vamos chamar a função agora
    if Assigned(Somar) then
      ShowMessage(IntToStr(Somar(4, 3)))
    else
      ShowMessage('Não foi possível chamar a rotina desejada');
  finally
    FreeLibrary(DLLHandle); // vamos liberar a DLL
  end;

end;

1

Use like this

var
  wc : array[0..1024] of WideChar;
  path : String;

begin
  // (...) Outros codigos
  path := Edit5.Text + 'teste.dll';
  StringToWideChar(path, wc, Length(path));
  LoadLibrary(wc);
end;
  • did not work. See the complete TEST code if I leave in the same directory works perfectly: http://pastebin.com/3iSrTPsH

Browser other questions tagged

You are not signed in. Login or sign up in order to post.