Delphi ile yazılmış bir DLL var. Bunun içerisindeki fonksiyonu visualstudio projesinde çalıştırmak istiyorum. Ancak VS bilgim çok az. Bunu nasıl yapabilirim.
demo yapmak üzere eklediğim dll içerisindeki fonksiyon DllMessage bir butona basınca bu fonksiyonu çağıran basit bir VB .net demoya ihtiyacım var. Hello world mesajı yazıcak. hepsi bu. Şimdiden teşekkür ederim.
DLL ektedir.
http://www.speedyshare.com/files/24449104/DLLkullan.zip
Hocam Yazdığınız DLL ye VS ulaşılamaz yada eklenemez diyor.
Bu bir activex nesnesi değil. Bildiğin DLL. tam terminolojisini bilmiyorum ama bunun .net ile doğrudan alakası yok. .Net olmasa da çalışabilen türden bir DLL. Ona göre muamele yapmamız gerek . Uygulama çalışınca kendisi import edecek. diye düşünüyorum. Görüldüğü gibi Delphi uygulaması o şekil çalışabiliyor. .Net ile de olur ama nasıl olur bilemedim.
Başka DLLimport projeleri buldum onlardan benzetmeye çalışıyorum.
Biri kendi DLLi için şöyle yapmış:
Imports System.Runtime.InteropServices
Imports System.Threading
Imports System.ComponentModel
Imports System.Data
Imports System.Windows.Forms
Imports Microsoft.Win32
Imports System.io
Public Class Form1
Inherits System.Windows.Forms.Form
#Region "Variables"
Private nBarcodeType As Integer
Private nThreshold As Integer
Private bDiskFile As Boolean
Private nImgFormat As Integer
Private nPageOption As Integer
Private nRLeft As Integer
Private nRTop As Integer
Private nRRight As Integer
Private nRBottom As Integer
Private nImgWidth As Integer
Private nImgHeight As Integer
#End Region
#Region "DLL Imports"
<DllImport("kernel32.dll", SetlastError:=True)> Private Shared Function LoadLibrary(ByVal LibFileName As String) As Integer
End Function
<DllImport("Decode2D.dll", SetlastError:=True)> Private Shared Function De2DInit() As Integer
End Function
<DllImport("Decode2D.dll", SetlastError:=True)> Private Shared Function De2DSetKey(ByVal Key As String) As Integer
End Function
<DllImport("Decode2D.dll", SetlastError:=True)> Private Shared Function De2DCleanUp() As Integer
End Function
<DllImport("Decode2D.dll", SetlastError:=True)> Private Shared Function De2DFreeMem() As Integer
End Function
<DllImport("Decode2D.dll", SetlastError:=True)> Private Shared Function De2DGetCount() As Integer
End Function
<DllImport("Decode2D.dll", SetlastError:=True)> Private Shared Function De2DGetStrLen(ByVal CodeIndex As Integer) As Integer
End Function
<DllImport("Decode2D.dll", SetlastError:=True)> Private Shared Function De2DGetCharAt(ByVal CodeIndex As Integer, ByVal CharIndex As Integer) As Integer
End Function
<DllImport("Decode2D.dll", SetlastError:=True)> Private Shared Function De2DGetPDF417Param(ByVal CodeIndex As Integer, ByRef Rows As Integer, ByRef Columns As Integer, ByRef ECLevel As Integer, ByRef Truncated As Integer) As Integer
End Function
<DllImport("Decode2D.dll", SetlastError:=True)> Private Shared Function De2DGetDMParam(ByVal CodeIndex As Integer, ByRef Rows As Integer, ByRef Columns As Integer) As Integer
End Function
<DllImport("Decode2D.dll", SetlastError:=True)> Private Shared Function De2DGetQRCodeParam(ByVal CodeIndex As Integer, ByRef Rows As Integer, ByRef Columns As Integer, ByRef Version As Integer, ByRef Level As Integer, ByRef Mask As Integer) As Integer
End Function
<DllImport("Decode2D.dll", SetlastError:=True)> Private Shared Function De2DGetRect(ByVal CodeIndex As Integer, ByRef P1 As Long, ByRef P2 As Long, ByRef P3 As Long, ByRef P4 As Long) As Integer
End Function
<DllImport("Decode2D.dll", SetlastError:=True)> Private Shared Function De2DLoadFromMem(ByVal Buffer As Byte(), ByVal Size As Long, ByVal ImgFormat As Integer) As Integer
End Function
<DllImport("Decode2D.dll", SetlastError:=True)> Private Shared Function De2DLoadFromFile(ByVal FileName As String, ByVal ImgFormat As Integer) As Integer
End Function
<DllImport("Decode2D.dll", SetlastError:=True)> Private Shared Function De2DGetNumOfPages() As Integer
End Function
<DllImport("Decode2D.dll", SetlastError:=True)> Private Shared Function De2DSetPage(ByVal PageIndex As Integer) As Integer
End Function
<DllImport("Decode2D.dll", SetlastError:=True)> Private Shared Function De2DGetImgSize(ByRef Width As Integer, ByRef Height As Integer) As Integer
End Function
<DllImport("Decode2D.dll", SetlastError:=True)> Private Shared Function De2DSetThreshold(ByVal Threshold As Integer) As Integer
End Function
<DllImport("Decode2D.dll", SetlastError:=True)> Private Shared Function De2DSetRegion(ByVal Left As Integer, ByVal Top As Integer, ByVal Right As Integer, ByVal Bottom As Integer) As Integer
End Function
<DllImport("Decode2D.dll", SetlastError:=True)> Private Shared Function De2DScanType(ByVal CodeType As Integer, ByVal Enabled As Integer) As Integer
End Function
<DllImport("Decode2D.dll", SetlastError:=True)> Private Shared Function De2DScan() As Integer
End Function
#End Region
#Region "Windows Form Designer generated code"
Public Sub New()
MyBase.New()
Dim WinDir As String
Dim DLLPath As String
WinDir = System.Environment.GetEnvironmentVariable("WinDir")
DLLPath = WinDir & "\System32\Decode2D.dll"
LoadLibrary(DLLPath)
De2DInit()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
Friend WithEvents Label14 As System.Windows.Forms.Label
Friend WithEvents Label15 As System.Windows.Forms.Label
Friend WithEvents Label16 As System.Windows.Forms.Label
Friend WithEvents Label17 As System.Windows.Forms.Label
Friend WithEvents Label18 As System.Windows.Forms.Label
Friend WithEvents Label19 As System.Windows.Forms.Label
Friend WithEvents Label20 As System.Windows.Forms.Label
Friend WithEvents Label21 As System.Windows.Forms.Label
Friend WithEvents txtWidth As System.Windows.Forms.TextBox
Friend WithEvents txtHeight As System.Windows.Forms.TextBox
Friend WithEvents txtPages As System.Windows.Forms.TextBox
Friend WithEvents cbxPages As System.Windows.Forms.ComboBox
Friend WithEvents txtRLeft As System.Windows.Forms.TextBox
Friend WithEvents txtRTop As System.Windows.Forms.TextBox
Friend WithEvents txtRWidth As System.Windows.Forms.TextBox
Friend WithEvents txtRHeight As System.Windows.Forms.TextBox
Friend WithEvents txtBarcodeInfo As System.Windows.Forms.TextBox
Friend WithEvents btnImageInfo As System.Windows.Forms.Button
Friend WithEvents btnOpen As System.Windows.Forms.Button
Friend WithEvents btnScan As System.Windows.Forms.Button
Friend WithEvents btnClose As System.Windows.Forms.Button
Friend WithEvents OFD As System.Windows.Forms.OpenFileDialog
Friend WithEvents btnScanningOptions As System.Windows.Forms.Button
Friend WithEvents Label9 As System.Windows.Forms.Label
Friend WithEvents txtThreshold As System.Windows.Forms.TextBox
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents cbxBarcodeType As System.Windows.Forms.ComboBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.GroupBox2 = New System.Windows.Forms.GroupBox
Me.btnImageInfo = New System.Windows.Forms.Button
Me.txtRHeight = New System.Windows.Forms.TextBox
Me.txtRWidth = New System.Windows.Forms.TextBox
Me.txtRTop = New System.Windows.Forms.TextBox
Me.txtRLeft = New System.Windows.Forms.TextBox
Me.cbxPages = New System.Windows.Forms.ComboBox
Me.txtPages = New System.Windows.Forms.TextBox
Me.txtHeight = New System.Windows.Forms.TextBox
Me.txtWidth = New System.Windows.Forms.TextBox
Me.Label21 = New System.Windows.Forms.Label
Me.Label20 = New System.Windows.Forms.Label
Me.Label19 = New System.Windows.Forms.Label
Me.Label18 = New System.Windows.Forms.Label
Me.Label17 = New System.Windows.Forms.Label
Me.Label16 = New System.Windows.Forms.Label
Me.Label15 = New System.Windows.Forms.Label
Me.Label14 = New System.Windows.Forms.Label
Me.txtBarcodeInfo = New System.Windows.Forms.TextBox
Me.btnOpen = New System.Windows.Forms.Button
Me.btnScan = New System.Windows.Forms.Button
Me.btnClose = New System.Windows.Forms.Button
Me.OFD = New System.Windows.Forms.OpenFileDialog
Me.btnScanningOptions = New System.Windows.Forms.Button
Me.Label9 = New System.Windows.Forms.Label
Me.txtThreshold = New System.Windows.Forms.TextBox
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.cbxBarcodeType = New System.Windows.Forms.ComboBox
Me.Label1 = New System.Windows.Forms.Label
Me.GroupBox2.SuspendLayout()
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'GroupBox2
'
Me.GroupBox2.Controls.Add(Me.btnImageInfo)
Me.GroupBox2.Controls.Add(Me.txtRHeight)
Me.GroupBox2.Controls.Add(Me.txtRWidth)
Me.GroupBox2.Controls.Add(Me.txtRTop)
Me.GroupBox2.Controls.Add(Me.txtRLeft)
Me.GroupBox2.Controls.Add(Me.cbxPages)
Me.GroupBox2.Controls.Add(Me.txtPages)
Me.GroupBox2.Controls.Add(Me.txtHeight)
Me.GroupBox2.Controls.Add(Me.txtWidth)
Me.GroupBox2.Controls.Add(Me.Label21)
Me.GroupBox2.Controls.Add(Me.Label20)
Me.GroupBox2.Controls.Add(Me.Label19)
Me.GroupBox2.Controls.Add(Me.Label18)
Me.GroupBox2.Controls.Add(Me.Label17)
Me.GroupBox2.Controls.Add(Me.Label16)
Me.GroupBox2.Controls.Add(Me.Label15)
Me.GroupBox2.Controls.Add(Me.Label14)
Me.GroupBox2.Location = New System.Drawing.Point(246, 15)
Me.GroupBox2.Name = "GroupBox2"
Me.GroupBox2.Size = New System.Drawing.Size(174, 297)
Me.GroupBox2.TabIndex = 1
Me.GroupBox2.TabStop = False
Me.GroupBox2.Text = "Image Info"
'
'btnImageInfo
'
Me.btnImageInfo.Enabled = False
Me.btnImageInfo.Location = New System.Drawing.Point(49, 256)
Me.btnImageInfo.Name = "btnImageInfo"
Me.btnImageInfo.Size = New System.Drawing.Size(80, 32)
Me.btnImageInfo.TabIndex = 4
Me.btnImageInfo.Text = "Apply"
'
'txtRHeight
'
Me.txtRHeight.Location = New System.Drawing.Point(96, 223)
Me.txtRHeight.Name = "txtRHeight"
Me.txtRHeight.Size = New System.Drawing.Size(64, 20)
Me.txtRHeight.TabIndex = 3
Me.txtRHeight.Text = ""
'
'txtRWidth
'
Me.txtRWidth.Location = New System.Drawing.Point(96, 195)
Me.txtRWidth.Name = "txtRWidth"
Me.txtRWidth.Size = New System.Drawing.Size(64, 20)
Me.txtRWidth.TabIndex = 2
Me.txtRWidth.Text = ""
'
'txtRTop
'
Me.txtRTop.Location = New System.Drawing.Point(96, 167)
Me.txtRTop.Name = "txtRTop"
Me.txtRTop.Size = New System.Drawing.Size(64, 20)
Me.txtRTop.TabIndex = 1
Me.txtRTop.Text = ""
'
'txtRLeft
'
Me.txtRLeft.Location = New System.Drawing.Point(96, 139)
Me.txtRLeft.Name = "txtRLeft"
Me.txtRLeft.Size = New System.Drawing.Size(64, 20)
Me.txtRLeft.TabIndex = 0
Me.txtRLeft.Text = ""
'
'cbxPages
'
Me.cbxPages.Location = New System.Drawing.Point(96, 110)
Me.cbxPages.Name = "cbxPages"
Me.cbxPages.Size = New System.Drawing.Size(64, 21)
Me.cbxPages.TabIndex = 15
'
'txtPages
'
Me.txtPages.Enabled = False
Me.txtPages.Location = New System.Drawing.Point(96, 81)
Me.txtPages.Name = "txtPages"
Me.txtPages.Size = New System.Drawing.Size(64, 20)
Me.txtPages.TabIndex = 10
Me.txtPages.Text = ""
'
'txtHeight
'
Me.txtHeight.Enabled = False
Me.txtHeight.Location = New System.Drawing.Point(96, 53)
Me.txtHeight.Name = "txtHeight"
Me.txtHeight.Size = New System.Drawing.Size(64, 20)
Me.txtHeight.TabIndex = 9
Me.txtHeight.Text = ""
'
'txtWidth
'
Me.txtWidth.Enabled = False
Me.txtWidth.Location = New System.Drawing.Point(96, 25)
Me.txtWidth.Name = "txtWidth"
Me.txtWidth.Size = New System.Drawing.Size(64, 20)
Me.txtWidth.TabIndex = 8
Me.txtWidth.Text = ""
'
'Label21
'
Me.Label21.Location = New System.Drawing.Point(8, 227)
Me.Label21.Name = "Label21"
Me.Label21.Size = New System.Drawing.Size(78, 18)
Me.Label21.TabIndex = 7
Me.Label21.Text = "Region Height"
'
'Label20
'
Me.Label20.Location = New System.Drawing.Point(8, 198)
Me.Label20.Name = "Label20"
Me.Label20.Size = New System.Drawing.Size(78, 18)
Me.Label20.TabIndex = 6
Me.Label20.Text = "Region Width"
'
'Label19
'
Me.Label19.Location = New System.Drawing.Point(8, 169)
Me.Label19.Name = "Label19"
Me.Label19.Size = New System.Drawing.Size(69, 18)
Me.Label19.TabIndex = 5
Me.Label19.Text = "Region Top"
'
'Label18
'
Me.Label18.Location = New System.Drawing.Point(8, 140)
Me.Label18.Name = "Label18"
Me.Label18.Size = New System.Drawing.Size(69, 18)
Me.Label18.TabIndex = 4
Me.Label18.Text = "Region Left"
'
'Label17
'
Me.Label17.Location = New System.Drawing.Point(8, 111)
Me.Label17.Name = "Label17"
Me.Label17.Size = New System.Drawing.Size(87, 18)
Me.Label17.TabIndex = 3
Me.Label17.Text = "Choose A Page"
'
'Label16
'
Me.Label16.Location = New System.Drawing.Point(8, 82)
Me.Label16.Name = "Label16"
Me.Label16.Size = New System.Drawing.Size(48, 18)
Me.Label16.TabIndex = 2
Me.Label16.Text = "Pages"
'
'Label15
'
Me.Label15.Location = New System.Drawing.Point(8, 53)
Me.Label15.Name = "Label15"
Me.Label15.Size = New System.Drawing.Size(48, 18)
Me.Label15.TabIndex = 1
Me.Label15.Text = "Height"
'
'Label14
'
Me.Label14.Location = New System.Drawing.Point(8, 24)
Me.Label14.Name = "Label14"
Me.Label14.Size = New System.Drawing.Size(48, 18)
Me.Label14.TabIndex = 0
Me.Label14.Text = "Width"
'
'txtBarcodeInfo
'
Me.txtBarcodeInfo.Location = New System.Drawing.Point(441, 21)
Me.txtBarcodeInfo.Multiline = True
Me.txtBarcodeInfo.Name = "txtBarcodeInfo"
Me.txtBarcodeInfo.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.txtBarcodeInfo.Size = New System.Drawing.Size(171, 291)
Me.txtBarcodeInfo.TabIndex = 2
Me.txtBarcodeInfo.Text = ""
'
'btnOpen
'
Me.btnOpen.Location = New System.Drawing.Point(56, 184)
Me.btnOpen.Name = "btnOpen"
Me.btnOpen.Size = New System.Drawing.Size(128, 24)
Me.btnOpen.TabIndex = 0
Me.btnOpen.Text = "Open An Image File"
'
'btnScan
'
Me.btnScan.Location = New System.Drawing.Point(56, 224)
Me.btnScan.Name = "btnScan"
Me.btnScan.Size = New System.Drawing.Size(128, 24)
Me.btnScan.TabIndex = 1
Me.btnScan.Text = "Scan It"
'
'btnClose
'
Me.btnClose.Location = New System.Drawing.Point(56, 264)
Me.btnClose.Name = "btnClose"
Me.btnClose.Size = New System.Drawing.Size(128, 24)
Me.btnClose.TabIndex = 2
Me.btnClose.Text = "Close"
'
'btnScanningOptions
'
Me.btnScanningOptions.Location = New System.Drawing.Point(64, 96)
Me.btnScanningOptions.Name = "btnScanningOptions"
Me.btnScanningOptions.Size = New System.Drawing.Size(80, 32)
Me.btnScanningOptions.TabIndex = 13
Me.btnScanningOptions.Text = "Apply"
'
'Label9
'
Me.Label9.Location = New System.Drawing.Point(16, 64)
Me.Label9.Name = "Label9"
Me.Label9.Size = New System.Drawing.Size(64, 16)
Me.Label9.TabIndex = 8
Me.Label9.Text = "Threshold"
'
'txtThreshold
'
Me.txtThreshold.Location = New System.Drawing.Point(104, 65)
Me.txtThreshold.Name = "txtThreshold"
Me.txtThreshold.Size = New System.Drawing.Size(96, 20)
Me.txtThreshold.TabIndex = 8
Me.txtThreshold.Text = "128"
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.cbxBarcodeType)
Me.GroupBox1.Controls.Add(Me.Label1)
Me.GroupBox1.Controls.Add(Me.btnScanningOptions)
Me.GroupBox1.Controls.Add(Me.Label9)
Me.GroupBox1.Controls.Add(Me.txtThreshold)
Me.GroupBox1.Location = New System.Drawing.Point(16, 16)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(216, 144)
Me.GroupBox1.TabIndex = 0
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "Scanning Options"
'
'cbxBarcodeType
'
Me.cbxBarcodeType.Items.AddRange(New Object() {"0 - PDF417", "1 - DataMatrix", "2 - QRCode"})
Me.cbxBarcodeType.Location = New System.Drawing.Point(104, 24)
Me.cbxBarcodeType.Name = "cbxBarcodeType"
Me.cbxBarcodeType.Size = New System.Drawing.Size(96, 21)
Me.cbxBarcodeType.TabIndex = 15
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(16, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(80, 16)
Me.Label1.TabIndex = 14
Me.Label1.Text = "Barcode Type"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(632, 326)
Me.Controls.Add(Me.btnClose)
Me.Controls.Add(Me.btnScan)
Me.Controls.Add(Me.btnOpen)
Me.Controls.Add(Me.txtBarcodeInfo)
Me.Controls.Add(Me.GroupBox2)
Me.Controls.Add(Me.GroupBox1)
Me.Name = "Form1"
Me.Text = "Demo"
Me.GroupBox2.ResumeLayout(False)
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
Private Sub Init_GUI()
cbxBarcodeType.SelectedIndex = 0
End Sub
#End Region
#Region "Private Functions"
Private Function GetImgFormat(ByVal ImgName As String)
Dim pos As Integer
Dim ext_name As String
Dim result As Integer
pos = InStr(ImgName, ".")
ext_name = Mid(ImgName, pos + 1)
If (StrComp(ext_name, "bmp", vbTextCompare) = 0) Then
result = 1
ElseIf (StrComp(ext_name, "gif", vbTextCompare) = 0) Then
result = 2
ElseIf (StrComp(ext_name, "ico", vbTextCompare) = 0) Then
result = 3
ElseIf ((StrComp(ext_name, "jpg", vbTextCompare) = 0) Or _
(StrComp(ext_name, "jpeg", vbTextCompare) = 0)) Then
result = 4
ElseIf (StrComp(ext_name, "png", vbTextCompare) = 0) Then
result = 5
ElseIf ((StrComp(ext_name, "tif", vbTextCompare) = 0) Or _
(StrComp(ext_name, "tiff", vbTextCompare) = 0)) Then
result = 6
ElseIf (StrComp(ext_name, "wmf", vbTextCompare) = 0) Then
result = 7
Else
result = -1
End If
GetImgFormat = result
End Function
Private Sub btnScanningOptions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnScanningOptions.Click
On Error GoTo ErrorHandler
nBarcodeType = cbxBarcodeType.SelectedIndex
nThreshold = CInt(txtThreshold.Text)
Exit Sub
ErrorHandler:
End Sub
Private Sub btnImageInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImageInfo.Click
Dim tmp As String
Dim ErrorMsg As String
On Error GoTo ErrorHandler
' Region's left value
nRLeft = CInt(txtRLeft.Text)
If ((nRLeft < 0) Or (nRLeft >= nImgWidth)) Then
ErrorMsg = ErrorMsg & "Left value must be between 0 and image width minus 1." & vbCrLf
nRLeft = 0
End If
' Region's top value
nRTop = CInt(txtRTop.Text)
If ((nRTop < 0) Or (nRTop >= nImgHeight)) Then
ErrorMsg = ErrorMsg & "Left value must be between 0 and image height minus 1." & vbCrLf
nRTop = 0
End If
' Region's right value
nRRight = nRLeft + CInt(txtRWidth.Text) - 1
If ((nRRight < nRLeft) Or (nRRight >= nImgWidth)) Then
ErrorMsg = ErrorMsg & "Right value must be between left value and image width minus 1." & vbCrLf
nRRight = nImgWidth - 1
End If
' Region's bottom value
nRBottom = nRTop + CInt(txtRHeight.Text) - 1
If ((nRBottom < nRTop) Or (nRBottom >= nImgHeight)) Then
ErrorMsg = ErrorMsg & "Bottom value must be between top value and image height minus 1." & vbCrLf
nRBottom = nImgHeight - 1
End If
If (Len(ErrorMsg) > 0) Then
MsgBox(ErrorMsg)
End If
Exit Sub
ErrorHandler:
End Sub
Private Sub cbxPages_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxPages.SelectedIndexChanged
Dim result As Integer
Dim w As Integer
Dim h As Integer
If ((nImgFormat = 2) Or (nImgFormat = 6)) Then
' Page option for TIF or GIF
nPageOption = CInt(cbxPages.Text)
result = De2DSetPage(nPageOption)
If (result = 1) Then
result = De2DGetImgSize(w, h)
txtWidth.Text = System.Convert.ToString(w)
txtRWidth.Text = System.Convert.ToString(w)
txtHeight.Text = System.Convert.ToString(h)
txtRHeight.Text = System.Convert.ToString(h)
txtRLeft.Text = "0"
txtRTop.Text = "0"
nRLeft = 0
nRTop = 0
nRRight = w - 1
nRBottom = h - 1
nImgWidth = w
nImgHeight = h
End If
End If
End Sub
#End Region
Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
Dim file_name As String
Dim file_size As Long
Dim pos As Long
Dim read_count As Integer
Dim buffer() As Byte
Dim ByteBuffer() As Byte
Dim result As Integer
Dim P As Integer
Dim I As Integer
Dim w As Integer
Dim h As Integer
' clean file name
OFD.FileName = ""
OFD.ShowDialog()
file_name = OFD.FileName
If (Len(file_name) = 0) Then
Exit Sub
End If
' get image format info
nImgFormat = GetImgFormat(file_name)
If (nImgFormat = -1) Then
' invalid image format
Exit Sub
End If
' load image content into the library directly from the file on the disk
result = De2DLoadFromFile(file_name, nImgFormat)
If (result = 1) Then
' loading is OK
If ((nImgFormat = 2) Or (nImgFormat = 6)) Then
' TIF or GIF file
' how many pages
P = De2DGetNumOfPages()
txtPages.Text = System.Convert.ToString(P)
cbxPages.Items.Clear()
' update page list
For I = 0 To (P - 1)
cbxPages.Items.Add(I)
Next I
cbxPages.SelectedIndex = 0
' choose 1st page
result = De2DSetPage(0)
If (result = 1) Then
' image size
result = De2DGetImgSize(w, h)
txtWidth.Text = System.Convert.ToString(w)
txtRWidth.Text = System.Convert.ToString(w)
txtHeight.Text = System.Convert.ToString(h)
txtRHeight.Text = System.Convert.ToString(h)
txtRLeft.Text = "0"
txtRTop.Text = "0"
nRLeft = 0
nRTop = 0
nRRight = w - 1
nRBottom = h - 1
nImgWidth = w
nImgHeight = h
End If
Else
txtPages.Text = ""
cbxPages.Items.Clear()
' Other image formats
txtPages.Text = ""
cbxPages.Items.Clear()
' image size
result = De2DGetImgSize(w, h)
txtWidth.Text = System.Convert.ToString(w)
txtRWidth.Text = System.Convert.ToString(w)
txtHeight.Text = System.Convert.ToString(h)
txtRHeight.Text = System.Convert.ToString(h)
txtRLeft.Text = "0"
txtRTop.Text = "0"
nRLeft = 0
nRTop = 0
nRRight = w - 1
nRBottom = h - 1
nImgWidth = w
nImgHeight = h
End If
btnImageInfo.Enabled = True
Else
btnImageInfo.Enabled = False
End If
End Sub
Private Sub btnScan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnScan.Click
Dim result As Integer
Dim count As Integer
Dim info As String
Dim I As Integer
Dim J As Integer
Dim X As Int32
Dim Y As Int32
Dim StrLen As Integer
Dim Point(3) As Long
Dim OneChar As Integer
Dim BarcodeInfo As String
Dim Rows As Integer
Dim Cols As Integer
Dim ECLevel As Integer
Dim Truncated As Integer
Dim Version As Integer
Dim Level As Integer
Dim Mask As Integer
' Currently 2d decoder library only supports decoding PDF417, DataMatrix and QRCode
' More 2D barcodes are coming soon
result = De2DScanType(nBarcodeType, 1)
' For full version library, pass the 10-digit license key to this function
' Sample code:
' result = De2DSetKey("123456-7890")
result = De2DSetKey("DEMO")
result = De2DSetThreshold(nThreshold)
result = De2DSetRegion(nRLeft, nRTop, nRRight, nRBottom)
result = De2DScan()
count = De2DGetCount()
If (count > 0) Then
If (count = 1) Then
BarcodeInfo = "1 Barcode Found" & vbCrLf
Else
BarcodeInfo = count & " Barcodes Found" & vbCrLf
End If
For I = 1 To count
BarcodeInfo = BarcodeInfo & "[Barcode " & System.Convert.ToString(I) + "]" & vbCrLf
' barcode type
If (nBarcodeType = 0) Then
' PDF417
BarcodeInfo = BarcodeInfo & "Type: PDF417" & vbCrLf
De2DGetPDF417Param(I - 1, Rows, Cols, ECLevel, Truncated)
BarcodeInfo = BarcodeInfo & "Number of rows: " & Rows & vbCrLf
BarcodeInfo = BarcodeInfo & "Number of columns: " & Cols & vbCrLf
BarcodeInfo = BarcodeInfo & "Error correction level: " & ECLevel & vbCrLf
If (Truncated = 0) Then
BarcodeInfo = BarcodeInfo & "Truncated: NO" & vbCrLf
Else
BarcodeInfo = BarcodeInfo & "Truncated: YES" & vbCrLf
End If
ElseIf (nBarcodeType = 1) Then
' DataMatrix
BarcodeInfo = BarcodeInfo & "Type: DataMatrix" & vbCrLf
De2DGetDMParam(I - 1, Rows, Cols)
BarcodeInfo = BarcodeInfo & "Number of rows: " & Rows & vbCrLf
BarcodeInfo = BarcodeInfo & "Number of columns: " & Cols & vbCrLf
ElseIf (nBarcodeType = 2) Then
' QRCode
BarcodeInfo = BarcodeInfo & "Type: QRCode" & vbCrLf
De2DGetQRCodeParam(I - 1, Rows, Cols, Version, Level, Mask)
BarcodeInfo = BarcodeInfo & "Number of rows: " & Rows & vbCrLf
BarcodeInfo = BarcodeInfo & "Number of columns: " & Cols & vbCrLf
BarcodeInfo = BarcodeInfo & "Version: " & Version & vbCrLf
If (Level = 0) Then
BarcodeInfo = BarcodeInfo & "Level: L" & vbCrLf
ElseIf (Level = 1) Then
BarcodeInfo = BarcodeInfo & "Level: M" & vbCrLf
ElseIf (Level = 2) Then
BarcodeInfo = BarcodeInfo & "Level: Q" & vbCrLf
ElseIf (Level = 3) Then
BarcodeInfo = BarcodeInfo & "Level: H" & vbCrLf
End If
BarcodeInfo = BarcodeInfo & "Mask: " & Mask & vbCrLf
End If
' barcode boundary rectangle
Call De2DGetRect(I - 1, Point(0), Point(1), Point(2), Point(3))
For J = 1 To 4
X = Point(J - 1) / &H10000
Y = Point(J - 1) And &HFFFF
BarcodeInfo = BarcodeInfo & "Point " & J & ": (" & X & ", " & Y & ")" & vbCrLf
Next J
' the string encoded by this barcode
StrLen = De2DGetStrLen(I - 1)
BarcodeInfo = BarcodeInfo & "String length: " & StrLen & vbCrLf
BarcodeInfo = BarcodeInfo & "String: "
For J = 0 To (StrLen - 1)
OneChar = System.Convert.ToByte(De2DGetCharAt(I - 1, J) And &HFF)
OneChar = OneChar And &HFF
BarcodeInfo = BarcodeInfo & Chr(OneChar)
Next J
BarcodeInfo = BarcodeInfo & vbCrLf & vbCrLf
Next I
txtBarcodeInfo.Text = BarcodeInfo
De2DFreeMem()
Else
txtBarcodeInfo.Text = "No barcode found."
End If
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
' free up memory
De2DCleanUp()
Me.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call De2DInit()
nBarcodeType = 0
cbxBarcodeType.SelectedIndex = 0
txtThreshold.Text = 128
txtBarcodeInfo.Text = ""
nThreshold = 128
bDiskFile = True
End Sub
End Class
Benim demo DLLin açık kodu :
library ProjectDLL;
uses
SysUtils,
Classes,
Dialogs;
procedure DllMessage; export;
begin
ShowMessage('Hello world from a Delphi DLL');
end;
function getit:PChar; stdcall; export;
begin
Result:=''
end;
exports getit,DllMessage;
end.
.NET / native C interop islemleri ile epey bir ugrastim.
Delphi'nin üretigi DLL'in fonksyonlari C++'daki gibi "decorated name"'li olabilir (argumana göre fonksyon ismine degisik eklentiler yapiliyor).
"Dependency walker" türü bir programla DLL'in export ettigi fonksyonlara bak. decorate/undecorate dügmesini kaçirma.
Simdi baktim, dekorasyon yok. üstekileri kaale alma.
<DllImport("Project.dll", SetlastError:=True)> Private Shared Sub DllMessage()
End Sub
tarzindaki kod isini görecektir.
hocam dlli ben yazıyorum fonksiyonlar belli sadece tek fonksiyonu çağıracaz. adı da bu: DllMessage
diğer dediklerini anlamaıyorum kısa yoldan bana bir demo şeyttiriversen çok makbule geçer.
adamın istediği DLLi güzelce delphi ile yazıyorum ama kendisi .net ile kullnacak öyle istemiş. bu demoyu çalıştırabilirsem kendi DLLimi de yapabilirim.
Sana zahmet bir bakıversen. Demo DLL burada
http://www.speedyshare.com/files/24449104/DLLkullan.zip
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("C:\Documents and Settings\Muhittin KAPLAN\Desktop\DLLkullan\ProjectDLL.dll", EntryPoint:="DllMessage")> _
Public Shared Sub _
DllMessage()
' Leave the body of the function empty.
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
DllMessage()
End Sub
End Class
http://www.4shared.com/file/H_6g_IkQ/importDLL.html
Buda Yaralandığım Döküman. Sadece Delphi ile değil Fonksiyonlarını bildiğiniz DLL leri kullanbilirsiniz.
http://msdn.microsoft.com/en-us/library/172wfck9(vs.71).aspx
Allah senden razı olsun. ufak bir konu daha danışsam. fonksiyonlar iyi güzel çalışıyor. peki olay nasıl tetiklenebilir.? DLL kendi bir olay üretebilir mi? Galiba bu şekil olmaz. çünkü DLL öylece duruyor. program bundan birşeyler istiyor.
"dalegate" kavramını araştırman gerek. import edilen bir DLL ile hiç yapmadım. İstediğin şu ise
Runtime zamanında oluşturulmuş bir buton un click event'i ne ulaşmak gibi bir düşüncen varsa delagete ve adressof u araştırman gerekli. hiç DLL içerinde oluşturulmuş bir event e bu şekilde ulaşmak gibi bir çalışmam olmadı.
Selam umarım işini görür;
http://www.codeproject.com/KB/DLL/dllevent.aspx (http://www.codeproject.com/KB/DLL/dllevent.aspx)
Sağol tam istediğim şey buydu. Fakat bana delphi versiyonu lazım.
Sonradan bir örnek buldum. Sanırım benzer şekilde yapılmış
http://delphi.about.com/od/windowsshellapi/a/mousehook.htm