PDA

View Full Version : [VB.NET] Utilizzo webcam su windows 7/8 x64


ryan79
09-05-2013, 18:53
Ciao a tutti!

Ho seguito questo tutorial (http://lobsterproductions.weebly.com/webcam-picture-tool.html)per acquisire immagini da webcam. Ho trovato però un problema. Una volta avviato mi viene mostrato questo messaggio:

L'assistente al debug gestito 'PInvokeStackImbalance' ha rilevato un problema in 'C:\ImageScanner\ImageScanner\bin\Debug\ImageScanner.vshost.exe'.

Informazioni aggiuntive: Una chiamata alla funzione PInvoke 'ImageScanner!ImageScanner.Form1::SendMessage' ha sbilanciato lo stack. Questo problema può verificarsi quando la firma PInvoke gestita non corrisponde alla firma di destinazione non gestita. Verificare che la convenzione di chiamata e i parametri della firma PInvoke corrispondano alla firma di destinazione non gestita.

Cercando un po' in Google ho trovato che la motivazione più ricorrente per spiegare l'errore sarebbe il tipo di architettura del sistema in uso (x64).
Ho provato a sostituire:

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Object) As Integer

con

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

e il pezzo di codice della sub OpenPreviewWindow()

If SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) Then
SendMessage(hHwnd, WM_CAP_SET_SCALE, True, 0)
SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0)
SendMessage(hHwnd, WM_CAP_SET_PREVIEW, True, 0)

con

If SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, CShort(iDevice), CType(0, String)) = 1 Then
SendMessage(hHwnd, WM_CAP_SET_SCALE, True, CType(0, String))
SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, CType(0, String))
SendMessage(hHwnd, WM_CAP_SET_PREVIEW, True, CType(0, String))

Ma non funziona comunque.

Qualcuno ha qualche consiglio da darmi? Grazie.