Author Topic: DLLC status  (Read 14360 times)

0 Members and 1 Guest are viewing this topic.

JRS

  • Guest
Re: DLLC status
« Reply #15 on: May 08, 2020, 03:44:10 PM »
Back to my original issue of using DLLC to define my callback function and return a function pointer.

dllco2_b.sb seems close.

Code: Script BASIC
  1.  
  2.   include dllc.sbi
  3.  
  4.   oxy=dllfile("oxygen.dll")
  5.  
  6.   o2_basic = dllproc( oxy, "o2_basic i =(c*source) " )
  7.   o2_exec  = dllproc( oxy, "o2_exec  i =(i call)   " )
  8.   o2_error = dllproc( oxy, "o2_error c*=()         " )
  9.   o2_errno = dllproc( oxy, "o2_errno i =()         " )
  10.   o2_len   = dllproc( oxy, "o2_len   i =()         " )
  11.   o2_mode  = dllproc( oxy, "o2_mode     (i mode)   " )
  12.  
  13.   dllcall o2_mode,1
  14.   src="""
  15.  extern
  16.  
  17.  function funA(sys v) as sys
  18.  print v
  19.  end function
  20.  
  21.  sub finish()
  22.  terminate
  23.  end sub
  24.  
  25.  end extern
  26.  
  27.  addr funA
  28.  """
  29.  
  30.   function oxygen(src)
  31.   dllcall o2_basic,src
  32.   if (dllcall(o2_errno)<>0) then
  33.     dllprnt dllcall(o2_error)
  34.     a=0
  35.   else
  36.     a=dllcall(o2_exec,0)
  37.   end if
  38.   oxygen=a
  39.   end function
  40.  
  41.   a=oxygen(src)
  42.   dllcald(a,123)
  43.   dllprnt "Return code: " & a & "\n"
  44.   dllfile
  45.   ' line input q
  46.  
  47.  

Return code: 15859792

Is this what I  refer to as an O2 virtual DLL function?

Is the returned value the function pointer address?

Do I need to call the finish() sub before exiting SB?

Can there be more than one function in the O2 code section? If so, how do I call the functions / subs?

Update

dllco2_c.sb answered my questions about multiple O2 functions and  calling finish.

« Last Edit: May 08, 2020, 07:38:04 PM by John »

JRS

  • Guest
Re: DLLC status
« Reply #16 on: May 08, 2020, 09:04:51 PM »
Charles,

In the dllco2_e.sb example I noticed an additional argument I haven't seen before. dllcald(a,1)

Hello   = dllproc(a,"Hello   c*=(c*value) ", dllcald(a,1) )

Is this a reference to the link sub?

I found an O2 callback function in an IUP example.

https://www.oxygenbasic.org/forum/index.php?topic=1843.msg20025#msg20025

This should help with my virtual callback function in DLLC.
« Last Edit: May 08, 2020, 09:28:18 PM by John »

Charles Pegge

  • Guest
Re: DLLC status
« Reply #17 on: May 08, 2020, 11:22:14 PM »
Sorry John,

I have to withdraw from programming activities for a while. It takes too much time and mental energy in my current circumstances, so I am protecting my health.

JRS

  • Guest
Re: DLLC status
« Reply #18 on: May 09, 2020, 06:45:48 AM »
No problem. Take care of yourself and mum.

The only mystery is why freeimage won't work with the current release of O2.

Roland,

If you get a moment can you try accessing the freeimage.dll in O2 and see if it's something I'm doing wrong. The only unique thing about freeimage is its scrambled function names.

Other DLLC examples seem to be working. I really would like to add DLLC to the next ScriptBasic release.
« Last Edit: May 09, 2020, 07:59:43 AM by John »

jack

  • Guest
Re: DLLC status
« Reply #19 on: May 09, 2020, 12:51:18 PM »
@John
what do you mean by "scrambled function names" ?

JRS

  • Guest
Re: DLLC status
« Reply #20 on: May 09, 2020, 01:22:48 PM »
Hi Jack,

Check out the dumpbin output I posted on the page 1 of this thread.

Aurel

  • Guest
Re: DLLC status
« Reply #21 on: May 09, 2020, 02:02:57 PM »
John
That is a lot of functions from FreeImage.dll
and who knows what might be wrong .
Do you can test loading of that dll ?

int fiDLL = LoadLibrary "FreeImage.dll"
print str(fiDLL) ' if is greater than 0 then is loaded

JRS

  • Guest
Re: DLLC status
« Reply #22 on: May 09, 2020, 02:12:26 PM »
Aurel,

The DLL loads fine. Calling it drops ScriptBasic to the command prompt. Using the same DLLC code I can call Oxygen.dll without issue.

The script worked in prior versions O2.
« Last Edit: May 09, 2020, 03:53:12 PM by John »

jack

  • Guest
Re: DLLC status
« Reply #23 on: May 09, 2020, 07:13:19 PM »
I can't get it to compile with FreeBasic, no matter what I do ld can't find the symbols
it does compile if I call the dll functions by ordinal but crashes when run

jack

  • Guest
Re: DLLC status
« Reply #24 on: May 09, 2020, 07:41:43 PM »
the 64-bit version works ok
the function names are not scrambled

JRS

  • Guest
Re: DLLC status
« Reply #25 on: May 09, 2020, 09:02:08 PM »
I can't get it to compile with FreeBasic, no matter what I do ld can't find the symbols
it does compile if I call the dll functions by ordinal but crashes when run

Thanks Jack!

That confirms it's a freeimage.dll (32bit) issue, not DLLC (O2).

jack

  • Guest
Re: DLLC status
« Reply #26 on: May 09, 2020, 10:15:37 PM »
sorry John
I took a nap and tried again and both 32 and 64-bit versions work ok using FB, I will try O2 and see what happens
where can I find Freeimage.inc ?
« Last Edit: May 09, 2020, 10:54:11 PM by jack »

jack

  • Guest
Re: DLLC status
« Reply #27 on: May 10, 2020, 01:52:54 AM »
I am not fluent in O2, but this code works in 32-bit, modified example from https://www.oxygenbasic.org/forum/index.php?topic=631.msg5169#msg5169
Code: [Select]
'include "Freeimage.inc"
'include "RTL64.inc"

type FREE_IMAGE_FORMAT as long
enum
FIF_UNKNOWN = -1
FIF_BMP = 0
FIF_ICO = 1
FIF_JPEG = 2
FIF_JNG = 3
FIF_KOALA = 4
FIF_LBM = 5
FIF_IFF = FIF_LBM
FIF_MNG = 6
FIF_PBM = 7
FIF_PBMRAW = 8
FIF_PCD = 9
FIF_PCX = 10
FIF_PGM = 11
FIF_PGMRAW = 12
FIF_PNG = 13
FIF_PPM = 14
FIF_PPMRAW = 15
FIF_RAS = 16
FIF_TARGA = 17
FIF_TIFF = 18
FIF_WBMP = 19
FIF_PSD = 20
FIF_CUT = 21
FIF_XBM = 22
FIF_XPM = 23
FIF_DDS = 24
FIF_GIF = 25
FIF_HDR = 26
FIF_FAXG3 = 27
FIF_SGI = 28
FIF_EXR = 29
FIF_J2K = 30
FIF_JP2 = 31
FIF_PFM = 32
FIF_PICT = 33
FIF_RAW = 34
FIF_WEBP = 35
FIF_JXR = 36
end enum

type FREE_IMAGE_FILTER as long

type FREE_IMAGE_FILTER as long
enum
FILTER_BOX = 0
FILTER_BICUBIC = 1
FILTER_BILINEAR = 2
FILTER_BSPLINE = 3
FILTER_CATMULLROM = 4
FILTER_LANCZOS3 = 5
end enum

declare function FreeImageGetVersion lib "FreeImage.dll" Alias "_FreeImage_GetVersion@0"()  as zstring ptr
declare function FreeImage_Load lib "FreeImage.dll" Alias "_FreeImage_Load@12" (byval fif as long, byval filename as zstring ptr, byval flags as long) as sys
declare function FreeImage_GetWidth lib "FreeImage.dll" Alias "_FreeImage_GetWidth@4"(byval dib as sys) as ulong
declare function FreeImage_GetHeight lib "FreeImage.dll" Alias "_FreeImage_GetHeight@4"(byval dib as sys) as ulong
declare function FreeImage_Rescale lib "FreeImage.dll" Alias "_FreeImage_Rescale@16"(byval dib as sys, byval dst_width as long, byval dst_height as long, byval filter as long) as sys
declare function FreeImage_Save lib "FreeImage.dll" Alias "_FreeImage_Save@16"(byval fif as long, byval dib as sys, byval filename as zstring ptr, byval flags as long) as BOOL

sys img,imr
long lx,ly,tx,ty,r

img = FreeImage_Load FIF_PNG,"world_flip.png",0
lx  = FreeImage_GetWidth img
ly  = FreeImage_GetHeight img
tx  = lx/2
ty  = ly/2
imr = FreeImage_Rescale img,tx,ty,FILTER_BOX
r   = FreeImage_Save FIF_JPEG,imr,"t.jpg",0
print r
print tx " x " ty "  ok"

print FreeImageGetVersion()

jack

  • Guest
Re: DLLC status
« Reply #28 on: May 10, 2020, 01:55:03 AM »
and this works in 64-bit
Code: [Select]
'include "Freeimage.inc"
'include "RTL64.inc"

type FREE_IMAGE_FORMAT as long
enum
FIF_UNKNOWN = -1
FIF_BMP = 0
FIF_ICO = 1
FIF_JPEG = 2
FIF_JNG = 3
FIF_KOALA = 4
FIF_LBM = 5
FIF_IFF = FIF_LBM
FIF_MNG = 6
FIF_PBM = 7
FIF_PBMRAW = 8
FIF_PCD = 9
FIF_PCX = 10
FIF_PGM = 11
FIF_PGMRAW = 12
FIF_PNG = 13
FIF_PPM = 14
FIF_PPMRAW = 15
FIF_RAS = 16
FIF_TARGA = 17
FIF_TIFF = 18
FIF_WBMP = 19
FIF_PSD = 20
FIF_CUT = 21
FIF_XBM = 22
FIF_XPM = 23
FIF_DDS = 24
FIF_GIF = 25
FIF_HDR = 26
FIF_FAXG3 = 27
FIF_SGI = 28
FIF_EXR = 29
FIF_J2K = 30
FIF_JP2 = 31
FIF_PFM = 32
FIF_PICT = 33
FIF_RAW = 34
FIF_WEBP = 35
FIF_JXR = 36
end enum

type FREE_IMAGE_FILTER as long

type FREE_IMAGE_FILTER as long
enum
FILTER_BOX = 0
FILTER_BICUBIC = 1
FILTER_BILINEAR = 2
FILTER_BSPLINE = 3
FILTER_CATMULLROM = 4
FILTER_LANCZOS3 = 5
end enum

declare function FreeImageGetVersion lib "FreeImage.dll" Alias "FreeImage_GetVersion"()  as zstring ptr
declare function FreeImage_Load lib "FreeImage.dll" Alias "FreeImage_Load" (byval fif as long, byval filename as zstring ptr, byval flags as long) as sys
declare function FreeImage_GetWidth lib "FreeImage.dll" Alias "FreeImage_GetWidth"(byval dib as sys) as ulong
declare function FreeImage_GetHeight lib "FreeImage.dll" Alias "FreeImage_GetHeight"(byval dib as sys) as ulong
declare function FreeImage_Rescale lib "FreeImage.dll" Alias "FreeImage_Rescale"(byval dib as sys, byval dst_width as long, byval dst_height as long, byval filter as long) as sys
declare function FreeImage_Save lib "FreeImage.dll" Alias "FreeImage_Save"(byval fif as long, byval dib as sys, byval filename as zstring ptr, byval flags as long) as BOOL

sys img,imr
long lx,ly,tx,ty,r

img = FreeImage_Load FIF_PNG,"world_flip.png",0
lx  = FreeImage_GetWidth img
ly  = FreeImage_GetHeight img
tx  = lx/2
ty  = ly/2
imr = FreeImage_Rescale img,tx,ty,FILTER_BOX
r   = FreeImage_Save FIF_JPEG,imr,"t.jpg",0
print r
print tx " x " ty "  ok"

print FreeImageGetVersion()

JRS

  • Guest
Re: DLLC status
« Reply #29 on: May 10, 2020, 03:48:26 AM »
Jack,

Are you using the latest version of FreeImage?

I wonder if the problem is FreeImage requires some constant set before executing any functions?
« Last Edit: May 10, 2020, 04:08:30 AM by John »