windows.GetProcAddress() vs DynLibs.GetProcAddress()

classic Classic list List threaded Threaded
60 messages Options
123
Reply | Threaded
Open this post in threaded view
|

windows.GetProcAddress() vs DynLibs.GetProcAddress()

fredvs
Hello.

I have a external dll. In Windows i can access perfectly the procedures with
GetProcAddress() if i use Windows unit.

If i use DynLibs unit, prog crash when i try to load the procedure.
I prefer to use DynLibs unit because i want to use the dll for Linux too (of course with library.so).

I have try, in linux to access the procedure with DynLibs too but same crash than for Windows.
What must i do to access procedure with DynLibs ?

Many thanks.


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: windows.GetProcAddress() vs DynLibs.GetProcAddress()

Michael Van Canneyt


On Mon, 13 Jan 2014, Fred van Stappen wrote:

> Hello.
>
> I have a external dll. In Windows i can access perfectly the procedures with
> GetProcAddress() if i use Windows unit.
>
> If i use DynLibs unit, prog crash when i try to load the procedure.
> I prefer to use DynLibs unit because i want to use the dll for Linux too (of course with library.so).
>
> I have try, in linux to access the procedure with DynLibs too but same crash than for Windows.
> What must i do to access procedure with DynLibs ?

Can you be more specific ?  What error do you get ? Can show some code ?

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: windows.GetProcAddress() vs DynLibs.GetProcAddress()

Tomas Hajny-2
In reply to this post by fredvs
On Mon, January 13, 2014 11:47, Fred van Stappen wrote:

> Hello.
>
> I have a external dll. In Windows i can access perfectly the procedures
> with
> GetProcAddress() if i use Windows unit.
>
> If i use DynLibs unit, prog crash when i try to load the procedure.
> I prefer to use DynLibs unit because i want to use the dll for Linux too
> (of course with library.so).
>
> I have try, in linux to access the procedure with DynLibs too but same
> crash than for Windows.
> What must i do to access procedure with DynLibs ?

Can you provide a simplified program demonstrating the problem? Does it
"crash" when trying the obtain the address, or when trying to use it (e.g.
after assignment to a procedural variable)? If it is the latter, have you
checked that the calling conventions of your DLL and your procedural type
match? If it is the former, how is the "crash" demonstrated (i.e. what
happens)?

Tomas


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: windows.GetProcAddress() vs DynLibs.GetProcAddress()

fredvs
In reply to this post by Michael Van Canneyt

> Date: Mon, 13 Jan 2014 11:58:21 +0100

> From: [hidden email]
> To: [hidden email]
> Subject: Re: [fpc-pascal] windows.GetProcAddress() vs DynLibs.GetProcAddress()
>
>
>
> On Mon, 13 Jan 2014, Fred van Stappen wrote:
>
> > Hello.
> >
> > I have a external dll. In Windows i can access perfectly the procedures with
> > GetProcAddress() if i use Windows unit.
> >
> > If i use DynLibs unit, prog crash when i try to load the procedure.
> > I prefer to use DynLibs unit because i want to use the dll for Linux too (of course with library.so).
> >
> > I have try, in linux to access the procedure with DynLibs too but same crash than for Windows.
> > What must i do to access procedure with DynLibs ?
>
> Can you be more specific ? What error do you get ? Can show some code ?
>
> Michael.

Hello and many thanks for answer.

The library is SoundTouch.dll and libSoundTouch.so from :

>> http://www.surina.net/soundtouch/

>>>Here part of working code (if i call soundtouch_createInstance, it works)
...
uses  
Windows ;
...

var
soundtouch_createInstance : function() : THandle; stdcall; 

...

procedure InitLib(LibFile : PAnsiChar);
begin
  LibHandle := LoadLibrary(LibFile);
  if LibHandle <> 0 then
     Pointer(soundtouch_createInstance)   := GetProcAddress(LibHandle, PAnsiChar('soundtouch_createInstance'));

/////////////////////

>>> Here part of NOT working code (if i call soundtouch_createInstance, it crash)
...
uses  
dynlibs ;
...

var
soundtouch_createInstance : function() : THandle; stdcall; 

...

procedure InitLib(LibFile : PAnsiChar);
begin
LibHandle:=DynLibs.LoadLibrary(libfilename);
  if LibHandle <> DynLibs.NilHandle then
   
    Pointer(soundtouch_createInstance)        := DynLibs.GetProcedureAddress(LibHandle, PAnsiChar('soundtouch_createInstance'));

/////////////////////

Many thanks.



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: windows.GetProcAddress() vs DynLibs.GetProcAddress()

Michael Van Canneyt


On Mon, 13 Jan 2014, Fred van Stappen wrote:

>
> >>> Here part of NOT working code (if i call soundtouch_createInstance, it crash)
> ...
> uses  
> dynlibs ;
> ...
>
> var
> soundtouch_createInstance : function() : THandle; stdcall; 
>
> ...
>
> procedure InitLib(LibFile : PAnsiChar);
> begin
> LibHandle:=DynLibs.LoadLibrary(libfilename);
>   if LibHandle <> DynLibs.NilHandle then
>    
>     Pointer(soundtouch_createInstance)        := DynLibs.GetProcedureAddress(LibHandle, PAnsiChar('soundtouch_createInstance'));
Remove the typecast PansiChar()

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: windows.GetProcAddress() vs DynLibs.GetProcAddress()

fredvs
In reply to this post by Tomas Hajny-2
> Date: Mon, 13 Jan 2014 12:07:54 +0100
> From: [hidden email]

> To: [hidden email]
> Subject: Re: [fpc-pascal] windows.GetProcAddress() vs DynLibs.GetProcAddress()
>
> On Mon, January 13, 2014 11:47, Fred van Stappen wrote:
> > Hello.
> >
> > I have a external dll. In Windows i can access perfectly the procedures
> > with
> > GetProcAddress() if i use Windows unit.
> >
> > If i use DynLibs unit, prog crash when i try to load the procedure.
> > I prefer to use DynLibs unit because i want to use the dll for Linux too
> > (of course with library.so).
> >
> > I have try, in linux to access the procedure with DynLibs too but same
> > crash than for Windows.
> > What must i do to access procedure with DynLibs ?
>
> Can you provide a simplified program demonstrating the problem? Does it
> "crash" when trying the obtain the address, or when trying to use it (e.g.
> after assignment to a procedural variable)? If it is the latter, have you
> checked that the calling conventions of your DLL and your procedural type
> match? If it is the former, how is the "crash" demonstrated (i.e. what
> happens)?
>
> Tomas

Hello Tomas.

I have sent part of code in earlier topic, do you need more ?
The crash append when i try to call the procedure.


LoadLibrary(libfile) seems to work, i get result as "true".

Thanks



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: windows.GetProcAddress() vs DynLibs.GetProcAddress()

Mark Morgan Lloyd-5
In reply to this post by Tomas Hajny-2
Tomas Hajny wrote:

> On Mon, January 13, 2014 11:47, Fred van Stappen wrote:
>> Hello.
>>
>> I have a external dll. In Windows i can access perfectly the procedures
>> with
>> GetProcAddress() if i use Windows unit.
>>
>> If i use DynLibs unit, prog crash when i try to load the procedure.
>> I prefer to use DynLibs unit because i want to use the dll for Linux too
>> (of course with library.so).
>>
>> I have try, in linux to access the procedure with DynLibs too but same
>> crash than for Windows.
>> What must i do to access procedure with DynLibs ?
>
> Can you provide a simplified program demonstrating the problem? Does it
> "crash" when trying the obtain the address, or when trying to use it (e.g.
> after assignment to a procedural variable)? If it is the latter, have you
> checked that the calling conventions of your DLL and your procedural type
> match? If it is the former, how is the "crash" demonstrated (i.e. what
> happens)?

Also note the availability of GetLoadErrorStr on most platforms in later
versions of the RTL (>= 2.6.2 I think).

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: windows.GetProcAddress() vs DynLibs.GetProcAddress()

fredvs
In reply to this post by Michael Van Canneyt
Date: Mon, 13 Jan 2014 12:32:53 +0100
From: [hidden email]
To: [hidden email]
Subject: Re: [fpc-pascal] windows.GetProcAddress() vs DynLibs.GetProcAddress()

 

On Mon, 13 Jan 2014, Fred van Stappen wrote:

>
> >>> Here part of NOT working code (if i call soundtouch_createInstance, it crash)
> ...
> uses  
> dynlibs ;
> ...
>
> var
> soundtouch_createInstance : function() : THandle; stdcall; 
>
> ...
>
> procedure InitLib(LibFile : PAnsiChar);
> begin
> LibHandle:=DynLibs.LoadLibrary(libfilename);
>   if LibHandle <> DynLibs.NilHandle then
>    
>     Pointer(soundtouch_createInstance)        := DynLibs.GetProcedureAddress(LibHandle, PAnsiChar('soundtouch_createInstance'));

Remove the typecast PansiChar()

Michael.

>> Hello Michael and thanks for answer.
But if i remove PansiChar(), i still get :

An unhandled exception occurred at $0000000000000000:
EAccessViolation: Access violation
$0000000000000000



_______________________________________________ fpc-pascal maillist - [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: windows.GetProcAddress() vs DynLibs.GetProcAddress()

Michael Van Canneyt


On Mon, 13 Jan 2014, Fred van Stappen wrote:

> Date: Mon, 13 Jan 2014 12:32:53 +0100
> From: [hidden email]
> To: [hidden email]
> Subject: Re: [fpc-pascal] windows.GetProcAddress() vs DynLibs.GetProcAddress()
>
>
>
> On Mon, 13 Jan 2014, Fred van Stappen wrote:
>
> >
> > >>> Here part of NOT working code (if i call soundtouch_createInstance, it crash)
> > ...
> > uses  
> > dynlibs ;
> > ...
> >
> > var
> > soundtouch_createInstance : function() : THandle; stdcall; 
> >
> > ...
> >
> > procedure InitLib(LibFile : PAnsiChar);
> > begin
> > LibHandle:=DynLibs.LoadLibrary(libfilename);
> >   if LibHandle <> DynLibs.NilHandle then
> >    
> >     Pointer(soundtouch_createInstance)        := DynLibs.GetProcedureAddress(LibHandle, PAnsiChar('soundtouch_createInstance'));
>
> Remove the typecast PansiChar()
>
> Michael.
> >> Hello Michael and thanks for answer.
> But if i remove PansiChar(), i still get :
> An unhandled exception occurred at $0000000000000000:
> EAccessViolation: Access violation
>   $0000000000000000
What is the value of  Pointer(soundtouch_createInstance) after the above statement ? Is it nil ?

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: windows.GetProcAddress() vs DynLibs.GetProcAddress()

fredvs


On Mon, 13 Jan 2014, Fred van Stappen wrote:

> Date: Mon, 13 Jan 2014 12:32:53 +0100
> From: [hidden email]
> To: [hidden email]
> Subject: Re: [fpc-pascal] windows.GetProcAddress() vs DynLibs.GetProcAddress()
>
>
>
> On Mon, 13 Jan 2014, Fred van Stappen wrote:
>
> >
> > >>> Here part of NOT working code (if i call soundtouch_createInstance, it crash)
> > ...
> > uses  
> > dynlibs ;
> > ...
> >
> > var
> > soundtouch_createInstance : function() : THandle; stdcall; 
> >
> > ...
> >
> > procedure InitLib(LibFile : PAnsiChar);
> > begin
> > LibHandle:=DynLibs.LoadLibrary(libfilename);
> >   if LibHandle <> DynLibs.NilHandle then
> >    
> >     Pointer(soundtouch_createInstance)        := DynLibs.GetProcedureAddress(LibHandle, PAnsiChar('soundtouch_createInstance'));
>
> Remove the typecast PansiChar()
>
> Michael.
> >> Hello Michael and thanks for answer.
> But if i remove PansiChar(), i still get :
> An unhandled exception occurred at $0000000000000000:
> EAccessViolation: Access violation
> $0000000000000000

What is the value of Pointer(soundtouch_createInstance) after the above statement ? Is it nil ?

Michael.
Thanks for answer Michael.

Hum, how can i get the value of pointer if the application crash when i do :

>>  FHandle := soundtouch_createInstance();  

Maybe, i dont understood your question...




_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: windows.GetProcAddress() vs DynLibs.GetProcAddress()

Michael Van Canneyt


On Mon, 13 Jan 2014, Fred van Stappen wrote:

> > > begin
> > > LibHandle:=DynLibs.LoadLibrary(libfilename);
> > >   if LibHandle <> DynLibs.NilHandle then
> > >    
> > >     Pointer(soundtouch_createInstance)        := DynLibs.GetProcedureAddress(LibHandle, PAnsiChar('soundtouch_createInstance
> '));
> >
> > Remove the typecast PansiChar()
> >
> > Michael.
> > >> Hello Michael and thanks for answer.
> > But if i remove PansiChar(), i still get :
> > An unhandled exception occurred at $0000000000000000:
> > EAccessViolation: Access violation
> >   $0000000000000000
>
> What is the value of  Pointer(soundtouch_createInstance) after the above statement ? Is it nil ?
>
> Michael.
> Thanks for answer Michael.
>
> Hum, how can i get the value of pointer if the application crash when i do :
>
> >>  FHandle := soundtouch_createInstance();  
Do a

Writeln((@soundtouch_createInstance)=Nil);

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: windows.GetProcAddress() vs DynLibs.GetProcAddress()

el_es
In reply to this post by fredvs
Hi,

'scue me if I did not catch something, but

On 13/01/14 12:13, Fred van Stappen wrote:
[...]

>> > procedure InitLib(LibFile : PAnsiChar);
>> > begin
>> > LibHandle:=DynLibs.LoadLibrary(libfilename);
>> >   if LibHandle <> DynLibs.NilHandle then
>> >    
>> >     Pointer(soundtouch_createInstance)        := DynLibs.GetProcedureAddress(LibHandle, PAnsiChar('soundtouch_createInstance'));
>>
/// why not just :

@soundtouch_createInstance := DynLibs.GetProcedureAddress(LibHandle, PAnsiChar('soundtouch_createInstance'));

(or without the PAnsiChar cast as Michael said:)

@soundtouch_createInstance := DynLibs.GetProcedureAddress(LibHandle, 'soundtouch_createInstance');

?


>> Remove the typecast PansiChar()
>>
>> Michael.
[...]

>  
> What is the value of  Pointer(soundtouch_createInstance) after the above statement ? Is it nil ?
>  
> Michael.
>
> Thanks for answer Michael.
>
> Hum, how can i get the value of pointer if the application crash when i do :
>
>>>  FHandle := soundtouch_createInstance();  
>
> Maybe, i dont understood your question...
>

if Assigned(soundtouch_createInstance) then ShowMessage('Got good pointer for soundtouch_createInstance')
else ShowMessage('soundtouch_createInstance not assigned);

placed directly after the GetProcedureAddress call ?


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: windows.GetProcAddress() vs DynLibs.GetProcAddress()

fredvs
In reply to this post by Michael Van Canneyt

On Mon, 13 Jan 2014, Fred van Stappen wrote:
 

> > > begin
> > > LibHandle:=DynLibs.LoadLibrary(libfilename);
> > >   if LibHandle <> DynLibs.NilHandle then
> > >    
> > >     Pointer(soundtouch_createInstance)        := DynLibs.GetProcedureAddress(LibHandle, PAnsiChar('soundtouch_createInstance
> '));
> >
> > Remove the typecast PansiChar()
> >
> > Michael.
> > >> Hello Michael and thanks for answer.
> > But if i remove PansiChar(), i still get :
> > An unhandled exception occurred at $0000000000000000:
> > EAccessViolation: Access violation
> > $0000000000000000
>
> What is the value of Pointer(soundtouch_createInstance) after the above statement ? Is it nil ?
>
> Michael.
> Thanks for answer Michael.
>
> Hum, how can i get the value of pointer if the application crash when i do :
>
> >>  FHandle := soundtouch_createInstance();  

Do a

Writeln((@soundtouch_createInstance)=Nil);

Michael.
___________

Thanks Michael.

Result in Linux for :

if ST_Load('/home/fred/libSoundTouch/libSoundTouch.so')
then writeln('ok') else writeln('no') ;
>> ok

Writeln((@soundtouch_createInstance)=Nil); >> FALSE

I agree it is very strange, in windows, with unit Windows, it works perfectly..


_______________________________________________ fpc-pascal maillist - [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: windows.GetProcAddress() vs DynLibs.GetProcAddress()

Michael Van Canneyt


On Mon, 13 Jan 2014, Fred van Stappen wrote:

>
> On Mon, 13 Jan 2014, Fred van Stappen wrote:
>
>
> > > > begin
> > > > LibHandle:=DynLibs.LoadLibrary(libfilename);
> > > >   if LibHandle <> DynLibs.NilHandle then
> > > >    
> > > >     Pointer(soundtouch_createInstance)        := DynLibs.GetProcedureAddress(LibHandle, PAnsiChar('soundtouch_createInstan
> ce
> > '));
> > >
> > > Remove the typecast PansiChar()
> > >
> > > Michael.
> > > >> Hello Michael and thanks for answer.
> > > But if i remove PansiChar(), i still get :
> > > An unhandled exception occurred at $0000000000000000:
> > > EAccessViolation: Access violation
> > >   $0000000000000000
> >
> > What is the value of  Pointer(soundtouch_createInstance) after the above statement ? Is it nil ?
> >
> > Michael.
> > Thanks for answer Michael.
> >
> > Hum, how can i get the value of pointer if the application crash when i do :
> >
> > >>  FHandle := soundtouch_createInstance();  
>
> Do a
>
> Writeln((@soundtouch_createInstance)=Nil);
>
> Michael.
> ___________
> Thanks Michael.
> Result in Linux for :
> if ST_Load('/home/fred/libSoundTouch/libSoundTouch.so')
>   then   writeln('ok') else  writeln('no') ;
> >> ok
> Writeln((@soundtouch_createInstance)=Nil);
> >> FALSE
> I agree it is very strange, in windows, with unit Windows, it works perfectly..
Wait.

What happens if you use dynlibs on windows ?

Because there can be 1000 other reasons why the load failed on linux,
not necessarily connected to dynlibs.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: windows.GetProcAddress() vs DynLibs.GetProcAddress()

fredvs
On Mon, 13 Jan 2014, Fred van Stappen wrote:
 

>
> On Mon, 13 Jan 2014, Fred van Stappen wrote:
>
>
> > > > begin
> > > > LibHandle:=DynLibs.LoadLibrary(libfilename);
> > > >   if LibHandle <> DynLibs.NilHandle then
> > > >    
> > > >     Pointer(soundtouch_createInstance)        := DynLibs.GetProcedureAddress(LibHandle, PAnsiChar('soundtouch_createInstan
> ce
> > '));
> > >
> > > Remove the typecast PansiChar()
> > >
> > > Michael.
> > > >> Hello Michael and thanks for answer.
> > > But if i remove PansiChar(), i still get :
> > > An unhandled exception occurred at $0000000000000000:
> > > EAccessViolation: Access violation
> > > $0000000000000000
> >
> > What is the value of Pointer(soundtouch_createInstance) after the above statement ? Is it nil ?
> >
> > Michael.
> > Thanks for answer Michael.
> >
> > Hum, how can i get the value of pointer if the application crash when i do :
> >
> > >>  FHandle := soundtouch_createInstance();  
>
> Do a
>
> Writeln((@soundtouch_createInstance)=Nil);
>
> Michael.
> ___________
> Thanks Michael.
> Result in Linux for :
> if ST_Load('/home/fred/libSoundTouch/libSoundTouch.so')
> then writeln('ok') else writeln('no') ;
> >> ok
> Writeln((@soundtouch_createInstance)=Nil);
> >> FALSE
> I agree it is very strange, in windows, with unit Windows, it works perfectly..

Wait.

What happens if you use dynlibs on windows ?

Because there can be 1000 other reasons why the load failed on linux,
not necessarily connected to dynlibs.

Michael.
____________________________________________

Yep, Michael, many thanks for helping.

>> What happens if you use dynlibs on windows ?

Exactly the same as for Linux, it crash.

What i do not understand it is why, with Windows unit, it works perfectly and with Dynlibs unit, it crash. (with same code, of course).


_______________________________________________ fpc-pascal maillist - [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: windows.GetProcAddress() vs DynLibs.GetProcAddress()

fredvs
In reply to this post by el_es
> To: [hidden email]
> From: [hidden email]

> Date: Mon, 13 Jan 2014 12:52:51 +0000
> Subject: Re: [fpc-pascal] windows.GetProcAddress() vs DynLibs.GetProcAddress()
>
> Hi,
>
> 'scue me if I did not catch something, but
>
> On 13/01/14 12:13, Fred van Stappen wrote:
> [...]
>
> >> > procedure InitLib(LibFile : PAnsiChar);
> >> > begin
> >> > LibHandle:=DynLibs.LoadLibrary(libfilename);
> >> > if LibHandle <> DynLibs.NilHandle then
> >> >
> >> > Pointer(soundtouch_createInstance) := DynLibs.GetProcedureAddress(LibHandle, PAnsiChar('soundtouch_createInstance'));
> >>
> /// why not just :
>
> @soundtouch_createInstance := DynLibs.GetProcedureAddress(LibHandle, PAnsiChar('soundtouch_createInstance'));
>
> (or without the PAnsiChar cast as Michael said:)
>
> @soundtouch_createInstance := DynLibs.GetProcedureAddress(LibHandle, 'soundtouch_createInstance');
>
> ?
>
>
> >> Remove the typecast PansiChar()
> >>
> >> Michael.
> [...]
> >
> > What is the value of Pointer(soundtouch_createInstance) after the above statement ? Is it nil ?
> >
> > Michael.
> >
> > Thanks for answer Michael.
> >
> > Hum, how can i get the value of pointer if the application crash when i do :
> >
> >>> FHandle := soundtouch_createInstance();
> >
> > Maybe, i dont understood your question...
> >
>
> if Assigned(soundtouch_createInstance) then ShowMessage('Got good pointer for soundtouch_createInstance')
> else ShowMessage('soundtouch_createInstance not assigned);
>
> placed directly after the GetProcedureAddress call ?
_______________________________

> /// why not just :
>
> @soundtouch_createInstance := DynLibs.GetProcedureAddress(LibHandle, PAnsiChar('soundtouch_createInstance'));
>
> (or without the PAnsiChar cast as Michael said:)
>
> @soundtouch_createInstance := DynLibs.GetProcedureAddress(LibHandle, 'soundtouch_createInstance');
>

Many thanks... but im in a web-cafe and they want to close, i have to go...

I will try this and give you news later.

Many thanks.




_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: windows.GetProcAddress() vs DynLibs.GetProcAddress()

fredvs
In reply to this post by el_es
> To: [hidden email]
> From: [hidden email]

> Date: Mon, 13 Jan 2014 12:52:51 +0000
> Subject: Re: [fpc-pascal] windows.GetProcAddress() vs DynLibs.GetProcAddress()
>
> Hi,
>
> 'scue me if I did not catch something, but
>
> On 13/01/14 12:13, Fred van Stappen wrote:
> [...]
>
> >> > procedure InitLib(LibFile : PAnsiChar);
> >> > begin
> >> > LibHandle:=DynLibs.LoadLibrary(libfilename);
> >> > if LibHandle <> DynLibs.NilHandle then
> >> >
> >> > Pointer(soundtouch_createInstance) := DynLibs.GetProcedureAddress(LibHandle, PAnsiChar('soundtouch_createInstance'));
> >>
> /// why not just :
>
> @soundtouch_createInstance := DynLibs.GetProcedureAddress(LibHandle, PAnsiChar('soundtouch_createInstance'));
>
> (or without the PAnsiChar cast as Michael said:)
>
> @soundtouch_createInstance := DynLibs.GetProcedureAddress(LibHandle, 'soundtouch_createInstance');
>
> ?
>
>
> >> Remove the typecast PansiChar()
> >>
> >> Michael.
> [...]
> >
> > What is the value of Pointer(soundtouch_createInstance) after the above statement ? Is it nil ?
> >
> > Michael.
> >
> > Thanks for answer Michael.
> >
> > Hum, how can i get the value of pointer if the application crash when i do :
> >
> >>> FHandle := soundtouch_createInstance();
> >
> > Maybe, i dont understood your question...
> >
>
> if Assigned(soundtouch_createInstance) then ShowMessage('Got good pointer for soundtouch_createInstance')
> else ShowMessage('soundtouch_createInstance not assigned);
>
> placed directly after the GetProcedureAddress call ?
___________

Hello Lucaz

/// why not just :
>
> @soundtouch_createInstance := DynLibs.GetProcedureAddress(LibHandle, PAnsiChar('soundtouch_createInstance'));
>

Get that error :

>> libSoundTouch.pas(56,5) Error: Can't assign values to an address

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: windows.GetProcAddress() vs DynLibs.GetProcAddress()

el_es
On 13/01/14 13:36, Fred van Stappen wrote:
[...]

> Hello Lucaz
>
> /// why not just :
>>
>> @soundtouch_createInstance := DynLibs.GetProcedureAddress(LibHandle, PAnsiChar('soundtouch_createInstance'));
>>
>
> Get that error :
>
>>> libSoundTouch.pas(56,5) Error: Can't assign values to an address
>

This (@syntax) is in (OBJ)FPC mode, your example is Delphi mode.



http://wiki.freepascal.org/Lazarus/FPC_Libraries#Loadlibrary_-_dynamically_loading_a_dynamic_library

http://forum.lazarus.freepascal.org/index.php?topic=1148.0

OK I stand corrected, re. the pointer() cast...

but then why not declare in a public header for this wrapper:
type
  TSoundtouchCreateInstanceProc = procedure;

then
soundtouch_createinstance := TSoundtouchCreateInstanceProc(DynLibs.GetProcedureAddress(...));

(nb. delphi mode)

?

-L.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: windows.GetProcAddress() vs DynLibs.GetProcAddress()

fredvs
Hello and many thanks to help.

Here demo to show the problem (i hope).

>> https://sites.google.com/site/fiensprototyping/dynlib_vs_windows.zip

There is a program : test.pas
It uses a external library soundtouch_2.dll.

There are 2 wrappers :
soundtouch_windows.pas (who uses windows unit) and
soundtouch_dynlib.pas (who uses dynlib unit)

There are  also 4 binaries :

test_windows_fpc262.exe => OK, works (use soundtouch_windows.pas and compiled with fpc 262)

test_windows_fpc271.exe => NO, does NOT work (use soundtouch_windows.pas and compiled with fpc 271)

test_dynlib_fpc262.exe => NO, does NOT work (use soundtouch_dynlib.pas and compiled with fpc 262)

test_windows_fpc271.exe => NO, does NOT work (use soundtouch_windows.pas and compiled with fpc 271)

You may test the prog with soundtouch_windows.pas or soundtouch_dynlib.pas (uncomment the one you want in use section).

Many thanks.


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: windows.GetProcAddress() vs DynLibs.GetProcAddress()

fredvs
From: [hidden email]
To: [hidden email]
Date: Mon, 13 Jan 2014 17:33:47 +0100
Subject: Re: [fpc-pascal] windows.GetProcAddress() vs DynLibs.GetProcAddress()

Hello and many thanks to help.

Here demo to show the problem (i hope).

>> https://sites.google.com/site/fiensprototyping/dynlib_vs_windows.zip

There is a program : test.pas
It uses a external library soundtouch_2.dll.

There are 2 wrappers :
soundtouch_windows.pas (who uses windows unit) and
soundtouch_dynlib.pas (who uses dynlib unit)

There are  also 4 binaries :

test_windows_fpc262.exe => OK, works (use soundtouch_windows.pas and compiled with fpc 262)

test_windows_fpc271.exe => NO, does NOT work (use soundtouch_windows.pas and compiled with fpc 271)

test_dynlib_fpc262.exe => NO, does NOT work (use soundtouch_dynlib.pas and compiled with fpc 262)

test_windows_fpc271.exe => NO, does NOT work (use soundtouch_windows.pas and compiled with fpc 271)

You may test the prog with soundtouch_windows.pas or soundtouch_dynlib.pas (uncomment the one you want in use section).

Many thanks.


_______________________________________________ fpc-pascal maillist - [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Oops, forget about the 2.7.1. fpc binaries... (a 64 bit compiler was use in place of 32 bit)).

So, only take care about :

test_windows_fpc262.exe => OK, works (use soundtouch_windows.pas and compiled with fpc 262)

test_dynlib_fpc262.exe => NO, does NOT work (use soundtouch_dynlib.pas and compiled with fpc 262)

Many thanks.



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Many thanks ;-)
123