Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Applikation -> DLL und umgekehrt (PChar) (https://www.delphipraxis.net/107910-applikation-dll-und-umgekehrt-pchar.html)

eLse-maestro 4. Feb 2008 14:50


Applikation -> DLL und umgekehrt (PChar)
 
Hi Leute,
Ich möchte einen string, bzw. einen PChar von einer dll an die Applikation & umgekehrt übergeben.
Mit einem Integer kriege ich das hin, aber nicht mit einem PChar, dann kommt immer eine zugriffsverletzung.

könnt ihr mir da weiterhelfen?
alle meine tutorials sind nur mit integer werten (dsdt.info + ein buch)

applikation:
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
type
  TInfoFunktion = function(about_what: pchar):pchar; stdcall;
  function info1(about_what: pchar):pchar;

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

var
  Form1: TForm1;

implementation

{$R *.dfm}
function info1(about_what: pchar):pchar;
var InfoFunktion: TInfoFunktion;
    Handle: THandle;
begin
  Handle:=LoadLibrary(PChar(ExtractFilePath(ParamStr(0))+'dll.dll'));
  if Handle <> 0 then begin
    @InfoFunktion := GetProcAddress(Handle, 'info');
    if @InfoFunktion <> nil then begin
      result := InfoFunktion(about_what);
    end;
    FreeLibrary(Handle);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var test:pchar;
begin
test:='test';
    showmessage(info1(@test));
end;

end.

dll:
Delphi-Quellcode:
library dll;



uses
  SysUtils,
  Classes;

{$R *.res}
function info(about_what: pchar):pchar; stdcall;
begin
  if about_what='test' then
  result := 'super1'
  else
  result:='super2';
end;

exports
  info;
begin
end.
edit: hmm und ich hatte heute schon ein paar av's

Medium 4. Feb 2008 14:55

Re: Applikation -> DLL und umgekehrt (PChar)
 
Zitat:

Zitat von eLse-maestro
dann kommt immer eine Fehlermeldung.

Ich hatte heute Gulasch.

Dax 4. Feb 2008 15:02

Re: Applikation -> DLL und umgekehrt (PChar)
 
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var test:pchar;
begin
test:='test';
    showmessage(info1(test));
end;

Luckie 4. Feb 2008 15:12

Re: Applikation -> DLL und umgekehrt (PChar)
 
Siehe hier: http://www.michael-puff.de/Artikel/2...String_DLL.php

(PS: Ich muss die Artikel noch mal überarbeiten, was den Kopf angeht.;) )

eLse-maestro 4. Feb 2008 16:01

Re: Applikation -> DLL und umgekehrt (PChar)
 
@dax, das hatte ich auch schon probiert, klappt nicht.

danke luckie.
ich verstehe nur eine zeile nicht
Str(Integer(@func1), s);


vielen dank


Alle Zeitangaben in WEZ +1. Es ist jetzt 18:56 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz