Incompatible types: PWideChar and TCaption

1

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

ERROR: Incompatible types: PWideChar and TCaption

I'm using it as follows:

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

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

Thank you!

    
asked by anonymous 23.10.2015 / 22:05

4 answers

2

Enjoy and test this:

libw := LoadLibrary(StringToOleStr(Edit1.Text + 'Project1.dll'));
    
24.10.2015 / 18:50
2

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

LoadLibrary(PChar(Edit5.Text + 'teste.dll'));
    
25.10.2015 / 17:35
1

Use it as well

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;
    
23.10.2015 / 23:32
1

An example: Imagine that in the dll it 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;
    
31.10.2015 / 20:03