Page 1 of 1

Simple DLL question

Posted: Thu Jan 10, 2013 4:15 pm
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

Re: Simple DLL question

Posted: Thu Jan 10, 2013 4:43 pm
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.

Re: Simple DLL question

Posted: Thu Jan 10, 2013 5:43 pm
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.

Re: Simple DLL question

Posted: Thu Jan 10, 2013 6:41 pm
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")

Re: Simple DLL question

Posted: Tue Jan 17, 2017 3:21 pm
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

Re: Simple DLL question

Posted: Tue Jan 17, 2017 3:35 pm
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.

Re: Simple DLL question

Posted: Tue Jan 17, 2017 3:50 pm
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.

Re: Simple DLL question

Posted: Wed Jan 18, 2017 1:49 am
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