PC Review Forums Newsgroups Microsoft DotNet Microsoft VB .NET C++ Function Pointer to VB.Net

Reply

C++ Function Pointer to VB.Net

 
Thread Tools Rate Thread
Old 14-03-2007, 09:13 AM   #1
banleong@gmail.com
Guest
 
Posts: n/a
Default 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

  Reply With Quote
Old 14-03-2007, 06:16 PM   #2
Branco Medeiros
Guest
 
Posts: n/a
Default Re: C++ Function Pointer to VB.Net

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.

  Reply With Quote
Old 14-03-2007, 08:57 PM   #3
lord.zoltar@gmail.com
Guest
 
Posts: n/a
Default Re: C++ Function Pointer to VB.Net

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?

  Reply With Quote
Old 15-03-2007, 01:24 AM   #4
banleong@gmail.com
Guest
 
Posts: n/a
Default Re: C++ Function Pointer to VB.Net

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

  Reply With Quote
Old 15-03-2007, 05:17 AM   #5
Branco Medeiros
Guest
 
Posts: n/a
Default Re: C++ Function Pointer to VB.Net

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.

  Reply With Quote
Old 15-03-2007, 07:02 AM   #6
banleong@gmail.com
Guest
 
Posts: n/a
Default Re: C++ Function Pointer to VB.Net

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 <DllImport> part
on early post.
However, passing the parameters seem to failed.Guess have not choice
but go back to manufacturer, eh?

Regards

  Reply With Quote
Old 15-03-2007, 08:00 AM   #7
susiedba@hotmail.com
Guest
 
Posts: n/a
Default Re: C++ Function Pointer to VB.Net

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 ****ing 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



  Reply With Quote
Old 15-03-2007, 03:05 PM   #8
Branco Medeiros
Guest
 
Posts: n/a
Default Re: C++ Function Pointer to VB.Net

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.

  Reply With Quote
Old 15-03-2007, 03:24 PM   #9
Mudhead
Guest
 
Posts: n/a
Default Re: C++ Function Pointer to VB.Net

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



<banleong@gmail.com> wrote in message
news:1173942127.379021.128630@e1g2000hsg.googlegroups.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 <DllImport> part
> on early post.
> However, passing the parameters seem to failed.Guess have not choice
> but go back to manufacturer, eh?
>
> Regards
>



  Reply With Quote
Old 16-03-2007, 04:05 AM   #10
banleong@gmail.com
Guest
 
Posts: n/a
Default Re: C++ Function Pointer to VB.Net

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!

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

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

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