Making a webcam dll using vb
Making a webcam dll using vb
Making a webcam dll using vb
Making a webcam dll using vb
Making a webcam dll using vb
Making a webcam dll using vb Making a webcam dll using vb Making a webcam dll using vb Making a webcam dll using vb Making a webcam dll using vb Making a webcam dll using vb Making a webcam dll using vb Making a webcam dll using vb
Making a webcam dll using vb Making a webcam dll using vb
Making a webcam dll using vb
Go Back  Xtreme Visual Basic Talk > > > Making a webcam dll using vb


Reply
 
Thread Tools Display Modes
  #1  
Old 03-04-2008, 03:00 PM
3dkingpin 3dkingpin is offline
Junior Contributor
 
Join Date: Feb 2008
Posts: 256
Default Making a webcam dll using vb


I have the following code:

Quote:

Option Explicit On
Option Strict On

Public Class iCam
#Region "Api/constants"

Private Const WS_CHILD As Integer = &H40000000
Private Const WS_VISIBLE As Integer = &H10000000
Private Const SWP_NOMOVE As Short = &H2S
Private Const SWP_NOZORDER As Short = &H4S
Private Const WM_USER As Short = &H400S
Private Const WM_CAP_DRIVER_CONNECT As Integer = WM_USER + 10
Private Const WM_CAP_DRIVER_DISCONNECT As Integer = WM_USER + 11
Private Const WM_CAP_SET_VIDEOFORMAT As Integer = WM_USER + 45
Private Const WM_CAP_SET_PREVIEW As Integer = WM_USER + 50
Private Const WM_CAP_SET_PREVIEWRATE As Integer = WM_USER + 52
Private Const WM_CAP_GET_FRAME As Long = 1084
Private Const WM_CAP_COPY As Long = 1054
Private Const WM_CAP_START As Long = WM_USER
Private Const WM_CAP_STOP As Long = (WM_CAP_START + 68)
Private Const WM_CAP_SEQUENCE As Long = (WM_CAP_START + 62)
Private Const WM_CAP_SET_SEQUENCE_SETUP As Long = (WM_CAP_START + 64)
Private Const WM_CAP_FILE_SET_CAPTURE_FILEA As Long = (WM_CAP_START + 20)

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Short, ByVal lParam As String) As Integer
Private Declare Function capCreateCaptureWindowA Lib "avicap32.dll" (ByVal lpszWindowName As String, ByVal dwStyle As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Short, ByVal hWndParent As Integer, ByVal nID As Integer) As Integer
Private Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal wDriver As Short, ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, ByVal cbVer As Integer) As Boolean
Private Declare Function BitBlt Lib "GDI32.DLL" (ByVal hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As Int32) As Boolean

#End Region

Private iDevice As String
Private hHwnd As Integer
Private lwndC As Integer

Public iRunning As Boolean

Private CamFrameRate As Integer = 15
Private OutputHeight As Integer = 240
Private OutputWidth As Integer = 360

Public Sub resetCam()
'resets the camera after setting change
If iRunning Then
closeCam()
Application.DoEvents()

If setCam() = False Then
MessageBox.Show("Errror Setting/Re-Setting Camera")
End If
End If

End Sub

Public Sub initCam(ByVal parentH As Integer)
'Gets the handle and initiates camera setup
If Me.iRunning = True Then
MessageBox.Show("Camera Is Already Running")
Exit Sub
Else

hHwnd = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, OutputWidth, CShort(OutputHeight), parentH, 0)


If setCam() = False Then
MessageBox.Show("Error setting Up Camera")
End If
End If
End Sub

Public Sub setFrameRate(ByVal iRate As Long)
'sets the frame rate of the camera
CamFrameRate = CInt(1000 / iRate)

resetCam()

End Sub

Private Function setCam() As Boolean
'Sets all the camera up
If SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, CShort(iDevice), CType(0, String)) = 1 Then
SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, CShort(CamFrameRate), CType(0, String))
SendMessage(hHwnd, WM_CAP_SET_PREVIEW, 1, CType(0, String))
Me.iRunning = True
Return True
Else
Me.iRunning = False
Return False
End If
End Function

Public Function closeCam() As Boolean
'Closes the camera
If Me.iRunning Then
closeCam = CBool(SendMessage(hHwnd, WM_CAP_DRIVER_DISCONNECT, 0, CType(0, String)))
Me.iRunning = False
End If
End Function

Public Function copyFrame(ByVal src As PictureBox, ByVal rect As RectangleF) As Bitmap
If iRunning Then
Dim srcPic As Graphics = src.CreateGraphics
Dim srcBmp As New Bitmap(src.Width, src.Height, srcPic)
Dim srcMem As Graphics = Graphics.FromImage(srcBmp)


Dim HDC1 As IntPtr = srcPic.GetHdc
Dim HDC2 As IntPtr = srcMem.GetHdc

BitBlt(HDC2, 0, 0, CInt(rect.Width), _
CInt(rect.Height), HDC1, CInt(rect.X), CInt(rect.Y), 13369376)

copyFrame = CType(srcBmp.Clone(), Bitmap)

'Clean Up
srcPic.ReleaseHdc(HDC1)
srcMem.ReleaseHdc(HDC2)
srcPic.Dispose()
srcMem.Dispose()
Else
MessageBox.Show("Camera Is Not Running!")
End If
End Function

Public Function FPS() As Integer
Return CInt(1000 / (CamFrameRate))
End Function

End Class
I want to turn this into a dll, so Ican use it with another programming language. Note the language will only be able to communicate with the dll using double and string values (stdcall).

I tried... New Project->New Class, then pasted the code into the class window. But numerous errors were highlighted, e.g. for MessageBox.Show it says 'Name MessageBox is not declared'. It also stops recognising the Graphics, Bitmap anf RectangleF types.

So is it possible to turn this into a user friendly webcam dll, which would allow you to display the cam image on the window which you specify.
__________________
Hey, Looking for entry level job in VB net programming. Got basic qualification, years of programming experience (mainly self taught) and good portfolio. (UK)
Reply With Quote
  #2  
Old 03-04-2008, 03:38 PM
AtmaWeapon's Avatar
AtmaWeaponMaking a webcam dll using vb AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

There's a couple of things to consider, I'll start with the more immediate concern and move to the less immediate.

The reason that many elements of your code stopped being recognized is because by default a Class Library project only includes a minimal set of references, whereas a Windows Forms project includes several. To remedy this problem, you'll have to add references to the appropriate DLLs and possibly add Imports statements as well. I'll tell you the general process so you can do this yourself in the future, then give you an idea of what references/Imports you should add.

Step 1 - Figure out what References/Imports you need
Find a class that is having trouble in the documentation; for this example I'll use MessageBox. You are interested in the part of the documentation that looks like this:
Code:
Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
This tells you two things:
  • You need to add a reference to System.Windows.Forms.dll
  • You need to add an Imports statement for System.Windows.Forms or fully qualify the class name.

Step 2 - Add the reference
  • Right-click your project and select "Add Reference..."
  • Find the desired dll in the list (in this case System.Windows.Forms).
  • Select the dll and click the "OK" button.

Step 3 - Imports Statement/Namespace Qualification
Add the appropriate imports statement to the top of your file; for the MessageBox it would look like this:
Code:
Imports System.Windows.Forms
Alternatively, you could just fully qualify all instances of the class; a fully-qualified name for MessageBox would be System.Windows.Forms.MessageBox. This is generally inconvenient, but in some cases is unavoidable.

Repeat those three steps for each class that's giving you trouble, and it should work. My guess is you need to add System.Drawing as well (for Graphics).

Also, keep in mind that the DLLs you produce with VB .NET are still .NET DLLs and will not be able to be called from managed C/C++ applications except via COM. Other .NET applications will have no problems using your DLL, but getting unmanaged code to work with managed code is tough and I can offer no advice in this area.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 03-06-2008, 05:17 AM
3dkingpin 3dkingpin is offline
Junior Contributor
 
Join Date: Feb 2008
Posts: 256
Default

thanks, i shall try that, however in light in what you said I might consider using Delphi instead for making my DLL, as they are fully compatible with my other language gml.

I understood that dll's you make with vb.net are only really compatible with .net languages. I might double check this as Im sure its not always the case.
__________________
Hey, Looking for entry level job in VB net programming. Got basic qualification, years of programming experience (mainly self taught) and good portfolio. (UK)
Reply With Quote
  #4  
Old 03-06-2008, 09:00 AM
AtmaWeapon's Avatar
AtmaWeaponMaking a webcam dll using vb AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Through some kind of process I have never used nor cared to study, you can make a .NET DLL that is usable by a COM language, but that's the only way a non-.NET language can use a .NET DLL that I know of.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Making a webcam dll using vb
Making a webcam dll using vb
Making a webcam dll using vb Making a webcam dll using vb
Making a webcam dll using vb
Making a webcam dll using vb
Making a webcam dll using vb Making a webcam dll using vb Making a webcam dll using vb Making a webcam dll using vb Making a webcam dll using vb Making a webcam dll using vb Making a webcam dll using vb
Making a webcam dll using vb
Making a webcam dll using vb
 
Making a webcam dll using vb
Making a webcam dll using vb
 
-->