Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to set Height, Width and Video Format in VFP using AVICAP32.DLL

Status
Not open for further replies.

dylim

Programmer
Dec 12, 2001
106
0
16
PH
Hi Guys,

I was able to fire up a webcam on a VFP form using this link:


The problem is, every time the form shows, it will always show a Format Dialog (shown below) asking for Resolution, Pixel Depth and Size.

Screenshot_2023-10-26_155714_xnl5oy.png


Anyway I can programmatically set the three parameters?
 
Fine, but there are still some other recommendations open. Single step through the intialization of the struct with the debugger. Change your error handling. Just two of the top of my head.

Chriss
 
Just to showcase what you're missing, likely:

Christofs struct init has this:
Code:
...
	If     .LoadLibrary() ;
	   and .CreateMemory() ;
	   and .Requery()
		[highlight #FCE94F]Return .T.[/highlight]
	Else
		.Release()
		[highlight #FCE94F]Return .F.[/highlight]
	Endif

What changes if an init returns .t. vs .f.?
Well, the object get's created or not.

The return value is not passed back as return value of the createobject() call, it's telling VFP to either keep the object (when .t. is returned, which also is the default when you don't write an explicit RETURN .T. but just end the code of a method) or it's telling VFP to scrap the object.

So if you still didn't get what I was already mentioning above: If the struct class doesn't really create, loBitMapInfoHeader stays .f., that actually happened for me until I added convert.fll to the PATH.

Run this and see what happens:
Code:
On Error errortologfile()

? 'before local'
? 'loObject type is',Vartype(loObject)

Local loObject
? 'after local'
? 'loObject type is',Vartype(loObject)

loObject = CreateObject("myclass")
? 'after createobject'
? 'loObject type is',Vartype(loObject)
? 'loObject.property1 type is',Vartype(loObject.property1)
? 'loObject.property2 type is',Vartype(loObject.property2)
? 'end'
Modify File errors.log

Define Class myclass as custom
  property1 = "string" && vartype "C"
  property2 = 1  && vartype "N"

  Procedure Init()
     Return .F. 
  EndProc
EndDefine

Procedure errortologfile()
   #Define CRLF Chr(13)+Chr(10)
   StrToFile(Message()+CRLF,'errors.log',.t.)
   Return

It's not showcasing what Christofs struct fails for in detail, you have to find out using the debugger and single stepping through the init, but this showcases how the vartype output can be blank, because loBitMapInfoHeader does not become an object as you expect and vartype can also error instead of returning "U" for undefined things.

Of course, when loBitMapInfoHeader does not become a struct object, everything else fails, especially since there will be no struct string nor pointer to send with the WM_CAP_SET_VIDEOFORMAT message.

Get the struct class to work, then you also don't get blank output from vartype() calls. It's not vartype returning blank, it's vartype erroring and error handler returning which results in blank lines. I make that obvious by establishing a simplistic (too simplistic indeed, for production) error handler, which just outputs MESSAGE() to a log file and finally show that log. You'll have three errors "loObject is not an object" and thus no vartype output, not even "U" for undefined.

You're working on wrong premises like vartype(anything) can't error, in the worst case it will only be "U" or perhaps "X". Untrue. And I already mentioned another error Vartype() might throw is "Alias ... not found". I've had both in my testing until I finally got the requirements correct for the struct class to work.



Chriss
 
Next step: Once the struct class actually instanciates, a webcam will only react to structs settings it does support. You can't just set the width and height to anything and even if you set them to a supported resolution, the other properties of the struct also have to match what the webcam supports.

On tip: The struct.setstring() method can set the member properties of a struct object and if you add RETURN cBuffer to the getvideoformat method of the webcam class you can make use of that:
Code:
loBitMapInfoHeader = createobject("bitmapinfoheader") && based on struct
lcStruct = Left(webcam.getvideoformat(),40)
loBitmapInfoheader.setstring(lcStruct)

I have not yet reacted to this:
dylim said:
I have included file CONVERT.FLL in the folder where the EXE is.
That might not suffice, especially when you run tests in the IDE, which still has the default folder most likely set to HOME(), not the poroject or EXE folder.

Christofs struct class has no code to search for convert.fll, it requires you to make it fiundable and that's best done by adding it to the PATH, i.e. add the folder with convert.fll in with SET PATH additive.
Code:
Set Path to "......\Struct\" additive
Where .... will depend on where you have that struct folder or you set it to the path of the EXE.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top