Simple DLL question

Just starting out? Need help? Post your questions and find answers here.
User avatar
purebuilt
User
User
Posts: 46
Joined: Sun Dec 17, 2006 5:30 pm
Location: Milwaukee, WI, USA

Simple DLL question

Post by purebuilt »

It has been a long time since I've worked with DLLs in PB. I created one using ProcedureDLL and compiled it, but when I connect and try to read the procedures, they don't seem to be recognized. What am I doing wrong?

Here is the code to read the library file. Do I need to DeclareDLL all the procedure in the DLL?

Code: Select all

EnableExplicit

; Load Libraries
Define.l hndCommonLib = OpenLibrary(#PB_Any,"Z:\E\GBEMS\_MONITORS\GBEMS_2G_common.dll")

If hndCommonLib
  Debug hndCommonLib
  ExamineLibraryFunctions(hndCommonLib)
  While NextLibraryFunction()
    Debug LibraryFunctionName()
  Wend
   CloseLibrary(hndCommonLib)
EndIf
Thanks

DB
- DB
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Simple DLL question

Post by skywalk »

Your code works fine for my PB dll's.
v5 x86 Windows.
Shrink your dll code to 1 or 2 functions and try again.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
purebuilt
User
User
Posts: 46
Joined: Sun Dec 17, 2006 5:30 pm
Location: Milwaukee, WI, USA

Re: Simple DLL question

Post by purebuilt »

OK. It is working now. I guess the compile with the ProcedureDLL statements did not compile or my AV program grabbed it. Thanks for the help. It looks like we should be using Prototypes instead so I will need to look at that further.
- DB
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Simple DLL question

Post by skywalk »

Code: Select all

; You can either use:
Import "myDLL.lib"
  myDLL_FN.i(param1.i, param2.d, etc...)
EndImport
; Or
Prototype.i proto_myDLL_FN(param1.i, param2.d, etc...)
hDLL = OpenLibrary(#PB_Any, "myDLL.dll") 
  Global proto_myDLL_FN.proto_myDLL_FN = GetFunction(hDLL, "myDLL_FN")
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
blueb
Addict
Addict
Posts: 1111
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Simple DLL question

Post by blueb »

Tried purebuilt's code (above)

Code: Select all

EnableExplicit

; Load Libraries
Define hndCommonLib = OpenLibrary(#PB_Any,"Hook.dll") ; change as needed

If hndCommonLib
  Debug hndCommonLib
  ExamineLibraryFunctions(hndCommonLib)
  While NextLibraryFunction()
    Debug LibraryFunctionName()
  Wend
   CloseLibrary(hndCommonLib)
EndIf
Using PB 5.51 x86... Doesn't work

Went to PB 5.44 LTS (x86) and it works.

Suspect a Unicode thing... any ideas? :?:

blueb
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Simple DLL question

Post by Lunasole »

blueb wrote:Tried purebuilt's code (above)

Code: Select all

EnableExplicit

; Load Libraries
Define hndCommonLib = OpenLibrary(#PB_Any,"Hook.dll") ; change as needed

If hndCommonLib
  Debug hndCommonLib
  ExamineLibraryFunctions(hndCommonLib)
  While NextLibraryFunction()
    Debug LibraryFunctionName()
  Wend
   CloseLibrary(hndCommonLib)
EndIf
Using PB 5.51 x86... Doesn't work

Went to PB 5.44 LTS (x86) and it works.

Suspect a Unicode thing... any ideas? :?:

blueb
I've checked this with 5.51 and 5.4, it worked fine in both cases (with BASS.dll library).
That should not be a unicode problem, because DLL export names are always ASCII as I remember, and this is handled by OS + PB which should not impact with that unicode migration.
Probably something is wrong with your hook.dll.
Last edited by Lunasole on Wed Jan 18, 2017 1:39 am, edited 2 times in total.
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
blueb
Addict
Addict
Posts: 1111
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Simple DLL question

Post by blueb »

Odd:

Code: Select all

ProcedureDLL RegisterHook(type, callback, instance=0, thread=0)
  ProcedureReturn SetWindowsHookEx_(type, callback, instance, thread) 
EndProcedure

ProcedureDLL UnregisterHook(type, callback, instance=0, thread=0)
  ProcedureReturn UnhookWindowsHookEx_(hook) 
EndProcedure
It was the simplest DLL I could find.
Hook.DLL was compiled in 2014 (probably with 5.43 x86)

I took the same code... Hook2.DLL recompiled with 5.51 x86

and everything is fine.

I can remember Danilo posting an example and stating:

Code: Select all

;==================================================================
; Author:         Danilo  
; Date:           November  15, 2013
; Version:           
; Requires:      Both this program and DLL need to get compiled in same mode: ASCII or UNICODE,
;                    Or you have to specify mode in PeekS(), for example: PeekS(*test\Echo("testing"),-1,#PB_Unicode)    
;==================================================================
This may have something to do with it... I'm not familiar enough with DLL's to know.
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Simple DLL question

Post by Lunasole »

blueb wrote: ; Requires: Both this program and DLL need to get compiled in same mode: ASCII or UNICODE,
; Or you have to specify mode in PeekS(), for example: PeekS(*test\Echo
Well that warning definitely is not related to DLL load or functions import/enumeration. It works fine both if DLL is ASCII or Unicode, as well as program mode doesn't matter [because as I said in previous post, that DLL export table and stuff which imports it are always ASCII].

> Hook.DLL was compiled in 2014 (probably with 5.43 x86)
Maybe something with that [5.43 had bug?], I can't tell exactly
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
Post Reply