Jump to content

Recommended Posts

Posted

Hello,

I'm using this camera udf for my tablet to connect to my usb microscope.

It works fine, but sometimes windows changes the device ID. I searched for the dll that's being used in this UDF for a function to get the device name.

I found a function called "getCaptureDeviceName".

 

But I have no idea how to use it :/ I tried a few things but idk what the char buffer thing means.

May anyone help me out and explain it to me?

 

This is my code so far: 

#include <GDIplus.au3>
#Include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

HotKeySet("{ESC}", "_Exit")
;--------------------------------------------------------------------------
; Local variables
Global $Width = @DesktopWidth, $Height = @DesktopHeight, $hGraphics
Global $msg
;--------------------------------------------------------------------------
; variables required for dshow escapi
Local $tagSimpleCapParams = "ptr mTargetBuf;" & "int mWidth;" & "int mHeight;"
Local $tSimpleCapParams = DllStructCreate($tagSimpleCapParams)
Local $tTargetBuf = DllStructCreate("BYTE[" & $Width*$Height*4 & "]")
Global $pTargetBuf = DllStructGetPtr($tTargetBuf)
DllStructSetData($tSimpleCapParams, 1, $pTargetBuf)
DllStructSetData($tSimpleCapParams, 2, $Width)
DllStructSetData($tSimpleCapParams, 3, $Height)
Local $pSimpleCapParams = DllStructGetPtr($tSimpleCapParams)
Local $device = 0 ;change this number to select dshow device

;---------------------------------------------------------------------------
;Escapi init
Global $Gui = GUICreate("EscApi WebCam", $Width, $Height, 0, 0, $WS_POPUP)
Global $label = GUICtrlCreateLabel("LAB CAM | STREAMING...", 0, $Height - 50, $Width, 50, BitOR($SS_CENTER, $SS_CENTERIMAGE))
Global $btn = GUICtrlCreateButton("EXIT", $Width - 100, $Height - 50, 100, 50)

GUICtrlSetBkColor($btn, 0xff0000)
GUICtrlSetColor($btn, 0x000000)
GUICtrlSetFont($btn, 20, 1000, "", "Courier", 5)
GUISetBkColor(0x000000, $Gui)
GUICtrlSetFont($label, 30, 1000, "", "Courier", 5)
GUICtrlSetColor($label, 0x00ff00)
GUISetCursor(16, "", $Gui)
GUICtrlSetCursor($btn, 16)
GUICtrlSetCursor($label, 16)
GUISetState(@SW_SHOW,$Gui)
_GDIPlus_Startup()
local $_escapi_Dll = DllOpen("escapi.dll")
$return = DllCall($_escapi_Dll,"int","initCOM")
$return = DllCall($_escapi_Dll,"int","countCaptureDevices")
Consolewrite("Number of devices = " & $return[0] & @CRLF)
Global $charbuffer
$return = DllCall($_escapi_Dll,"str","getCaptureDeviceName","uint",2,"char",$charbuffer,"int",20)
Consolewrite($return)
$return = DllCall($_escapi_Dll,"int:cdecl","initCapture", "int", $device, "ptr", $pSimpleCapParams)
;---------------------------------------------------------------------------
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($Gui)

While 1

;Get frame
DllCall($_escapi_Dll,"none:cdecl","doCapture", "int", $device)
Do
$return = DllCall($_escapi_Dll,"int:cdecl","isCaptureDone", "int", $device)
GUISetState(@SW_SHOW, $gui)
$msg = GUIGetMsg()
If $msg = $btn Then
    _Exit()
EndIf
Until $return[0] = 1

$hBMP = _WinAPI_CreateBitmap($Width, $Height, 1 , 32 , $pTargetBuf)
Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)

_GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $Width, $Height - 100)


sleep(10)
_GDIPlus_BitmapDispose($hImage)
_WinAPI_DeleteObject($hBMP)

WEnd

;--------------------------------------------------------------------------
Func _Exit()
   _GDIPlus_GraphicsDispose($hGraphics)
   _GDIPlus_Shutdown()
DllCall($_escapi_Dll,"none:cdecl","deinitCapture", "int", 0)
GUIDelete($Gui)

    Exit
EndFunc

 

and this is the documentation of the DLL API:

struct SimpleCapParams
{
  /* Target buffer. 
   * Must be at least mWidth * mHeight * sizeof(int) of size! 
   */
  int * mTargetBuf;
  /* Buffer width */
  int mWidth;
  /* Buffer height */
  int mHeight;
};


/* Sets up the ESCAPI DLL and the function pointers below. Call this first! */
/* Returns number of capture devices found (same as countCaptureDevices, below) */
int setupESCAPI();

/* return the number of capture devices found */
int 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!
 */
int initCapture(unsigned int deviceno, struct SimpleCapParams *aParams);

/* deinitCapture closes the video capture device. */
void deinitCapture(unsigned int deviceno);

/* doCapture requests video frame to be captured. */
void doCapture(unsigned int deviceno);

/* isCaptureDone returns 1 when the requested frame has been captured.*/
int isCaptureDone(unsigned int deviceno);

/* Get the user-friendly name of a capture device. */
void getCaptureDeviceName(unsigned int deviceno, char *namebuffer, int bufferlength);

/* Returns the ESCAPI DLL version. 0x200 for 2.0 and later (for legacy support)*/
int ESCAPIDLLVersion();

/* Returns the ESCAPI version. 0x300 for 3.0.
   When checking the version, accept higher versions too. */
int ESCAPIVersionProc();

/* 
  On properties -
  - Not all cameras support properties at all.
  - Not all properties can be set to auto.
  - Not all cameras support all properties.
  - Messing around with camera properties may lead to weird results, so YMMV.
*/

/* Gets value (0..1) of a camera property (see CAPTURE_PROPERTIES, above) */
float getCapturePropertyValueProc(unsigned int deviceno, int prop);
/* Gets whether the property is set to automatic (see CAPTURE_PROPERTIES, above) */
int getCapturePropertyAutoProc(unsigned int deviceno, int prop);
/* Set camera property to a value (0..1) and whether it should be set to auto. */
int setCapturePropertyProc(unsigned int deviceno, int prop, float value, int autoval);

/*
  All error situations in ESCAPI are considered catastrophic. If such should
  occur, the following functions can be used to check which line reported the
  error, and what the HRESULT of the error was. These may help figure out
  what the problem is.
*/

/* Return line number of error, or 0 if no catastrophic error has occurred. */
int getCaptureErrorLineProc(unsigned int deviceno);
/* Return HRESULT of the catastrophic error, or 0 if none. */
int getCaptureErrorCodeProc(unsigned int deviceno);

 

Posted
11 hours ago, Nine said:

Try this :

#include <Array.au3>

Local $tBuffer = DllStructCreate("char string[100]")
Local $aReturn = DllCall("escapi.dll","none:cdecl","getCaptureDeviceName","uint",2,"struct*",$tBuffer,"int",DllStructGetSize($tBuffer))
_ArrayDisplay($aReturn)
ConsoleWrite($tBuffer.string & @CRLF)

 

It works thank you :)

Would you mind explaining me what type of data this $tBuffer.string is? I tried to StringInStr this but I cannot put this into a string variable.

Posted
3 hours ago, Nine said:

It is part of a structure that consist of 100 chars.  You can assign it to a variable and it will be fully considered as a string.  Show me the code you used and the error you got.

 

it seems to be an error of the latest autoit version. i tried an older version and my code works. thx :)

Posted (edited)

Then show the error-producing code, so we can assert if a bug is ramping there. Also tell us that you don't mix x86 and x64 versions.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted
17 hours ago, jchd said:

Then show the error-producing code, so we can assert if a bug is ramping there. Also tell us that you don't mix x86 and x64 versions.

it said invalid conversion from void to string. And nope I didn't mix up the architecture.

I'm on 3.3.6.1 now and it works. same code. no changes. im fine with that.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...