Author Topic: Request for DLL examples?  (Read 215 times)

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Full Member
  • ***
  • Posts: 231
    • PluriBASIC
Request for DLL examples?
« on: January 11, 2019, 10:40:18 AM »

 Hello, i am in need of some DLL examples. Maybe i could figure out, but i rather not trial and error this time. :)
I basically need to know how to capture, %DLL_PROCESS_ATTACH, %DLL_PROCESS_DETACH, %DLL_THREAD_ATTACH and 
%DLL_THREAD_DETACH.

Also, are the extern tags the ones needed for exporting the functions? Thanks!

John

  • Hero Member
  • *****
  • Posts: 3551
Re: Request for DLL examples?
« Reply #1 on: January 11, 2019, 12:06:35 PM »
Have you looked at how Charles is building the oxygen.dll?

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 3974
    • Oxygen Basic
Re: Request for DLL examples?
« Reply #2 on: January 11, 2019, 03:03:24 PM »
Hi Brian,

A minimal 64bit o2 DLL:

Code: [Select]

  '
  $dll
  $filename "t64.dll"
  uses RTL64


  'print "t64.dll Loaded"


  function HelloA(string s) as string, export
    return "HelloA "+s
  end function

  function HelloW(wstring s) as wstring, export
    return "HelloW "+s
  end function

Also supported without tagging each function:

extern export
..
end extern


Do you still need the low-level stuff: %DLL_PROCESS_ATTACH ?

John

  • Hero Member
  • *****
  • Posts: 3551
Re: Request for DLL examples?
« Reply #3 on: January 11, 2019, 03:59:42 PM »
It might be worth looking at the DLLC code as Charles does some amazing things with virtual shared objects and dynamic FFI.

Brian Alvarez

  • Full Member
  • ***
  • Posts: 231
    • PluriBASIC
Re: Request for DLL examples?
« Reply #4 on: January 11, 2019, 04:12:39 PM »
Do you still need the low-level stuff: %DLL_PROCESS_ATTACH ?

Hello Charles, Im trying to emulate an example that requires the %DLL_PROCESS_DETACH stuff, so, it would be great to have an example if possible. :)

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 3974
    • Oxygen Basic
Re: Request for DLL examples?
« Reply #5 on: January 11, 2019, 07:52:08 PM »
You can see it near the beginning of the RTLs:

DLL entry code in RTL64.inc
Code: [Select]
  % mode64bit


  '=================
  #ifdef dll
  '=================
  '
  'DLL EQUATES
  '
  % DLL_PROCESS_ATTACH   1
  % DLL_THREAD_ATTACH    2
  % DLL_THREAD_DETACH    3
  % DLL_PROCESS_DETACH   0
  % DLL_PROCESS_VERIFIER 4
  '
  select rdx
    case DLL_PROCESS_ATTACH : jmp fwd dll_start
    case DLL_PROCESS_DETACH : jmp fwd dll_finish
    case DLL_THREAD_ATTACH  : mov rax,0 : ret
    case DLL_THREAD_DETACH  : mov rax,0 : ret
  end select
  mov rax,0
  ret

  '---------
  dll_start:
  '=========
  '
  jmp fwd prolog

  '----------
  dll_finish:
  '==========
  '
  push rbx : push rsi : push rdi : push rax : push rbp
  mov rbp,rsp
  '
  lea rip rbx,bssdata
  '
  ! finish()
  finish()
  '
  mov rax,0
  mov rsp,rbp
  pop rbp : add rsp,8 : pop rdi : pop rsi : pop rbx
  ret


  '==========
  #endif 'DLL
  '==========