473,416 Members | 1,659 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

C++ Function Pointer to VB.Net

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

Mar 14 '07 #1
10 3394
banleong wrote:
<snip>
I am currently converting some of C++ codes to VB.net
<snip>
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
<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.

Mar 14 '07 #2
I think function pointers are replaced (at least functionally) by
delegates. I'm not entirely sure what you're trying to do her, so I
can't suggest any code easily, but maybe look into using delegates
instead of function pointers.

What kind of error are you getting?

Mar 14 '07 #3
Branco,

Yes, it is external libraries.

Lord Zoltar,
Basically, when i tried to pass the parameter as follows in this
function, i got error:

BBCameraPreviewStart(HBBCAMERA, BBParam)

where HBBCamera is the handler and BBParam is the struction
declaration of BBCameraParameter.

I assume there is not problem getting the handler because I can call
other functions like getting camera info by passing the handler
(function not shown here).

So, I assume there could be the way I declare the structure or passing
parameters of BBParam that causes the error.

Perhaps i should break down by questions to:
1) Is my declaration correct for BBCameraPreviewStart in VB.net code
based on the C++ codes?

BBAPI DWORD WINAPI BBCameraPreviewStart(HBBCAMERA,
BBCameraParameter*);

to

Public Shared Function BBCameraPreviewStart(ByVal HBBCamera As IntPtr,
ByRef BBParam1 As BBCameraParameter) As Integer
End Function

2) Did i pass the parameter correct when calling BBCameraPreviewStart
function? Below are my procedure

Dim BBParam As BBCameraParameter 'Declare variable to hold
BBCameraParameter structure
With BBParam
.preview_width = 0
.preview_height = 100
.preview_format = 0
.ImageQuality = 5
.brightness = 5
.rotation = rotation_degree.rotate_0
.preview_x = 0
.preview_y = 0
.contrast = 200
.saturation = 200
.ef_mode = effect_mode.effect_none
.wb_mode = white_balance_mode.wb_auto
Dim pbuffer() As Byte
ReDim pbuffer(.preview_width * .preview_height * 2)
ReDim .reserved(20)
.p_app_buffer = pbuffer
.p_app_capture_buffer = pbuffer

End With

'Call function
BBCameraPreviewStart (Handler, BBParam)

Am i doing the right thing here?

Thanks and Regards

Mar 15 '07 #4
banleong wrote:
<snip>
Yes, it is external libraries.
<snip>
1) Is my declaration correct for BBCameraPreviewStart in VB.net code
based on the C++ codes?

BBAPI DWORD WINAPI BBCameraPreviewStart(HBBCAMERA,
BBCameraParameter*);

to

Public Shared Function BBCameraPreviewStart(ByVal HBBCamera As IntPtr,
ByRef BBParam1 As BBCameraParameter) As Integer
End Function
<snip>

Nope. When you have to reference a method in an external library, you
need to indicate to VB which library is this (the .dll file), the
character type accepted by the method (ansi or unicode) and the method
signature, among other things.

Usually this is done using a Declare. Suppose, for instance, that the
method that you want to call is from, say, a dll called BBAPI.dll.
This would be the declaration of the function in VB:

Declare Ansi Function BBCameraPreviewStart _
Lib "BBAPI.dll" ( _
ByVal HBBCamera As IntPtr,
ByRef BBParam1 As BBCameraParameter) As Integer

Of course, this is just the declaration. To actually *call* the
method, it's no different from any other methods.

HTH.

Regards,

Branco.

Mar 15 '07 #5
On Mar 15, 1:17 pm, "Branco Medeiros" <branco.medei...@gmail.com>
wrote:
banleong wrote:

<snip>Yes, it is external libraries.
<snip>
1) Is my declaration correct for BBCameraPreviewStart in VB.net code
based on the C++ codes?
BBAPI DWORD WINAPI BBCameraPreviewStart(HBBCAMERA,
BBCameraParameter*);
to
Public Shared Function BBCameraPreviewStart(ByVal HBBCamera As IntPtr,
ByRef BBParam1 As BBCameraParameter) As Integer
End Function

<snip>

Nope. When you have to reference a method in an external library, you
need to indicate to VB which library is this (the .dll file), the
character type accepted by the method (ansi or unicode) and the method
signature, among other things.

Usually this is done using a Declare. Suppose, for instance, that the
method that you want to call is from, say, a dll called BBAPI.dll.
This would be the declaration of the function in VB:

Declare Ansi Function BBCameraPreviewStart _
Lib "BBAPI.dll" ( _
ByVal HBBCamera As IntPtr,
ByRef BBParam1 As BBCameraParameter) As Integer

Of course, this is just the declaration. To actually *call* the
method, it's no different from any other methods.

HTH.

Regards,

Branco.
Branco,

Thanks for your reply.

Actually i already declare the external function as

<DllImport("bbappapi.dll")_
Public Shared Function BBCameraPreviewStart(ByVal HBBCamera As
IntPtr, ByRef BBParam1 As BBCameraParameter) As Integer
End Function

Sorry for the confusion because i didn't include the <DllImportpart
on early post.
However, passing the parameters seem to failed.Guess have not choice
but go back to manufacturer, eh?

Regards

Mar 15 '07 #6
hey C++ kid

go and play in a freeway

C++ is dead and so is VB
SERIOUSLY

it's about time that someone told you the truth-- MS had a full hand--
the worlds most popular programming language; and they FOLDED. THEY
GAVE UP AND KILLED THE LANGUAGE; BECAUSE THE KIDS IN REDMOND WERE
SCARED OF A TINY COMPANY FROM CALIFORNIA WITH A THREE BILLION DOLLAR
MARKET CAP.
C++ is dead.
Java is dead.
VB is dead.

PHP won the war.
I'm dead fucking serious
-Todos

On Mar 14, 2:13 am, banle...@gmail.com wrote:
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

Mar 15 '07 #7
banleong wrote:
<snip>
Actually i already declare the external function as

<DllImport("bbappapi.dll")_
Public Shared Function BBCameraPreviewStart(ByVal HBBCamera As
<snip>

I suggest you try to provide a more complete description of your
scenario. Having known that you had already declared the function with
DllImport would spare a couple a posts, don't you think? Also, in your
first post you say that you get an error message while calling the
function, but don't provide it for lack of relevancy in the message.
Well, maybe the message *is irrelevant*, but then, again, maybe not
(the "DllImport" wasn't irrelevant at all, you see?).

Also missing is an example of the original C++ code filling the
paramenters (sometimes thare's a gotcha that passes unnoticed).

Finally -- to give some purpose to this post -- I noticed that the
fields you show in the C++ declaration of the BBCameraParameter struct
don't seem to match your usage of the parameter. It would help also if
you provided your actual VB declaration of the struct.

HTH.

Branco.

Mar 15 '07 #8
HBBCAMERA is a typedef pointer, so you'll have to pass the first parameter
ByRef. If that doesn't work, try changing the IntPtr to an UInt32

Public Shared Function BBCameraPreviewStart(ByRef HBBCamera As IntPtr,
ByRef BBParam1 As BBCameraParameter) As Integer
End Function

or

Dim HBBCamera as Unit32

Public Shared Function BBCameraPreviewStart(ByRef HBBCamera As UInt32,
ByRef BBParam1 As BBCameraParameter) As Integer
End Function

<ba******@gmail.comwrote in message
news:11**********************@e1g2000hsg.googlegro ups.com...
On Mar 15, 1:17 pm, "Branco Medeiros" <branco.medei...@gmail.com>
wrote:
>banleong wrote:

<snip>Yes, it is external libraries.
<snip>
1) Is my declaration correct for BBCameraPreviewStart in VB.net code
based on the C++ codes?
BBAPI DWORD WINAPI BBCameraPreviewStart(HBBCAMERA,
BBCameraParameter*);
to
Public Shared Function BBCameraPreviewStart(ByVal HBBCamera As IntPtr,
ByRef BBParam1 As BBCameraParameter) As Integer
End Function

<snip>

Nope. When you have to reference a method in an external library, you
need to indicate to VB which library is this (the .dll file), the
character type accepted by the method (ansi or unicode) and the method
signature, among other things.

Usually this is done using a Declare. Suppose, for instance, that the
method that you want to call is from, say, a dll called BBAPI.dll.
This would be the declaration of the function in VB:

Declare Ansi Function BBCameraPreviewStart _
Lib "BBAPI.dll" ( _
ByVal HBBCamera As IntPtr,
ByRef BBParam1 As BBCameraParameter) As Integer

Of course, this is just the declaration. To actually *call* the
method, it's no different from any other methods.

HTH.

Regards,

Branco.

Branco,

Thanks for your reply.

Actually i already declare the external function as

<DllImport("bbappapi.dll")_
Public Shared Function BBCameraPreviewStart(ByVal HBBCamera As
IntPtr, ByRef BBParam1 As BBCameraParameter) As Integer
End Function

Sorry for the confusion because i didn't include the <DllImportpart
on early post.
However, passing the parameters seem to failed.Guess have not choice
but go back to manufacturer, eh?

Regards

Mar 15 '07 #9
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
*/
#define WM_BBCAMERA_UPDATE_FPS WM_USER+1000

#define BB_CAMERA_CODE_SUCCESS 0
#define BB_CAMERA_CODE_ERR_UNKNOWN 1
#define BB_CAMERA_CODE_ERR_INVALID_HANDLE 2
#define BB_CAMERA_CODE_ERR_INVALID_PARAMETER 3

typedef enum
{
wb_auto = 0,
wb_cloudy,
wb_daylight,
wb_fluorescent_1,
wb_fluorescent_2,
wb_light_bulb

} white_balance_mode;

typedef enum
{
effect_none = 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 = 1,
flip_y,
flip_x_y,
flip_origin
} flip_mode;

typedef enum
{
rate_auto = 1,
rate_day_manual,
rate_night_manual
} frame_rate_mode;

typedef enum
{
auto_save = 0,
manual_save
} save_mode;

typedef enum
{
file_type_jpg = 0,
file_type_bmp
} save_image_type;

typedef enum
{
rotate_default=0,
rotate_0,
rotate_90,
rotate_180,
rotate_270

} rotation_degree;

typedef enum
{
pixel_format_ycbcr = 0,
pixel_format_rgb_565, // output data °¡ bmp ÀÌ´Ù.
pixel_format_rgb_565_raw // output data °¡ 16bit rgb µ¥ÀÌÅÍ ÀÌ´Ù.

} 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¿¡¼* µ¥ÀÌÅ͸¦ ¹Þ
±âÀ§ÇÑ Æ÷ÀÎÅÍ

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------------
#Region " BB CAMERA API DECLARATIONS "
Public Const BB_CAMERA_CODE_SUCCESS = 0
Public Const BB_CAMERA_CODE_ERR_UNKNOWN = 1
Public Const BB_CAMERA_CODE_ERR_INVALID_HANDLE = 2
Public Const BB_CAMERA_CODE_ERR_INVALID_PARAMETER = 3

Enum white_balance_mode
wb_auto = 0
wb_cloudy
wb_daylight
wb_fluorescent_1
wb_fluorescent_2
wb_light_bulb
End Enum

Enum effect_mode
effect_none = 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 = 1
flip_y
flip_x_y
flip_origin
End Enum

Enum frame_rate_mode
rate_auto = 1
rate_day_manual
rate_night_manual
End Enum

Enum save_mode
auto_save = 0
manual_save
End Enum

Enum save_image_type
file_type_jpg = 0
file_type_bmp
End Enum

Enum rotation_degree
rotate_default = 0
rotate_0
rotate_90
rotate_180
rotate_270
End Enum

Enum pixel_format_select
pixel_format_ycbcr = 0
pixel_format_rgb_565 ' // output data °¡ bmp ÀÌ´Ù.
pixel_format_rgb_565_raw ' // output data °¡ 16bit rgb µ¥ÀÌÅÍ
ÀÌ´Ù.
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
#End Region

#Region " VARIABLES DECLARATION "
Dim HBBCAMERA As IntPtr
Dim BBInfo As New BBCameraInfo
Dim BBParam As New BBCameraParameter

#End Region

#Region " BB CAMERA API"
<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
#End Region
' So this is the method that i call to
'
Private Sub StartOperation()

Dim BBParam As BBCameraParameter
Dim StartCamera as boolean

Try
HBBCAMERA = BBCameraOpen(picCamera.Handle) 'Get the
handler
StartCamera = True
Catch ex As Exception
StartCamera = False
End Try

If StartCamera Then
' If camera started then assign some parameters
With BBParam
.preview_width = 0
.preview_height = 100
.preview_format = 0
.ImageQuality = 5
.brightness = 50
.rotation = rotation_degree.rotate_0
.preview_x = 0
.preview_y = 0
.contrast = 200
.saturation = 200
.ef_mode = effect_mode.effect_none
.wb_mode = white_balance_mode.wb_auto
Dim pbuffer() As Byte
ReDim pbuffer(.preview_width * .preview_height * 2)
ReDim .reserved(20)
.p_app_buffer = pbuffer
.p_app_capture_buffer = pbuffer
End With
TextBox1.Text = "Get handle :" & HBBCAMERA.ToString

'GET CAMERA INFO (No problem here, can get the info from
camera)
BBCameraGetInfo(HBBCAMERA, BBInfo)
TextBox1.Text += vbCrLf & "BBInfo.image_max_height:" &
BBInfo.image_max_height
TextBox1.Text += vbCrLf & "BBInfo.image_max_width:" &
BBInfo.image_max_width
TextBox1.Text += vbCrLf & "BBInfo.preview_max_height:" &
BBInfo.preview_max_height
TextBox1.Text += vbCrLf & "BBInfo.preview_max_width:" &
BBInfo.preview_max_width
TextBox1.Text += vbCrLf & "BBInfo.preview_min_width:" &
BBInfo.preview_min_width

Try
'Preview camera image (ERROR OCCURS HERE)
Dim rst As Integer = BBCameraPreviewStart(HBBCAMERA,
BBParam)
TextBox1.Text += vbCrLf & "Preview OK"

Catch ex As Exception
TextBox1.Text += vbCrLf & "Preview Failed"

End Try

Else
TextBox1.Text += vbCrLf & "Cannot start camera"
End If
End Sub
----------------------------- 'END OF VB.Net
Codes---------------------

Hope to hear from you guys.

Thanks again!

Mar 16 '07 #10
banleong wrote:
<snipped due to sheer size>

Yikes, it seems Google groups didn't like my post. Here it goes again
(sorry if it gets duplicated...)

Yes, there were issues with you conversion of the structures: missing,
wrongly typed and out-of-order fields, as well as missing marshalling
information. This may be causing your code to fail.

Try the rewrites below, I hope they're somewhat more "correct" than
the ones you already have.

<code>
'At file level
Imports InterOp = System.Runtime.InteropServices

'Inside your class
Public Const RESERVED_FIELD_MAX As integer = 19

<InterOp.StructLayout( _
InterOp.LayoutKind.Sequential, _
Charset:=InterOp.CharSet.Ansi)_
Structure BBCameraParameter
Public preview_width As UInteger
Public preview_height As UInteger
Public preview_x As UInteger
Public preview_y As UInteger
Public preview_format As UInteger
Public preview_zoom As UInteger
<InterOp.MarshalAs(InterOp.UnmanagedType.LPStr)_
Public capture_file_name As String

Public capture_width As UInteger
Public capture_height As UInteger
Public capture_format As pixel_format_select
Public capture_strobe_on As UInteger
Public contrast As UInteger
Public saturation As UInteger
Public brightness As UInteger
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

'Must initialize explicitly
<VBFixedArray(RESERVED_FIELD_MAX)_
Public reserved() As UInteger

<InterOp.MarshalAs(InterOp.UnmanagedType.LPArray )_
Public p_app_buffer() As Byte
<InterOp.MarshalAs(InterOp.UnmanagedType.LPArray )_
Public p_app_capture_buffer() As Byte
Public stillimage_savemode As save_mode
Public save_fileType As save_image_type
Public ImageQuality As UInteger

Public isSaveFile As Boolean
Public rotation_degree As rotation_degree

End Structure

<InterOp.StructLayout(InterOp.LayoutKind.Sequentia l)_
Structure BBCameraInfo
Public preview_max_width As UInteger
Public preview_max_height As UInteger
Public preview_min_width As UInteger
Public preview_min_height As UInteger
Public image_max_width As UInteger
Public image_max_height As UInteger

'Must initialize explicitly
<VBFixedArray(RESERVED_FIELD_MAX)_
Public reserved() As UInteger
End Structure

<InterOp.DllImport("bbappapi.dll", Charset:=InterOp.CharSet.Ansi)_
Public Shared Function BBCameraPreviewStart( _
ByVal HBBCamera As IntPtr, _
ByRef BBParam1 As BBCameraParameter) As Integer
End Function
</code>

Just remember that when declaring instances of both BBCameraParamete
and BBCamera info you need to explicitly dimmension the reserverd
field:

Dim Param As New BBCameraParameter
ReDim Param.reserved(RESERVED_FIELD_MAX)

Dim Info As New BBCameraInfo
ReDim Info.reserved(RESERVED_FIELD_MAX)
HTH.

Regards,

Branco.

Mar 16 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
37
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
2
by: sushil | last post by:
+1 #include<stdio.h> +2 #include <stdlib.h> +3 typedef struct +4 { +5 unsigned int PID; +6 unsigned int CID; +7 } T_ID; +8 +9 typedef unsigned int (*T_HANDLER)(void); +10
27
by: Marlene Stebbins | last post by:
I am experimenting with function pointers. Unfortunately, my C book has nothing on function pointers as function parameters. I want to pass a pointer to ff() to f() with the result that f() prints...
23
by: bluejack | last post by:
Ahoy... before I go off scouring particular platforms for specialized answers, I thought I would see if there is a portable C answer to this question: I want a function pointer that, when...
3
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules'...
54
by: John | last post by:
Is the following program print the address of the function? void hello() { printf("hello\n"); } void main() { printf("hello function=%d\n", hello); }
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
20
by: MikeC | last post by:
Folks, I've been playing with C programs for 25 years (not professionally - self-taught), and although I've used function pointers before, I've never got my head around them enough to be able to...
10
by: Richard Heathfield | last post by:
Stephen Sprunk said: <snip> Almost. A function name *is* a pointer-to-function. You can do two things with it - copy it (assign its value to an object of function pointer type, with a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.