Hi, all,
I am trying to make a datamatrix decoding program for a usb webcam. I am using the Datamatrix.net 0.4.4 dll (in C#). This dll has the following exported function:
I just don't know how to pass the HBITMAP or a BITMAP to the .net dll.
namespace DataMatrix.net
{
[ComVisible(true)]
public class DmtxImageDecoder
{
/// <summary>
/// returns a list of all decoded DataMatrix codes in the image provided
/// </summary>
public List<string> DecodeImage(Bitmap image)
{
return DecodeImage(image, int.MaxValue, TimeSpan.MaxValue);
}
In Autoitv3 i used Dot-NET_AutoIt.au3, and loaded the dll without errors. Then I use _ScreenCapture_CaptureWnd to capture the Handle of the Webcam image window, which also works.
But when I try to call the dll DecodeImage function, AutoIt crashes:
;(...) Load of .net dll - works
;(...)
Func Snapper()
Local $hBMP, $hBitmap, $hGraphic, ReturnS
$hBMP = _ScreenCapture_CaptureWnd("", $hGUI, 0, 0, -1, -1, False); we take a picture of the gui with the video stream
; The Following works: (just for testing purposes)
_WinAPI_SaveHBITMAPToFile("Test2.bmp",$hBMP)
;now create Bitmap from HBITMAP:
$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
; Now Call to the dll, which crashes:
$ReturnS = $oPerson.DecodeImage($hBitmap)
;(...)
I also tried to pass a HBITMAP:
/// <summary>
/// returns a list of all decoded DataMatrix codes in the image provided
/// </summary>
public String DecodeImage4(IntPtr HbitmapHandle)
{
Bitmap bild = Bitmap.FromHbitmap(hbitmapHandle);
String ReturnS;
List<string> ListS;
ListS = DecodeImage(bild, int.MaxValue, TimeSpan.MaxValue);
//Return only the first Datamatrix
ReturnS = ListS[0];
return ReturnS;
}
Like This:
;(...) Load of .net dll - works
;(...)
Func Snapper()
Local $hBMP, $hBitmap, $hGraphic, ReturnS
$hBMP = _ScreenCapture_CaptureWnd("", $hGUI, 0, 0, -1, -1, False); we take a picture of the gui with the video stream
; The Following works:
_WinAPI_SaveHBITMAPToFile("Test2.bmp",$hBMP)
; Now Call to the dll, which crashes:
$ReturnS = $oPerson.DecodeImage($hBMP)
;(...)
Always the same error message:
==> The requested action with this object has failed.:
$ReturnS = $oPerson.DecodeImage($hBMP)
$ReturnS = $oPerson^ ERROR
I tried to call another function in the dll, which worked ok.
I just don't know how to pass the HBITMAP or a BITMAP to the .net dll.
Any idea anyone? Thank you