Funtions Aufruf in C# DLL

  • Moin,

    ich versuche verzweifelt einige Funktionen in einer C# DLL aufzurufen. Leider geht das völlig schief.

    Grundsetzlich geht es um die Erstellung von Barcode images.

    http://www.codeproject.com/KB/macros/Barc…spx?msg=2561828

    Hierzu muss in der barcodelib.dll die Funktion

    public Image Encode(TYPE iType, string StringToEncode, int Width, int Height)

    aufgerufen werden.

    Zum Speichern des Bildes gibt es dann noch

    public void SaveImage(string Filename, SaveTypes FileType).

    Mit C++ ist das alles kein Problem aber in AutoIT finde ich einfach keine Möglichkeit. Ich denke es gibt sie aber.... Hinzu kommt noch die Deklaration der Variabeln image und iType.

    Die Frage ist nun. Kennt jemand ein Tutorial zum Thema AutoIT / C# oder maybe sogar die Lösung dieser Problemstellung?


    Danke

    megaflops ?(

  • C# ist .NET, das geht doch mit AutoIT nicht zum Ansprechen oder irre ich mich?
    Welchen Barcode-Typ willst du denn?

  • @mega

    Danke für den Link. Dort sind ein paar spannende BC Lösungen zu finden.....ich werde die mal testen.

    @progandy

    .Net geht nicht...sehr schade! Ich brauche derzeit Code128 und 2of5.


    Danke

    megaflops

  • Hab mal I2of5 und 2of5 nach AutoIt umgesetzt:

    Spoiler anzeigen
    [autoit]

    Infos von http://www.codeproject.com/KB/cpp/includeh10.aspx
    und http://www.spatula.net/proc/barcode/code25.src
    #include <Array.au3>
    #include <Misc.au3>
    #include <Winapi.au3>
    #include <WindowsConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstants.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    #include <ComboConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 633, 448, 193, 125)
    $Label1 = GUICtrlCreateLabel("Barcode", 16, 8, 44, 17)
    $in = GUICtrlCreateInput("0123456789", 80, 8, 249, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER))

    [/autoit] [autoit][/autoit] [autoit]

    $Ratio = GUICtrlCreateInput("4", 80, 40, 113, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER))
    $PenWidth = GUICtrlCreateInput("1", 80, 80, 113, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER))
    $barColor = GUICtrlCreateInput("0", 80, 120, 249, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER))
    $spaceColor = GUICtrlCreateInput("0x00FFFFFF", 80, 152, 249, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER))
    $comCode = GUICtrlCreateCombo("2of5", 368, 64, 209, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
    GUICtrlSetData(-1,"I2of5")

    [/autoit] [autoit][/autoit] [autoit]

    $Label = GUICtrlCreateLabel("", 24, 240, 588, 177)
    $Label2 = GUICtrlCreateLabel("Ratio", 16, 40, 29, 17)
    $Label3 = GUICtrlCreateLabel("PenWidth", 16, 80, 51, 17)
    $Label4 = GUICtrlCreateLabel("BarColor", 16, 120, 44, 17)
    $Label5 = GUICtrlCreateLabel("SpaceColor", 16, 152, 59, 17)
    $Label6 = GUICtrlCreateLabel("CodeGen:", 384, 40, 52, 17)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    $hwnd = GUICtrlGetHandle($Label)
    $hDC = _WinAPI_GetDC($hwnd)
    Global $Array, $savedin
    AdlibEnable("Draw",100)

    [/autoit] [autoit][/autoit] [autoit]

    #region - GUI SelectLoop
    While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
    _WinAPI_ReleaseDC($hwnd,$hDC)
    Exit
    Case $msg >= $Ratio And $msg <= $comCode
    $savedin = ""
    EndSelect
    WEnd
    #endregion

    [/autoit] [autoit][/autoit] [autoit]

    Func DRAW()
    If $savedin == GUICtrlRead($in) Then Return
    $savedin = GUICtrlRead($in)
    ;~ $Array = EncodeI2of5($savedin)
    Switch GUICtrlRead($comCode)
    Case "2of5"
    $Array = _Encode2of5($savedin)
    Case "I2of5"
    $Array = EncodeI2of5($savedin)
    EndSwitch
    If IsArray($Array) Then
    _WinAPI_RedrawWindow($hwnd,0,0,$RDW_INVALIDATE+$RDW_UPDATENOW)
    _Barcode2DC($hDC,0,0,100,100,$Array,Execute(GUICtrlRead($barColor)),Execute(GUICtrlRead($SpaceColor)),GUICtrlRead($PenWidth),GUICtrlRead($Ratio))
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _Barcode2DC($hDC,$iX,$iY0,$iY10,$iY11,ByRef $pb,$ColorBar=0,$ColoeSpace=0x00FFFFFF,$iPenW=1,$i_Ratio=2)
    $hPenBar =DllCall("gdi32.dll","long","CreatePen","int",0,"int",$iPenW,"long",$ColorBar);::CreatePen(PS_SOLID,iPenW,clrBar);
    $hPenBar = $hPenBar[0]
    $hPenSpace =DllCall("gdi32.dll","long","CreatePen","int",0,"int",$iPenW,"long",$ColoeSpace);CreatePen(PS_SOLID,iPenW,clrSpace);
    $hPenSpace = $hPenSpace[0]
    $hPenOld=_WINAPI_SelectObject($hDC,$hPenBar);

    [/autoit] [autoit][/autoit] [autoit]

    ;~ BYTE*pb=ia_Buf;
    Local $i0,$iNum0 = UBound($pb)-1;i_LenBuf;

    Local $bBar;
    Local $i1,$iNum1;
    Local $iY;
    for $i0=1 To $iNum0 ;i0<iNum0;i0++)

    $bBar =BitAND($pb[$i0],0x01);
    $iNum1 =_Iif(BitAND($pb[$i0],0x02),$i_Ratio,1);
    $iY =_Iif(BitAND($pb[$i0],0x04),$iY11,$iY10);
    for $i1=1 To $iNum1 ;i1<iNum1;i1++)

    if ($bBar) Then
    _WinAPI_SelectObject($hDC,$hPenBar);::SelectObject(hDC,hPenBar);
    else
    _WinAPI_SelectObject($hDC,$hPenSpace);::SelectObject(hDC,hPenSpace);
    EndIf
    DllCall("gdi32.dll","int","MoveToEx","long",$hDC,"int",$iX,"int",$iY0,"int",0)
    DllCall("gdi32.dll","int","LineTo","long",$hDC,"int",$iX,"int",$iY)
    ;~ ::MoveToEx(hDC,iX,iY0,0);
    ;~ ::LineTo(hDC,iX,iY);
    $iX+=$iPenW;
    Next
    ;~ pb++;
    Next
    ;~ ::SelectObject(hDC,hPenOld);
    _WinAPI_SelectObject($hDC,$hPenOld)
    _WinAPI_DeleteObject($hPenBar)
    _WinAPI_DeleteObject($hPenSpace)
    ;~ ::DeleteObject(hPenBar);
    ;~ ::DeleteObject(hPenSpace);
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _Encode2of5($String)
    Dim $pb[7] = ["",3,0,3,0,1,0]
    For $i = 1 To StringLen($String)
    _2of5Code($pb,StringMid($String,$i,1))
    Next
    $bound = UBound($pb)
    ReDim $pb[$bound+5]
    $pb[$bound] = 3
    $pb[$bound+1] = 0
    $pb[$bound+2] = 1
    $pb[$bound+3] = 0
    $pb[$bound+4] = 3
    Return $pb
    EndFunc
    Func _2of5Code(ByRef $pb,$ch)
    Local $infs[10]= ["NNWWN","WNNNW","NWNNW","WWNNN","NNWNW","WNWNN","NWWNN","NNNWW","WNNWN","NWNWN"]
    ;START: WWN
    If $ch < 0 Or $ch > 9 Then Return 0
    For $i = 1 To 5
    $ppb = UBound($pb)
    ReDim $pb[UBound($pb)+2]
    If StringMid($infs[$ch],$i,1) == "N" Then
    $pb[$ppb] = 1
    $pb[$ppb+1] = 0
    Else
    $pb[$ppb] = 3
    $pb[$ppb+1] = 0
    EndIf
    Next
    ;STOP: WNW
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;~ EncodeI2of5(const char*pszCode)
    Func EncodeI2of5($pszCode)
    ;~ Clear();
    If Not StringIsDigit($pszCode) Or $pszCode == "" Then Return 0
    Local $pb[1]
    ;~ BYTE*pFst=ia_Buf;
    ;~ BYTE*pb=pFst;

    [/autoit] [autoit][/autoit] [autoit]

    Local $iNum=stringlen($pszCode);
    If Mod($iNum,2) <> 0 Then
    $pszCode = "0" & $pszCode
    $iNum = StringLen($pszCode)
    EndIf

    Local $i
    ;~ //"nnnn"
    for $i=0 To 3;i<4;i++)
    $ppb = UBound($pb)
    ReDim $pb[UBound($pb)+1]
    $pb[$ppb] = 0
    if(Mod($i,2) =0) Then $pb[$ppb]+=1;
    ;~ pb++;
    Next

    [/autoit] [autoit][/autoit] [autoit]

    Local $iV;
    for $i=1 To $iNum Step 2;i<iNum;i+=2)

    $iV = StringMid($pszCode,$i,2)
    $x = P_GetNarrorWideBarSpaceI2of5($pb,$iV);
    If $x = 0 Then Return 0
    ;~ pb=P_GetNarrorWideBarSpaceI2of5(pb,iV);
    ;~ if(pb==0) return 0;
    Next

    [/autoit] [autoit][/autoit] [autoit]

    ;~ //"wnn"
    $ppb = UBound($pb)
    ReDim $pb[UBound($pb)+1]
    $pb[$ppb] += 3
    ;~ *pb+=3; pb++;
    ;~ *pb+=0; pb++;
    ;~ *pb+=1; pb++;
    $ppb = UBound($pb)
    ReDim $pb[UBound($pb)+1]
    $pb[$ppb] += 0
    $ppb = UBound($pb)
    ReDim $pb[UBound($pb)+1]
    $pb[$ppb] += 1

    [/autoit] [autoit][/autoit] [autoit]

    ;~ i_LenBuf=pb-pFst;
    return $pb
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func P_GetNarrorWideBarSpaceI2of5(ByRef $pb,$ch)

    if($ch<0) Then return 0;
    if($ch>99) Then return 0;

    [/autoit] [autoit][/autoit] [autoit]

    Local $infs[100][2] = _
    [ _
    [0, "nnnnwwwwnn"], _
    [1, "nwnnwnwnnw"], _
    [2, "nnnwwnwnnw"], _
    [3, "nwnwwnwnnn"], _
    [4, "nnnnwwwnnw"], _
    [5, "nwnnwwwnnn"], _
    [6, "nnnwwwwnnn"], _
    [7, "nnnnwnwwnw"], _
    [8, "nwnnwnwwnn"], _
    [9, "nnnwwnwwnn"], _
    [10, "wnnnnwnwwn"], _
    [11, "wwnnnnnnww"], _
    [12, "wnnwnnnnww"], _
    [13, "wwnwnnnnwn"], _
    [14, "wnnnnwnnww"], _
    [15, "wwnnnwnnwn"], _
    [16, "wnnwnwnnwn"], _
    [17, "wnnnnnnwww"], _
    [18, "wwnnnnnwwn"], _
    [19, "wnnwnnnwwn"], _
    [20, "nnwnnwnwwn"], _
    [21, "nwwnnnnnww"], _
    [22, "nnwwnnnnww"], _
    [23, "nwwwnnnnwn"], _
    [24, "nnwnnwnnww"], _
    [25, "nwwnnwnnwn"], _
    [26, "nnwwnwnnwn"], _
    [27, "nnwnnnnwww"], _
    [28, "nwwnnnnwwn"], _
    [29, "nnwwnnnwwn"], _
    [30, "wnwnnwnwnn"], _
    [31, "wwwnnnnnnw"], _
    [32, "wnwwnnnnnw"], _
    [33, "wwwwnnnnnn"], _
    [34, "wnwnnwnnnw"], _
    [35, "wwwnnwnnnn"], _
    [36, "wnwwnwnnnn"], _
    [37, "wnwnnnnwnw"], _
    [38, "wwwnnnnwnn"], _
    [39, "wnwwnnnwnn"], _
    [40, "nnnnwwnwwn"], _
    [41, "nwnnwnnnww"], _
    [42, "nnnwwnnnww"], _
    [43, "nwnwwnnnwn"], _
    [44, "nnnnwwnnww"], _
    [45, "nwnnwwnnwn"], _
    [46, "nnnwwwnnwn"], _
    [47, "nnnnwnnwww"], _
    [48, "nwnnwnnwwn"], _
    [49, "nnnwwnnwwn"], _
    [50, "wnnnwwnwnn"], _
    [51, "wwnnwnnnnw"], _
    [52, "wnnwwnnnnw"], _
    [53, "wwnwwnnnnn"], _
    [54, "wnnnwwnnnw"], _
    [55, "wwnnwwnnnn"], _
    [56, "wnnwwwnnnn"], _
    [57, "wnnnwnnwnw"], _
    [58, "wwnnwnnwnn"], _
    [59, "wnnwwnnwnn"], _
    [60, "nnwnwwnwnn"], _
    [61, "nwwnwnnnnw"], _
    [62, "nnwwwnnnnw"], _
    [63, "nwwwwnnnnn"], _
    [64, "nnwnwwnnnw"], _
    [65, "nwwnwwnnnn"], _
    [66, "nnwwwwnnnn"], _
    [67, "nnwnwnnwnw"], _
    [68, "nwwnwnnwnn"], _
    [69, "nnwwwnnwnn"], _
    [70, "nnnnnwwwwn"], _
    [71, "nwnnnnwnww"], _
    [72, "nnnwnnwnww"], _
    [73, "nwnwnnwnwn"], _
    [74, "nnnnnwwnww"], _
    [75, "nwnnnwwnwn"], _
    [76, "nnnwnwwnwn"], _
    [77, "nnnnnnwwww"], _
    [78, "nwnnnnwwwn"], _
    [79, "nnnwnnwwwn"], _
    [80, "wnnnnwwwnn"], _
    [81, "wwnnnnwnnw"], _
    [82, "wnnwnnwnnw"], _
    [83, "wwnwnnwnnn"], _
    [84, "wnnnnwwnnw"], _
    [85, "wwnnnwwnnn"], _
    [86, "wnnwnwwnnn"], _
    [87, "wnnnnnwwnw"], _
    [88, "wwnnnnwwnn"], _
    [89, "wnnwnnwwnn"], _
    [90, "nnwnnwwwnn"], _
    [91, "nwwnnnwnnw"], _
    [92, "nnwwnnwnnw"], _
    [93, "nwwwnnwnnn"], _
    [94, "nnwnnwwnnw"], _
    [95, "nwwnnwwnnn"], _
    [96, "nnwwnwwnnn"], _
    [97, "nnwnnnwwnw"], _
    [98, "nwwnnnwwnn"], _
    [99, "nnwwnnwwnn"] _
    ]

    [/autoit] [autoit][/autoit] [autoit]

    Local $i;
    for $i=1 To 10;i<10;i++)
    $ppb = UBound($pb)
    ReDim $pb[UBound($pb)+1]
    $pb[$ppb] = 0
    if(StringMid($infs[$ch][1],$i,1)=='w') Then $pb[$ppb]+=2;
    if(Mod($i-1,2) =0) Then $pb[$ppb]+=1;
    Next
    ;~ ReDim $pb[UBound($pb)+2]
    ;~ return $pb;
    Return 1
    EndFunc

    [/autoit]


    //Edit: bacode128 gibt es jetzt hier: http://www.autoitscript.com/forum/index.php?showtopic=72081&hl=

    Einmal editiert, zuletzt von progandy (25. Mai 2008 um 16:33)

  • @progandy

    Danke für die tips und den Link. Ich habe inzwischen festgestellt, dass die Qualität des BC so nicht ausreicht. Durch hinweise hier im Forum habe ich einen postscript code gefunden, der sehr gut aussieht. Sobald ich das umgesetzt habe werde ich es posten.

    Eventuell werden sich meine Fragen nun mehr um ImageMagick, GS, PS drehen....