To all gurus,
I am currently converting some of C++ codes to VB.net
The C++ Codes is as follows :
================= C++ CODE ==================
typedef struct _tagBBCameraParameter
{
unsigned int preview_width;
unsigned int preview_height;
unsigned int preview_x;
unsigned int preview_y;
unsigned int preview_format;
unsigned int preview_zoom;
const TCHAR* capture_file_name;
unsigned int contrast;
unsigned int saturation;
unsigned int brightness;
} BBCameraParameter;
typedef LPVOID HBBCAMERA;
BBAPI DWORD WINAPI BBCameraPreviewStart(HBBCAMERA,
BBCameraParameter*);
BBAPI DWORD WINAPI BBCameraPreviewStop(HBBCAMERA);
================= END C++ CODE ==================
I managed to convert most of the codes to VB.Net but when I try to fun
BBCameraPreviewStart function, it gives error.
'=================Partial VB.Net Code
Public Shared Function BBCameraPreviewStart(ByVal HBBCamera As IntPtr,
ByRef BBParam1 As BBCameraParameter) As Integer
End Function
Public Shared Function BBCameraPreviewStop(ByVal HBBCamera As IntPtr)
As Integer
End Function
'=========== END OF PARTIAL VB.NET CODES
This is how i pass the parameters;
Dim BBParam as BBCameraParameter '// already declared but not shown
here
Dim HBBCamera as IntPtr '//Handle
'I have no problems getting handle but once i set the parameters for
BBParam and pass as follows, i get error (not much help from the
message).
BBCameraPreviewStart(HBBCAMERA, BBParam)
How do I call function BBCameraPreviewStart correctly? Did i do it
correctly?
Please advices.
Thanks
<snip>
<snip>
<snip>
Don't those need to be Declares to external libraries instead of local
methods?
Something like:
Declare Function BBCameraPreviewStart Lib "???" ( _
ByVal HBBCamera As IntPtr,
ByRef BBParam1 As BBCameraParameter) As Integer
Declare Function BBCameraPreviewStop Lib "???" ( _
ByVal HBBCamera As IntPtr) As Integer
HTH.
Regards,
Branco.
On Thursday, March 15, 2007 11:05 PM banleon wrote:
Branco,
Thanks for your comment and sorry about the mixed up and confusion.
Below is the complete source code in C++ and converted VB.Net source
code.
The C++ code (bbappapi.h) is provided by hardware manufacturer.
However, they don't have any samples available in .Net and their
technical support is unreachable most of the time.
I also include the VB.Net source codes that i converted from C++ codes
and a function to call the methods. The error message is
"NotSupportedException" which i think it's useless, or is it?
I hope i didn't miss out other information here. By the way, it's for
Windows CE 5.0 device.
-------------------- Begin C++ Code (bbappapi.h)
------------------------------
/*
* camera
*/
typedef enum
{
wb_auto =3D 0,
wb_cloudy,
wb_daylight,
wb_fluorescent_1,
wb_fluorescent_2,
wb_light_bulb
} white_balance_mode;
typedef enum
{
effect_none =3D 0,
effect_negative,
effect_embossing,
effect_black_n_white,
effect_sketch,
effect_solarization,
effect_sephia,
effect_aqua,
effect_posterize,
effect_warm,
effect_cool,
effect_antique,
effect_moonlight,
effect_fog,
} effect_mode;
typedef enum
{
flip_x =3D 1,
flip_y,
flip_x_y,
flip_origin
} flip_mode;
typedef enum
{
rate_auto =3D 1,
rate_day_manual,
rate_night_manual
} frame_rate_mode;
typedef enum
{
auto_save =3D 0,
manual_save
} save_mode;
typedef enum
{
file_type_jpg =3D 0,
file_type_bmp
} save_image_type;
typedef enum
{
rotate_default=3D0,
rotate_0,
rotate_90,
rotate_180,
rotate_270
} rotation_degree;
typedef enum
{
pixel_format_ycbcr =3D 0,
pixel_format_rgb_565, // output data =B0=A1 bmp =C0=CC=B4=D9.
pixel_format_rgb_565_raw // output data =B0=A1 16bit rgb =B5=A5=C0=CC=C5=
=CD =C0=CC=B4=D9.
} pixel_format_select;
typedef struct _tagBBCameraParameter
{
unsigned int preview_width;
unsigned int preview_height;
unsigned int preview_x;
unsigned int preview_y;
unsigned int preview_format;
unsigned int preview_zoom;
const TCHAR* capture_file_name;
unsigned int capture_width;
unsigned int capture_height;
pixel_format_select capture_format;
unsigned int capture_strobe_on;
unsigned int contrast;
unsigned int saturation;
unsigned int brightness;
effect_mode ef_mode;
white_balance_mode wb_mode;
flip_mode fp_mode;
frame_rate_mode fr_mode;
unsigned int reserved[20];
BYTE* p_app_buffer;
BYTE* p_app_capture_buffer; //still image capture=BF=A1=BC=AD =B5=A5=C0=
=CC=C5=CD=B8=A6 =B9=DE
=B1=E2=C0=A7=C7=D1 =C6=F7=C0=CE=C5=CD
save_mode stillimage_savemode;
save_image_type save_fileType;
unsigned int ImageQuality;
BOOL isSaveFile;
rotation_degree rotation;
} BBCameraParameter;
typedef struct _tagBBCameraInfo
{
unsigned int preview_max_width;
unsigned int preview_max_height;
unsigned int preview_min_width;
unsigned int preview_min_height;
unsigned int image_max_width;
unsigned int image_max_height;
unsigned int reserved[20];
} BBCameraInfo;
typedef LPVOID HBBCAMERA;
BBAPI HBBCAMERA WINAPI BBCameraOpen(HWND);
BBAPI DWORD WINAPI BBCameraClose(HBBCAMERA);
BBAPI DWORD WINAPI BBCameraPreviewStart(HBBCAMERA,
BBCameraParameter*);
BBAPI DWORD WINAPI BBCameraPreviewStop(HBBCAMERA);
BBAPI DWORD WINAPI BBCameraPreviewPause(HBBCAMERA);
BBAPI DWORD WINAPI BBCameraPreviewResume(HBBCAMERA);
BBAPI DWORD WINAPI BBCameraPreviewZoom(HBBCAMERA, BBCameraParameter*);
BBAPI DWORD WINAPI BBCameraGetRawDataStart(HBBCAMERA,
BBCameraParameter*);
BBAPI DWORD WINAPI BBCameraGetRawDataStop(HBBCAMERA);
BBAPI DWORD WINAPI BBCameraGetRawDataPause(HBBCAMERA);
BBAPI DWORD WINAPI BBCameraGetRawDataResume(HBBCAMERA);
BBAPI DWORD WINAPI BBCameraGetRawDataZoom(HBBCAMERA,
BBCameraParameter*);
BBAPI DWORD WINAPI BBCameraCapture(HBBCAMERA, BBCameraParameter*);
BBAPI DWORD WINAPI BBCameraStoreCaptureImage(HBBCAMERA,
BBCameraParameter*);
BBAPI DWORD WINAPI BBCameraRestartPreviewFromCapture(HBBCAMERA,
BBCameraParameter*);
BBAPI DWORD WINAPI BBCameraSetWhiteBalance(HBBCAMERA,
BBCameraParameter*);
BBAPI DWORD WINAPI BBCameraSetContrast(HBBCAMERA, BBCameraParameter*);
BBAPI DWORD WINAPI BBCameraSetSaturation(HBBCAMERA,
BBCameraParameter*);
BBAPI DWORD WINAPI BBCameraSetBrightness(HBBCAMERA,
BBCameraParameter*);
BBAPI DWORD WINAPI BBCameraSetEffect(HBBCAMERA, BBCameraParameter*);
BBAPI DWORD WINAPI BBCameraSetFlip(HBBCAMERA, BBCameraParameter*);
BBAPI DWORD WINAPI BBCameraNightMode(HBBCAMERA, BBCameraParameter*);
BBAPI DWORD WINAPI BBCameraGetInfo(HBBCAMERA, BBCameraInfo*);
BBAPI DWORD WINAPI BBCameraDumpRegister(HBBCAMERA);
------------------------------ END of C++ Code -----------------------
---------------------------- Declaration in VB.Net------------
Public Const BB_CAMERA_CODE_SUCCESS =3D 0
Public Const BB_CAMERA_CODE_ERR_UNKNOWN =3D 1
Public Const BB_CAMERA_CODE_ERR_INVALID_HANDLE =3D 2
Public Const BB_CAMERA_CODE_ERR_INVALID_PARAMETER =3D 3
Enum white_balance_mode
wb_auto =3D 0
wb_cloudy
wb_daylight
wb_fluorescent_1
wb_fluorescent_2
wb_light_bulb
End Enum
Enum effect_mode
effect_none =3D 0
effect_negative
effect_embossing
effect_black_n_white
effect_sketch
effect_solarization
effect_sephia
effect_aqua
effect_posterize
effect_warm
effect_cool
effect_antique
effect_moonlight
effect_fog
End Enum
Enum flip_mode
flip_x =3D 1
flip_y
flip_x_y
flip_origin
End Enum
Enum frame_rate_mode
rate_auto =3D 1
rate_day_manual
rate_night_manual
End Enum
Enum save_mode
auto_save =3D 0
manual_save
End Enum
Enum save_image_type
file_type_jpg =3D 0
file_type_bmp
End Enum
Enum rotation_degree
rotate_default =3D 0
rotate_0
rotate_90
rotate_180
rotate_270
End Enum
Enum pixel_format_select
pixel_format_ycbcr =3D 0
pixel_format_rgb_565 ' // output data =B0=A1 bmp =C0=CC=B4=D9.
pixel_format_rgb_565_raw ' // output data =B0=A1 16bit rgb =B5=A5=
=C0=CC=C5=CD
=C0=CC=B4=D9.
End Enum
Structure BBCameraInfo
Public preview_max_width As System.UInt16
Public preview_max_height As System.UInt16
Public preview_min_width As System.UInt16
Public image_max_width As System.UInt16
Public image_max_height As System.UInt16
End Structure
Structure BBCameraParameter
Public preview_width As System.UInt16
Public preview_height As System.UInt16
Public preview_x As System.UInt16
Public preview_y As System.UInt16
Public preview_format As System.UInt16
Public preview_zoom As System.UInt16
Public capture_file_name As String
Public capture_width As System.UInt16
Public capture_height As System.UInt16
Public capture_strobe_on As System.UInt16
Public capture_format As pixel_format_select
Public contrast As System.UInt16
Public saturation As System.UInt16
Public brightness As System.UInt16
Public ef_mode As effect_mode
Public wb_mode As white_balance_mode
Public fp_mode As flip_mode
Public fr_mode As frame_rate_mode
' unsigned int reserved[20];
Public reserved() As System.UInt16
Public p_app_buffer() As Byte
Public p_app_capture_buffer() As Byte
Public stillimage_savemode As save_mode
Public save_fileType As save_image_type
Public ImageQuality As Integer
Public isSaveFile As Boolean
Public rotation As rotation_degree
End Structure
Dim HBBCAMERA As IntPtr
Dim BBInfo As New BBCameraInfo
Dim BBParam As New BBCameraParameter
<DllImport("bbappapi.dll")> _
Public Shared Function BBCameraOpen(ByVal HWND As IntPtr)
As IntPtr
End Function
<DllImport("bbappapi.dll")> _
Public Shared Function BBCameraClose(ByVal HBBCamera As IntPtr)
As Integer
End Function
<DllImport("bbappapi.dll")> _
Public Shared Function BBCameraPreviewStart(ByVal HBBCamera As
IntPtr, ByRef BBParam1 As BBCameraParameter) As Integer
End Function
<DllImport("bbappapi.dll")> _
Public Shared Function BBCameraPreviewStop(ByVal HBBCamera As IntPtr)
As Integer
End Function
<DllImport("bbappapi.dll")> _
Public Shared Function BBCameraPreviewPause(ByVal HBBCamera As IntPtr)
As Integer
End Function
<DllImport("bbappapi.dll")> _
Public Shared Function BBCameraPreviewZoom(ByVal HBBCamera As IntPtr)
As Integer
End Function
<DllImport("bbappapi.dll")> _
Public Shared Function BBCameraGetInfo(ByVal HBBCamera As IntPtr,
ByRef BBInfo As BBCameraInfo) As Integer
End Function
<DllImport("bbappapi.dll")> _
Public Shared Function BBCameraGetRawDataStart(ByVal HBBCamera As
IntPtr, ByRef BBParam As BBCameraParameter) As Integer
End Function
<DllImport("bbappapi.dll")> _
Public Shared Function BBCameraGetRawDataStop(ByVal HBBCamera As
IntPtr) As Integer
End Function
<DllImport("bbappapi.dll")> _
Public Shared Function BBCameraGetRawDataPause(ByVal HBBCamera As
IntPtr, ByRef BBParam1 As BBCameraParameter) As Integer
End Function
<DllImport("bbappapi.dll")> _
Public Shared Function BBCameraGetRawDataResume(ByVal HBBCamera As
IntPtr) As Integer
End Function
<DllImport("bbappapi.dll")> _
Public Shared Function BBCameraCapture(ByVal HBBCamera As IntPtr,
ByRef BBParam1 As BBCameraParameter) As Integer
End Function
' So this is the method that i call to
'
Private Sub StartOperation()
Dim BBParam As BBCameraParameter
Dim StartCamera as boolean
Try
HBBCAMERA =3D BBCameraOpen(picCamera.Handle) 'Get the
handler
StartCamera =3D True
Catch ex As Exception
StartCamera =3D False
End Try
If StartCamera Then
' If camera started then assign some parameters
With BBParam
.preview_width =3D 0
.preview_height =3D 100
.preview_format =3D 0
.ImageQuality =3D 5
.brightness =3D 50
.rotation =3D rotation_degree.rotate_0
.preview_x =3D 0
.preview_y =3D 0
.contrast =3D 200
.saturation =3D 200
.ef_mode =3D effect_mode.effect_none
.wb_mode =3D white_balance_mode.wb_auto
Dim pbuffer() As Byte
ReDim pbuffer(.preview_width * .preview_height * 2)
ReDim .reserved(20)
.p_app_buffer =3D pbuffer
.p_app_capture_buffer =3D pbuffer
End With
TextBox1.Text =3D "Get handle :" & HBBCAMERA.ToString
'GET CAMERA INFO (No problem here, can get the info from
camera)
BBCameraGetInfo(HBBCAMERA, BBInfo)
TextBox1.Text +=3D vbCrLf & "BBInfo.image_max_height:" &
BBInfo.image_max_height
TextBox1.Text +=3D vbCrLf & "BBInfo.image_max_width:" &
BBInfo.image_max_width
TextBox1.Text +=3D vbCrLf & "BBInfo.preview_max_height:" &
BBInfo.preview_max_height
TextBox1.Text +=3D vbCrLf & "BBInfo.preview_max_width:" &
BBInfo.preview_max_width
TextBox1.Text +=3D vbCrLf & "BBInfo.preview_min_width:" &
BBInfo.preview_min_width
Try
'Preview camera image (ERROR OCCURS HERE)
Dim rst As Integer =3D BBCameraPreviewStart(HBBCAMERA,
BBParam)
TextBox1.Text +=3D vbCrLf & "Preview OK"
Catch ex As Exception
TextBox1.Text +=3D vbCrLf & "Preview Failed"
End Try
Else
TextBox1.Text +=3D vbCrLf & "Cannot start camera"
End If
End Sub
----------------------------- 'END OF VB.Net
Codes---------------------
Hope to hear from you guys.
Thanks again!