compiler cant load escapi.dll error

General FreeBASIC programming questions.
Post Reply
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

compiler cant load escapi.dll error

Post by BasicCoder2 »

Recently my old laptop crashed and gave out and I had to buy a new laptop with Windows11.
I had saved my programs on USB ram sticks.
After downloading FreeBASIC onto the new laptop I tried to run an .exe program that captures images from any web cam.
It worked fine.
However when I tried to compile the source code and run it there was a fail with this error,
can't load 'escapi.dll' !
It is a 64 bit machine.
I am using FreeBASIC-1.09.0-win64

escapi.bi and the escapi.dll are in the same folder as the program being compiled and the escapi.dll in the folder must be being used by the .exe program compiled on my previous computer for the .exe to have worked.

Any ideas?

Code: Select all

#include "escapi.bi"

const SCR_W = 320
const SCR_H = 240

dim as integer nDevices=setupESCAPI()
if nDevices<1 then
  print "No active capture device found!"
  beep:sleep:end
end if

ScreenRes SCR_W,SCR_H,32
dim as any ptr lpImage=ImageCreate(SCR_W,SCR_H)

dim as SimpleCapParams Params
with Params
  .mWidth  = SCR_W
  .mHeight = SCR_H
  .mTargetBuf=cptr(integer ptr,lpImage)
  .mTargetBuf+=8
end with

WindowTitle "initCapture=" & str(initCapture(0, @Params))

while inkey<>chr$(27)
  doCapture(0)
  While isCaptureDone(0)<>1:Sleep(10):Wend
  put (0,0),lpImage,pset
wend
escapi.bi

Code: Select all

' Extremely Simple Capture API

type SimpleCapParams
  ' Target buffer. 
  ' Must be at least mWidth * mHeight * sizeof(int) of size! 
  as integer ptr mTargetBuf
  as integer  mWidth
  as integer  mHeight
end type


' Sets up the ESCAPI DLL and the function pointers below. Call this first!
' Returns number of capture devices found (same as countCaptureDevices, below)
declare function setupESCAPI() as integer

' return the number of capture devices found
type countCaptureDevicesProc as function cdecl as integer
dim shared as countCaptureDevicesProc countCaptureDevices

' initCapture tries to open the video capture device. 
' Returns 0 on failure, 1 on success. 
' Note: Capture parameter values must not change while capture device
'       is in use (i.e. between initCapture and deinitCapture).
'       Do *not* free the target buffer, or change its pointer!
type initCaptureProc as function cdecl (deviceno as integer,p as  SimpleCapParams ptr) as integer
dim shared as initCaptureProc initCapture

' deinitCapture closes the video capture device.
type deinitCaptureProc as sub cdecl(deviceno as integer)
dim shared as deinitCaptureProc deinitCapture

' doCapture requests video frame to be captured.
type doCaptureProc as sub cdecl(deviceno as integer)
dim shared as doCaptureProc doCapture

' isCaptureDone returns 1 when the requested frame has been captured.
type isCaptureDoneProc as function cdecl(deviceno as integer) as integer
dim shared as isCaptureDoneProc isCaptureDone

' Get the user-friendly name of a capture device.
type getCaptureDeviceNameProc as sub cdecl(deviceno as integer,namebuffer as zstring ptr,bufferlength as integer)
dim shared as getCaptureDeviceNameProc getCaptureDeviceName

' Returns the ESCAPI DLL version. 0x200 for 2.0
type ESCAPIDLLVersionProc as function() as integer
dim shared as ESCAPIDLLVersionProc ESCAPIDLLVersion

' Internal: initialize COM
type initCOMProc as sub cdecl
dim shared as initCOMProc initCOM

function setupESCAPI() as integer

  ' Load DLL dynamically
  dim as any ptr capdll = DyLibLoad("escapi.dll")
  if (capdll = 0) then
    print "can't load 'escapi.dll' !"
    beep:sleep:return 0
  end if
  ' Fetch function DyLibSymbol(escapi_dll,
  countCaptureDevices  = DyLibSymbol(capdll, "countCaptureDevices")
  initCapture          = DyLibSymbol(capdll, "initCapture")
  deinitCapture        = DyLibSymbol(capdll, "deinitCapture")
  doCapture            = DyLibSymbol(capdll, "doCapture")
  isCaptureDone        = DyLibSymbol(capdll, "isCaptureDone")
  initCOM              = DyLibSymbol(capdll, "initCOM")
  getCaptureDeviceName = DyLibSymbol(capdll, "getCaptureDeviceName")
  ESCAPIDLLVersion     = DyLibSymbol(capdll, "ESCAPIDLLVersion")

  if ESCAPIDLLVersion=0 then
    print "can't get proc address !"
    beep:sleep:return 0
  end if
  if (ESCAPIDLLVersion() <> &H200) then
        print "wrong dll version !"
    beep:sleep:return 0
  end if
  ' Initialize COM.
  initCOM()

  ' and return the number of capture devices found.
  return countCaptureDevices()
end function
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: compiler cant load escapi.dll error

Post by fxm »

Have you checked whether to unblock the dll file (after restoring it to your new laptop):
- Open Microsoft Windows Explorer to locate and right-click the restored file, choose Properties from the context menu.
- Click the Unblock button in the lower right-hand corner of the resulting dialog.
- Click OK or Apply.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: compiler cant load escapi.dll error

Post by dodicat »

Just running your code without any dll I get
can't load 'escapi.dll' !
So your DyLibLoad("escapi.dll") is not finding the dll and returning 0
Did you check the dll is 64 bits?
I downloaded
https://github.com/pbcodex/escapi/blob/ ... pi_x64.dll
and used
DyLibLoad("escapi_x64.dll")
It runs OK, I get
No active capture device found!
Which is fair enough, I don't have an active capture device.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: compiler cant load escapi.dll error

Post by BasicCoder2 »

Thank you very much dodicat that has saved me a lot of time.
FreeBASIC users are so lucky to have members such as yourself.
It now works except I am getting a blank magenta screen so I will have to work on that.
It has been a long time but I am keen to continue on some projects using webcams that I started some time ago now.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: compiler cant load escapi.dll error

Post by BasicCoder2 »

Thanks fxm i will look into your suggestion.
coderJeff
Site Admin
Posts: 4326
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: compiler cant load escapi.dll error

Post by coderJeff »

This header: escapi.h looks like it is using all 'int' data type. If this header is used on both 32-bit and 64-bit, then probably need to adjust the declarations for the DLL.

'int' in C is 32-bits wide on both 32-bit and 64-bit targets.
'long' in fb is 32-bits wide on both 32-bit and 64-bit targets.
But 'integer' in fb is 32-bits wide on 32-bit targets and 64-bit wide on 64-bit targets.

Try changing 'integer' to 'long' everywhere in the fb source to match the data type used by the DLL because 'integer' in fb can be 32-bits or 64-bits depending on target.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: compiler cant load escapi.dll error

Post by BasicCoder2 »

@coderJeff

Thank you. That worked. I am now am getting the webcam image instead of a blank magenta image.

I also had to change integer in the program itself to remove the suspicious pointer warning.

.mTargetBuf=cptr(integer ptr,lpImage)

to

.mTargetBuf=cptr(long ptr,lpImage)
Post Reply