Re: [lazarus] DLL trouble

2007-09-15 Thread Sebastian Kraft
On Saturday 15 September 2007 23:19:48 Marco van de Voort wrote:
> On Sat, Sep 15, 2007 at 11:03:00PM +0200, Christian U. wrote:
> >>   result:='test';
> >> end;
> >>
> >> exports  GetString;
> >> end.
> >
> > strings are no standart types and cannto exported from an library without
> > special memmanager, use pchar
>
> Shortstrings can. He of course could have put it in Delphi mode, in which
> case the strings are ansistrings, and then the crash isn't strange.
>
Yes... ansistrings were enabled as standard because it was part of a lazarus 
project. That's also the reason why the simplified example worked outside of 
lazarus project

_
 To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] DLL trouble

2007-09-15 Thread Marco van de Voort
On Sat, Sep 15, 2007 at 11:03:00PM +0200, Christian U. wrote:
>>   result:='test';
>> end;
>> 
>> exports  GetString;
>> end.
>>   
> strings are no standart types and cannto exported from an library without 
> special memmanager, use pchar

Shortstrings can. He of course could have put it in Delphi mode, in which
case the strings are ansistrings, and then the crash isn't strange.

_
 To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] DLL trouble

2007-09-15 Thread Sebastian Kraft
On Saturday 15 September 2007 23:03:00 Christian U. wrote:
> > function GetString: string;export;
> > begin
> >   result:='test';
> > end;
> >
> > exports  GetString;
> > end.
>
> strings are no standart types and cannto exported from an library
> without special memmanager, use pchar
>
Thanks a lot! I tried with an integer and it worked...
Afterwards I tried with a PChar. Worked too :)

Sebastian



_
 To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] DLL trouble

2007-09-15 Thread Christian U.



function GetString: string;export;
begin
  result:='test';
end;

exports  GetString;
end.
  
strings are no standart types and cannto exported from an library 
without special memmanager, use pchar



+++

and here how it is called

+
var
libhandle: TLibHandle;
GetStringAddr: function: string;
str: string;  
begin

  libhandle:=LoadLibrary('libtestlib1');
  pointer(GetStringAddr):=GetProcAddress(FLibraryHandle, 'GetString');
  str:=GetStrAddr();
  writeln(str)
  unloadLibrary(libhandle);
  writeln(str)
end.
+++

It always crashes when I want to write 'str' the second time :( 


Sebastian

_
 To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives

  


_
To unsubscribe: mail [EMAIL PROTECTED] with
   "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] DLL trouble

2007-09-15 Thread Michael Van Canneyt


On Sat, 15 Sep 2007, Sebastian Kraft wrote:

> Hi,
> 
> Isn't it possible to use some functions from a dynamic library and afterwards 
> unload the library?
> can anybody tell me whats wrong with the following code?
> 
> This is my library:
> 
> ++
> library testlib1;
> 
> function GetString: string;export;
> begin
>   result:='test';
> end;
> 
> exports  GetString;
> end.
> +++
> 
> and here how it is called
> 
> +
> var
> libhandle: TLibHandle;
> GetStringAddr: function: string;
> str: string;  
> begin
>   libhandle:=LoadLibrary('libtestlib1');
>   pointer(GetStringAddr):=GetProcAddress(FLibraryHandle, 'GetString');
>   str:=GetStrAddr();
>   writeln(str)
>   unloadLibrary(libhandle);
>   writeln(str)
> end.
> +++
> 
> It always crashes when I want to write 'str' the second time :( 

Probably because the library has closed standard output ?

Michael.

_
 To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] DLL trouble

2007-09-15 Thread Sebastian Kraft
sorry... the simplified example I have posted works... The problem seems to 
stuck in the bigger program..

_
 To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives


[lazarus] DLL trouble

2007-09-15 Thread Sebastian Kraft
Hi,

Isn't it possible to use some functions from a dynamic library and afterwards 
unload the library?
can anybody tell me whats wrong with the following code?

This is my library:

++
library testlib1;

function GetString: string;export;
begin
  result:='test';
end;

exports  GetString;
end.
+++

and here how it is called

+
var
libhandle: TLibHandle;
GetStringAddr: function: string;
str: string;  
begin
  libhandle:=LoadLibrary('libtestlib1');
  pointer(GetStringAddr):=GetProcAddress(FLibraryHandle, 'GetString');
  str:=GetStrAddr();
  writeln(str)
  unloadLibrary(libhandle);
  writeln(str)
end.
+++

It always crashes when I want to write 'str' the second time :( 

Sebastian

_
 To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives