|
Recompile your program as an 32bit.
|
|
|
|
|
It appears that your code is compiled for AnyCPU, which will default to 64-bit on a 64-bit machine. Since you don't have 64-bit ODBC drivers and only 32-bit, your code cannot use them. You cannot mix 64 and 32 bit code in the same process.
|
|
|
|
|
great. this is what im looking for. thanks.
C# コードMicrosoft End User
2000-2008
「「「「「「「「「「「「「「「「「「「「「「「「「「「「
The best things in life are free
」」」」」」」」」」」」」」」」」」」」」」」」」」」」
|
|
|
|
|
<off topic="">
Do you know of the new vb.net (2010) has 64bit support for odbc, ado and dao
Jan
|
|
|
|
|
There is no such thing as VB.NET having 64-bit support for ODBC and ADO.NET. DAO died a long time ago.
It's a matter of having 64-bit drivers for the data sources you're going to use.
|
|
|
|
|
thanx.
I did use dao. but like you wrote. It is dead. For the same reason I don't work with VB6 anymore. I'm just a small hobby programmer
Jan
|
|
|
|
|
Dear all,
I'm trying to call a function in a DLL. And I code a Connector to connect it.
But I'm getting the error message at "Marshal.FreeHGlobal(ptr)".
Sorry, this is my first time touch on DLL. And I have to continue previous developer project which is this.
Below are my codes , please kindly advise. Thanks
VB Form
Imports DRS40Connector.Dpi32
Imports System.Text
Imports Excel
Imports System.IO
Imports System.Threading
Imports System.Data
Imports System.Data.OleDb
Imports System.Runtime.InteropServices
Imports System.Text.RegularExpressions
Public Class CheckCIDFrm
Delegate Sub uploadToDRSDelegate() 'Thread-safe function call
Private t1 As Thread 'Runs UpdateToDRS function
'Thread-safe call to UploadToDRS function
Private Sub UploadToDRSThread()
If lblMsg.InvokeRequired Then
Dim d As New uploadToDRSDelegate(AddressOf UploadToDRS)
Me.Invoke(d)
Else
UploadToDRS()
End If
End Sub
'Upload Customer Records to DRS
Private Sub UploadToDRS()
'Disable upload btn
Dim cdb As New DpiCdb_t()
Dim result As Integer = CustomerEnquiry(TextBox1.Text, cdb)
If result = CallFailure Then
MessageBox.Show(GetError(dpi))
Else
MessageBox.Show("It works")
End If
End Sub
Public Function CustomerEnquiry(ByVal customerID As Double, ByRef cdb As DpiCdb_t) As Boolean
' Not interested in announcements
' Disable announcement retrieval
'DpiEnaAno(_dpi, False)
' Not interested in customer picture
' Allocate empty picture buffer
Dim picCap As Integer = 0
Dim picBuf As Byte() = New Byte(picCap - 1) {}
Dim picLen As Integer = 0
' Not interested in customer signature
' Allocate empty signature picture buffer
Dim sigCap As Integer = 0
Dim sigBuf As Byte() = New Byte(sigCap - 1) {}
Dim sigLen As Integer = 0
' Allocate customer database block
'cdb = New DpiCdb_t()
Dim ptr As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(cdb))
Marshal.StructureToPtr(cdb, ptr, False)
' Retrieve customer information
Dim result As Integer = -1
Try
result = DpiGcdi(dpi, String.Empty, customerID, ptr, picBuf, picLen, picCap, sigBuf, sigLen, sigCap)
cdb = CType(Marshal.PtrToStructure(ptr, GetType(DpiCdb_t)), DpiCdb_t)
Finally
' Always free the unmanaged memory
If ptr <> IntPtr.Zero Then
Marshal.FreeHGlobal(ptr)
End If
End Try
' Return true if successful, otherwise false
Return result = 0
End Function
'Get Error from DRS
Private Function GetError(ByRef dpi As Dpi_t) As String
Dim errMsg As New StringBuilder(DPI_ERR_LEN + 1)
DpiErr(dpi, errMsg)
Return errMsg.ToString
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
t1 = New Thread(AddressOf UploadToDRSThread)
t1.Start()
End Sub
End Class
DLL Connector
Public Class Dpi32
Public Const CallSuccess As Integer = 0
Public Const CallFailure As Integer = -1
Public Const DPI_CRD_LEN = 16 'Card number
Public Const DPI_CDA_LEN = 37 'Card data
Public Const DPI_CTI_LEN = 10 'Customer title
Public Const DPI_CNM_LEN = 40 'Customer name
Public Const DPI_CIL_LEN = 4 'Complimentary issue location number
Public Const DPI_UID_LEN = 8 'User identifier
Public Const DPI_UPW_LEN = 40 'Password length
Public Const DPI_LNM_LEN = 40 'Long user name
Public Const DPI_ERR_LEN = 80 'Error message
Public Const DPI_PRG_LEN = 40 'Program path name length
Public Const DPI_R32_CTC_LEN = 3 'Release 32 cust type code length (3-chars)
Public Const DPI_CTC_LEN = 4 'Customer type code length
Public Const DPI_CTD_LEN = 40 'Customer type description length
Public Const DPI_IPN_LEN = 15 'IC/passport number length
Public Const DPI_IPT_LEN = 1 'IC/passport type length
Public Const DPI_R38_ADL_LEN = 25 'Release 38 address line length
Public Const DPI_ADL_LEN = 35 'Address line length
Public Const DPI_CTY_LEN = 15 'City name length
Public Const DPI_STE_LEN = 15 'State name length
Public Const DPI_CON_LEN = 15 'Country name length
Public Const DPI_R38_PCD_LEN = 7 'Release 38 post code length
Public Const DPI_PCD_LEN = 10 'Post code length
Public Const DPI_ARC_LEN = 2 'Area code length
Public Const DPI_TNM_LEN = 51 'Title and name length
Public Const DPI_PZD_LEN = 40 'Prize description length
Public Const DPI_PCI_LEN = 4 'Profit centre identifier length
Public Const DPI_PCN_LEN = 40 'Profit centre name length
Public Const DPI_CYC_LEN = 2 'Currency code length
Public Const DPI_CAR_LEN = 40 'Complimentary adjustment remarks
Public Const DPI_SDT_LEN = 8 'String date length
Public Const DPI_STM_LEN = 6 'String time length
Public Const DPI_ATD_LEN = 10 'Address/telephone descrition length
Public Const DPI_TEL_LEN = 20 'Telephone number length
Public Const DPI_PFI_LEN = 4 'Preference flag identifier length
Public Const DPI_PFV_LEN = 40 'Preference flag value length
Public Const DPI_R37_PFV_LEN = 6 'Release 37 preference flag value length
Public Const DPI_WGN_LEN = 4 'Work group name length
Public Const DPI_GEN_LEN = 1 'Gender length
Public Const DPI_BUS_LEN = 40 'Business or employer's name length
Public Const DPI_COTC_LEN = 3 'Contact type code length
Public Const DPI_MAX_HOST = 10 'Maximum host computers
Public Const DPI_MAX_TER = 6 'Maximum telephone records
Public Const DPI_R32_MAX_PFR = 36 'Max pref flag records as at release 32
Public Const DPI_R37_MAX_PFR = 60 'Max pref flag records as at release 37
Public Const DPI_MAX_PFR = 120 'Maximum preference flag records
Public Const DPI_EMA_LEN = 129 'Email address
Public Const DPI_CXT_LEN = 4 'Customer transaction type
Public Const DPI_FAI_LEN = 4 'Facility identifier
Public Const DPI_CMD_LEN = 4 'Command name
Public Const DPI_BCS_LEN = 2048 'Background command string
Public Const DPI_IPA_LEN = 15 'IP address
Public Const DPI_FNM_LEN = 20 'File name
Public Const DPI_EC_PIN_LEN = 8 'E-cash PIN length
Public Const DPI_ROOM_NO_LEN = 8 'Room number length
Public Const DPI_LANG_CODE_LEN = 2 'Language code length
Public Const DPI_TXID_LEN = 20 'Transaction identifier
Public Const DPI_SID_LEN = 40 'Stored image description
Public Const DPI_CCT_BAL_STR_LEN = 10 'Credit card term balance string
Public Const DPI_ANO_CODE_LEN As Integer = 4 'Announcement code
Public Const DPI_MAX_ANO As Integer = 8 'Maximum announcement records
Public Const DPI_MAX_ANO_TEXT_BUF As Integer = 8192 'Maximum announcement records
Public Const DPI_ANO_TEXT_LEN As Integer = 8192
'ADDRESS/TELEPHONE STATES
Public Const DPI_ATS_OK As Integer = 0 'OK
Public Const DPI_ATS_BL As Integer = 1 'Blocked
Public Const DPI_ATS_XX As Integer = 2 'Invalid
'DPI data block structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=1)> _
Public Structure Dpi_t
'Unix protocol services daemon
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_PRG_LEN + 1)> _
Dim dpiDrSuPsd As String
'Pointer to communications data
Dim dpiVoidCom As IntPtr
'Pointer to client environment header
Dim dpiVoidCeh As IntPtr
'Response body
Dim dpiRspBdy As IntPtr
'Response length
Dim dpiRspLen As Integer
'Customer Maintenance data
Dim dpiCmData As IntPtr
'Read Customer Transactions data
Dim dpiRdcxData As IntPtr
'Last error code
Dim dpiLstErr As Integer
'Last rejection mode
Dim dpiLstRejMode As Short
Dim dpiCdb As IntPtr
'Override no update authorisation
Dim dpiONoUa As Byte
'Override too much
Dim dpiOTooMuch As Byte
'Override barred customer
Dim dpiOBar As Byte
'Validate PIN on next GCDC/GCDI
Dim dpiVPin As Byte
'Personal identification number
Dim dpiPin As Integer 'long
'Card data
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_CDA_LEN + 1)> _
Dim dpiCda As String
'Enquiry currency code (if any)
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_CYC_LEN + 1)> _
Dim dpiEcCyc As String
'Address type
Dim dpiAdSel As Short
'Transaction identifier
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_TXID_LEN + 1)> _
Dim dpiTxid As String
'Profit centre identifier
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_PCI_LEN + 1)> _
Dim dpiPci As String
'Complimentary issue location
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_CIL_LEN + 1)> _
Dim dpiCil As String
'Approver's ID & password
Dim dpiEcoApprUidUpw As DpiEcoApprUidUpw_t
'Approver's card data
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_CDA_LEN + 1)> _
Dim dpiEcoApprCda As String
'Approver's type
Dim dpiEcoAppr As Short
'Rounding adjustment
Dim dpiEcoRndAdj As Double
'Area entry user identifier
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_UID_LEN + 1)> _
Dim dpiAentUid As String
'Area entry long user name
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_LNM_LEN + 1)> _
Dim dpiAentLnm As String
End Structure
'ECO AMLA approver id & password structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=1)> _
Public Structure DpiEcoApprUidUpw_t
'Approver's ID
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_UID_LEN + 1)> _
Dim dpiEcoApprUidUpwUid As String
'Approver's password
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_UPW_LEN + 1)> _
Dim dpiEcoApprUidUpwUpw As String
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=1)> _
Public Structure DpiPfi_t
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_PFI_LEN + 1)> _
Dim dpiPfrPfi As String
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=1)> _
Public Structure DpiPfv_t
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_PFV_LEN + 1)> _
Dim dpiPfrPfv As String
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=1)> _
Public Structure DpiTel_t
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_TEL_LEN + 1)> _
Dim dpiTerTel As String
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=1)> _
Public Structure DpiAnoCode_t
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_ANO_CODE_LEN + 1)> _
Dim dpiAnoCode As String
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=1)> _
Public Structure DpiAnoText_t
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_ANO_TEXT_LEN + 1)> _
Dim dpiAnoText As String
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=1)> _
Public Structure DpiAtd_t
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_ATD_LEN + 1)> _
Dim dpiTerAtd As String
End Structure
Public Class DpiCsb_t
Public Const DPI_CSB_OK As Integer = 0
Public Const DPI_CSB_SUS As Integer = 1
Public Const DPI_CSB_RES As Integer = 2
Public Const DPI_CSB_BAR As Integer = 4
Public Const DPI_CSB_CVL As Integer = 8
Public Const DPI_CSB_CPD As Integer = 16
Public Const DPI_CSB_SEC As Integer = 32
End Class
#Region "CUSTOMER DATA BLOCK"
''' <summary>Customer data block</summary>
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=4)> _
Public Structure DpiCdb_t
#Region "Financial figures"
''' <summary>Visible entitlement balance</summary>
Public dpiVisBal As Double
''' <summary>Hidden reserve balance</summary>
Public dpiHidBal As Double
''' <summary>Loyalty point balance</summary>
Public dpiLptBal As Double
''' <summary>Cash e-cash balance</summary>
Public dpiCecBal As Double
''' <summary>Non-neg e-cash balance</summary>
Public dpiNecBal As Double
''' <summary>Comp overdraft limit</summary>
Public dpiCol As Double
''' <summary>Cross drawdown visible balance</summary>
Public dpiVisXdd As Double
''' <summary>Cross drawdown hidden balance</summary>
Public dpiHidXdd As Double
''' <summary>Cross drawdown loyalty balance</summary>
Public dpiLptXdd As Double
''' <summary>Cross drawdown comp o/d limit</summary>
Public dpiColXdd As Double
''' <summary>Displayable visible balance</summary>
Public dpiVisDsp As Double
''' <summary>Displayable loyalty balance</summary>
Public dpiLptDsp As Double
''' <summary>Expiry look-ahead amount</summary>
Public dpiXlaAmt As Double
''' <summary>Visible entitlement available</summary>
Public dpiVisAvl As Double
#End Region
#Region "Miscellaneous information"
''' <summary>Time of the query</summary>
Public dpiTim As Integer
''' <summary>Customer identifier</summary>
Public dpiCid As Double
''' <summary>Last customer transfer time</summary>
Public dpiLczTim As Integer
''' <summary>Number of telephone records</summary>
Public dpiTerCnt As UInteger
''' <summary>Number of preference flag records</summary>
Public dpiPfrCnt As UInteger
''' <summary>Customer status bitmap</summary>
Public dpiCsb As DpiCsb_t
''' <summary>Customer class</summary>
Public dpiCcl As Short
''' <summary>Expiry look-ahead period (days)</summary>
Public dpiXlaPrd As Short
''' <summary>Room booking limit</summary>
Public dpiRmLim As Short
''' <summary>Customer title</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_CTI_LEN + 1)> _
Public dpiCti As String
''' <summary>Customer name</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_CNM_LEN + 1)> _
Public dpiCnm As String
''' <summary>Customer gender</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_GEN_LEN + 1)> _
Public dpiGen As String
''' <summary>Customer type code</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_CTC_LEN + 1)> _
Public dpiCtc As String
''' <summary>Customer type description</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_CTD_LEN + 1)> _
Public dpiCtd As String
''' <summary>Date of birth</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_SDT_LEN + 1)> _
Public dpiDob As String
''' <summary>Date added</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_SDT_LEN + 1)> _
Public dpiDad As String
''' <summary>Last Customer Maintenance date</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_SDT_LEN + 1)> _
Public dpiLcmDat As String
''' <summary>Loyalty point last activity date</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_SDT_LEN + 1)> _
Public dpiLptLdt As String
''' <summary>Card expiry date</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_SDT_LEN + 1)> _
Public dpiCrdExp As String
''' <summary>Last play date</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_SDT_LEN + 1)> _
Public dpiLpd As String
''' <summary>Last customer transfer date</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_SDT_LEN + 1)> _
Public dpiLczDat As String
''' <summary>Customer currency code</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_CYC_LEN + 1)> _
Public dpiCcCyc As String
''' <summary>This facility identifier</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_FAI_LEN + 1)> _
Public dpiThisFai As String
''' <summary>Update inst facility identifier</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_FAI_LEN + 1)> _
Public dpiUiFai As String
''' <summary>Home inst facility identifier</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_FAI_LEN + 1)> _
Public dpiHiFai As String
''' <summary>Preferred language</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_LANG_CODE_LEN + 1)> _
Public dpiPrefLang As String
''' <summary>Lang code of national script</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_LANG_CODE_LEN + 1)> _
Public dpiNasLang As String
''' <summary>Customer name in national script</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_CNM_LEN + 1)> _
Public dpiNasCnm As String
''' <summary>Customer title in national script</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_CTI_LEN + 1)> _
Public dpiNasCti As String
''' <summary>Show visible balance flag</summary>
<MarshalAs(UnmanagedType.I1)> _
Public dpiShowVisBal As Boolean
''' <summary>Visible balance string</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_CCT_BAL_STR_LEN + 1)> _
Public dpiVisBalStr As String
''' <summary>Show loyalty balance flag</summary>
<MarshalAs(UnmanagedType.I1)> _
Public dpiShowLptBal As Boolean
''' <summary>Loyalty balance string</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_CCT_BAL_STR_LEN + 1)> _
Public dpiLptBalStr As String
''' <summary>Region code</summary>
Public dpiRgn As Short
''' <summary>Number of announcement</summary>
Public dpiAnoCnt As UInteger
#End Region
#Region "IC/Passport details"
''' <summary>IC/passport number</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_IPN_LEN + 1)> _
Public dpiIpn As String
''' <summary>IC/passport type ("I" or "P")</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_IPT_LEN + 1)> _
Public dpiIpt As String
''' <summary>IC/passport country</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_CON_LEN + 1)> _
Public dpiIpc As String
#End Region
#Region "Customer's address"
''' <summary>Address line 1</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_ADL_LEN + 1)> _
Public dpiAd1 As String
''' <summary>Address line 2</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_ADL_LEN + 1)> _
Public dpiAd2 As String
''' <summary>Address line 3</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_ADL_LEN + 1)> _
Public dpiAd3 As String
''' <summary>City</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_CTY_LEN + 1)> _
Public dpiCty As String
''' <summary>State</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_STE_LEN + 1)> _
Public dpiSte As String
''' <summary>Country</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_CON_LEN + 1)> _
Public dpiCon As String
''' <summary>Post code</summary>
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DPI_PCD_LEN + 1)> _
Public dpiPcd As String
#End Region
#Region "Customer's telephone records"
''' <summary>Customer's telephone records</summary>
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=DPI_MAX_TER)> _
Public dpiTerArr As DpiTer_t()
#End Region
#Region "Preference flag records"
''' <summary>Preference flag records</summary>
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=DPI_MAX_PFR)> _
Public dpiPfrArr As DpiPfr_t()
#End Region
#Region "Announcement records"
''' <summary>Announcement records</summary>
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=DPI_MAX_ANO)> _
Public dpiAnoArr As DpiAno_t()
#End Region
End Structure
#End Region
' TELEPHONE RECORD STRUCTURE
Public Class DpiTer_t
Public dpiTerAtd As New DpiAtd_t() ' Address/phone description
Public dpiTerTel As New DpiTel_t() ' Telephone number
Public dpiTerTe1 As SByte ' Best number flag
End Class
' PREFERENCE FLAG RECORD STRUCTURE
Public Class DpiPfr_t
Public dpiPfrPfi As New DpiPfi_t() ' Preference flag identifier
Public dpiPfrPfv As New DpiPfv_t() ' Preference flag value
End Class
' ANNOUNCEMENT RECORD STRUCTURE
Public Class DpiAno_t
Public dpiAnoCode As New DpiAnoCode_t() ' Announcement code
Public dpiAnoText As New DpiAnoText_t() ' Announcement text
End Class
'Initiation
<DllImport("dpi32.dll")> _
Public Shared Function DpiIni(ByRef dpi As Dpi_t, <MarshalAs(UnmanagedType.LPStr)> ByVal cfgName As String, ByVal hInst As IntPtr) As Integer
End Function
'Log-on
<DllImport("dpi32.dll")> _
Public Shared Function DpiOn(ByRef dpi As Dpi_t, <MarshalAs(UnmanagedType.LPStr)> ByVal cil As StringBuilder, <MarshalAs(UnmanagedType.LPStr)> ByVal uid As StringBuilder, <MarshalAs(UnmanagedType.LPStr)> ByVal upw As StringBuilder, <MarshalAs(UnmanagedType.LPStr)> ByVal cda As StringBuilder) As Integer
End Function
'Change work group
<DllImport("dpi32.dll")> _
Public Shared Function DpiCwg(ByRef dpi As Dpi_t, <MarshalAs(UnmanagedType.LPStr)> ByVal cil As String, <MarshalAs(UnmanagedType.LPStr)> ByVal wgn As String) As Integer
End Function
'Log-off
<DllImport("dpi32.dll")> _
Public Shared Function DpiOff(ByRef dpi As Dpi_t, <MarshalAs(UnmanagedType.LPStr)> ByVal cil As StringBuilder) As Integer
End Function
'Terminate
<DllImport("dpi32.dll")> _
Public Shared Function DpiTrm(ByRef dpi As Dpi_t) As Integer
End Function
'Return last error message
<DllImport("dpi32.dll")> _
Public Shared Function DpiErr(ByRef dpi As Dpi_t, <MarshalAs(UnmanagedType.LPStr)> ByVal err As StringBuilder) As Integer
End Function
'CUSTOMER MAINTENANCE FUNCTION DECLARATIONS
'Initialise
<DllImport("dpi32.dll")> _
Public Shared Function DpiCmIni(ByRef dpi As Dpi_t) As Integer
End Function
'Get customer identifier
<DllImport("dpi32.dll")> _
Public Shared Function DpiCmGetCid(ByRef dpi As Dpi_t, ByRef cid As Double) As Integer
End Function
'Load general data
<DllImport("dpi32.dll")> _
Public Shared Function DpiCmLoadGen(ByRef dpi As Dpi_t, ByVal cid As Double, <MarshalAs(UnmanagedType.LPStr)> ByVal cnm As String, <MarshalAs(UnmanagedType.LPStr)> ByVal cti As String, <MarshalAs(UnmanagedType.LPStr)> ByVal dob As String, <MarshalAs(UnmanagedType.LPStr)> ByVal ctc As String, <MarshalAs(UnmanagedType.LPStr)> ByVal gen As String, <MarshalAs(UnmanagedType.LPStr)> ByVal bus As String, <MarshalAs(UnmanagedType.LPStr)> ByVal ipn As String, <MarshalAs(UnmanagedType.LPStr)> ByVal ipt As String, <MarshalAs(UnmanagedType.LPStr)> ByVal ipc As String, ByVal col As Double, ByVal raf As Integer, ByVal ced As Double, ByVal nac As String, ByVal telAts As Short, ByVal adrAts As Short, ByVal emaAts As Short) As Integer
End Function
'Load telephone number
<DllImport("dpi32.dll")> _
Public Shared Function DpiCmLoadTel(ByRef dpi As Dpi_t, <MarshalAs(UnmanagedType.LPStr)> ByVal atd As String, <MarshalAs(UnmanagedType.LPStr)> ByVal tel As String, ByVal best As Integer) As Integer
End Function
'Load Address
<DllImport("dpi32.dll")> _
Public Shared Function DpiCmLoadAdr(ByRef dpi As Dpi_t, <MarshalAs(UnmanagedType.LPStr)> ByVal atd As String, <MarshalAs(UnmanagedType.LPStr)> ByVal ad1 As String, <MarshalAs(UnmanagedType.LPStr)> ByVal ad2 As String, <MarshalAs(UnmanagedType.LPStr)> ByVal ad3 As String, <MarshalAs(UnmanagedType.LPStr)> ByVal cty As String, <MarshalAs(UnmanagedType.LPStr)> ByVal ste As String, <MarshalAs(UnmanagedType.LPStr)> ByVal con As String, <MarshalAs(UnmanagedType.LPStr)> ByVal pcd As String, ByVal rgnId As Integer) As Integer
End Function
'Load Customer Email Address
<DllImport("dpi32.dll")> _
Public Shared Function DpiCmLoadEma(ByRef dpi As Dpi_t, <MarshalAs(UnmanagedType.LPStr)> ByVal ema As String) As Integer
End Function
'Load customer currency code
<DllImport("dpi32.dll")> _
Public Shared Function DpiCmLoadCc(ByRef dpi As Dpi_t, <MarshalAs(UnmanagedType.LPStr)> ByVal cccyc As String) As Integer
End Function
'Load preference flag value
<DllImport("dpi32.dll")> _
Public Shared Function DpiCmLoadPfv(ByRef dpi As Dpi_t, <MarshalAs(UnmanagedType.LPStr)> ByVal pfi As String, <MarshalAs(UnmanagedType.LPStr)> ByVal pfv As String) As Integer
End Function
'Add Customer
<DllImport("dpi32.dll")> _
Public Shared Function DpiCmAdd(ByRef dpi As Dpi_t) As Integer
End Function
'Change Customer
<DllImport("dpi32.dll")> _
Public Shared Function DpiCmChg(ByRef dpi As Dpi_t) As Integer
End Function
'Terminate
<DllImport("dpi32.dll")> _
Public Shared Function DpiCmTrm(ByRef dpi As Dpi_t) As Integer
End Function
'Append contact log entry
<DllImport("dpi32.dll")> _
Public Shared Function DpiClg(ByRef dpi As Dpi_t, ByVal cid As Double, <MarshalAs(UnmanagedType.LPStr)> ByVal dat As String, <MarshalAs(UnmanagedType.LPStr)> ByVal tim As String, <MarshalAs(UnmanagedType.LPStr)> ByVal uid As String, <MarshalAs(UnmanagedType.LPStr)> ByVal cotc As String, ByVal con As String, <MarshalAs(UnmanagedType.LPStr)> ByVal fud As String) As Integer
End Function
<DllImport("dpi32.dll")> _
Public Shared Function DpiGcdi(ByRef dpi As Dpi_t, <MarshalAs(UnmanagedType.LPStr)> ByVal cil As String, ByVal cid As Double, ByVal cdb As IntPtr, <MarshalAs(UnmanagedType.LPArray)> ByVal pic As Byte(), ByRef picLen As Integer, _
ByVal picCap As Integer, <MarshalAs(UnmanagedType.LPArray)> ByVal sig As Byte(), ByRef sigLen As Integer, ByVal sigCap As Integer) As Integer
End Function
End Class
|
|
|
|
|
Next time you get the StackOverflowException, I would check the stack trace. You will want to save this to a file somehow so that you don't have to try to look at it in the debugger. Look for a cycle of functions over and over and over and.... This will be the source of your stack overflow.
PS. Posting code is good. Posting too much code is bad. In general, I would aim for no more than 30 lines of code when possible. Any more than that and people will simply skip your question because they do not have the time to analyze that much code to help you.
|
|
|
|
|
I'm working on an app that utilizes a filesystemwatcher to detect for a particular type of file. When the watcher is running, everything is fine. The watcher correctly picks up new files.
However, the app needs to support being paused and restarted. So, if the app is paused, files are then copied into the directory and the watcher is restarted - it doesn't pick up the existing files even though they match the filter.
I realize the watcher wouldn't trigger the created or modified events, but is there a way to make the watcher to pick up these files, or do I just need to code around this? Just wanted to make sure I wasn't overlooking something with the filewatcher itself.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
The watcher will only do things it is designed for. It will not detect files that have been added while the watcher is paused.
Why pause the App? why not leave it running and just handle the events while the file copy operation is in progress.
system.io.filesystemwatcher[^]
|
|
|
|
|
I don't come up with the design requirements, I'm just tasked with "getting it done". Just checking to make sure that the filewatcher doesn't support this action. Thanks though.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Well, here's an alternative solution... Instead of pausing the FSW, pause the handler. When you get an event, check to see whether your handler is "paused"... If so, stick the event in a Queue instead. When unpausing, process the Queue first.
|
|
|
|
|
Admittedly, I've never heard of pausing a handler. Could you point me in the right direction?
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Something like this (pseudocode):
Class Watcher
Private System.IO.FileSystemWatcher
Private Bool IsPaused
Private Queue
Public Sub Pause()
IsPaused = true
End Sub
Public Sub UnPause()
While Queue is not empty
ProcessFSWEvent(next item in queue)
IsPaused = false
End Sub
Private Sub FileSystemWatcherEventHandler(sender, eventargs)
If IsPaused Then
Add eventargs to Queue
Else
ProcessFSWEvent(eventargs)
End Sub
Private Sub ProcessFSWEvent(eventargs)
Do whatever you'd normally do with the event
End Sub
|
|
|
|
|
I am currently tasked with building a question and answer faq for one of our top executives. Basic premise is that an employee can post an anonymous question through a web form, which will then save the question and the employee's reply email address to a SQL database and, after this, email our Assistant Chief.
To make things easier for our Assistant Chief and to keep him from having to connect to an internal site (all of this is behind our firewall), I would like to build an application that will accept emails from him so he can send answers from his iPhone or any other mobile device he checks his email through. This application would then take his answer and place it with the user's question, email the user the response and then, if the user has marked that the question can be posted to our internal intranet, post the question and answer for all to see. It will also have to remove the user's email address to keep the anonymity.
Am I chasing a pipe dream here or is it something that can be done? I need to put together a proposal in two weeks, so any help would be appreciated.
Thanks in advance.
|
|
|
|
|
If you need to have an emailing feature as you said, you should get in touch with your networking guys to provide you with a email address which you will then access through the application.
Another idea could be to have an admin section in the same website which will be accessible only to your chief. Now, there you can have a gridview/listview or something with the sorted list of messages. On clicking them, you can provide a page similar to the one we see while replying to the post here.
Once reply button is clicked, you can save the reply next to question and mail to concerned person through SMTP.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Maybe this might help ...
A POP3 Client in C# .NET[^]
Sounds like a "doable" project.
1) People can enter questions to management
2) Questions are forwarded to management for response
3) Management reponses via email
4) Response is forwarded to the anonymous user and possibly posted on a Intranet server.
Sounds cool ...
One thing for sure is that you will need a dedicated email account for the website to read/write emails from. Also, make sure that you "whitelist" the users that can respond to this email account, you don't want to process emails about Viagra. You will have to keep some sort of ID in the subject line so that when the response is processed from management, it gets posted to the correct question.
This project will keep you busy for a while.
|
|
|
|
|
Good ideas...I'm in the process of building on a similar idea. Your feedback will be the grounds for added feature sets.
modified on Wednesday, January 27, 2010 10:00 AM
|
|
|
|
|
Hi all.
Right first off - ive only just installed vb.net (2008), im well used to VB6, but never switched as i could get 6 to do everything i needed. so go easy on me! (assume i now nothing).
im doing a little project for fun, im building a tracking paintball gun. however im new to image processing so im looking for a little help.
What i need to do is to caputre an image from 2 webcams (set at an angle to each other to capture a wide image) at the same time, which cover the paintball field (they may overlap very slightly). I then need to stitch these 2 images together, and create some sort of array of colour values (or maybe i could make 2 arrays first and join them, probably easier)
I then need to somehow detect moving objects between this array, and the previous array(s)
i think some sort of edge detection / high pass filter would help too.
so the 2 main things i need help with are:
Image capture, and extracting colour information per pixel.
oh and the code needs to be efficient enough to do this at a frame rate of approx 10fps
if possible i dont want to use someone else's code to do this, i would like to work it from scratch
|
|
|
|
|
Well.
I try to display the datagridviewbuttoncell, acording to the value of the cell. But I can't succeed. I tried by the following ways.
I mean, suppose....
Private Sub DataGridView1_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEnter
Dim r1 As Integer = e.RowIndex
If Len(Trim(DataGridView1(1, r1).Value)) <> 0 Then
Dim BnCell As New DataGridViewButtonCell
DataGridView1(2, r1) = BnCell
Else
Dim TxtCell As New DataGridViewTextBoxCell
DataGridView1(2, r1) = TxtCell
End If
End Sub
So, like the above if the data is available in column(1), then column(2) of currentcell will be datagridviewbuttoncell
or else datagridviewtextboxcell
Any better ideas for me?
Thanks
|
|
|
|
|
I'm working on a utility to do a find replace operation on Word documents (2003 version not docx)
We've a version of this that uses automation, however it's too slow, and runs into problems with documents linked to excel, and containing macros (and anything else that causes messages to show).
I've got code sorted out that will do this finding and replacing the bytes in a byte array of the file (see below). This works perfectly as long as the length of the bytes I replace is the same as the length of the bytes I need to find. If I change the length of the file the document will no longer open in word.
When I make the change required manually (ie through MS Word), the byte length of the file doesn't change, so I'm assuming there must be a buffer somewhere in the file that is getting used.
Please give me feedback on how to update the file correctly.
Code:
(please excuse the rough nature of this code - I'm prototyping!)
(also DoReplace is based on code downloaded from T'Interweb. Can't remember where, but if its yours, thanks!)
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim find As String = "String To Find"
Dim replace As String = "String To Replace"
Dim path As String = "c:\InputPath.doc"
Dim updatedpath As String = "c:\OutputPath.doc"
Dim encoding As System.Text.Encoding = System.Text.Encoding.GetEncoding(1252)
Dim fi As New FileInfo(path)
Dim fs As New FileStream(path, FileMode.Open)
Dim bytes(CInt(fs.Length)) As Byte
fs.Read(bytes, 0, CInt(fs.Length))
fs.Close()
Dim newBytes() As Byte = DoReplace(bytes, encoding.GetBytes(find), encoding.GetBytes(replace))
fs = New FileStream(updatedpath, FileMode.Create)
fs.Write(newBytes, 0, newBytes.Length)
fs.Close()
End Sub
Public Function DoReplace(ByVal bytes As Byte(), ByVal findBytes As Byte(), ByVal replaceBytes() As Byte) As Byte()
Dim newBytes As New Generic.List(Of Byte)
Dim ndx As Integer = 0
For x As Integer = 0 To bytes.Length - 1
' bytes is the original files bytes
If bytes(x) = findBytes(ndx) Then
' findBytes is a byte[] from the"find" string
If ndx = (findBytes.Length - 1) Then
For y As Integer = 0 To replaceBytes.Length - 1
'replaceBytes is a byte[] from the "replace" string
newBytes.Add(replaceBytes(y))
Next
ndx = 0
Else
ndx += 1
End If
Else
If ndx > 0 Then
For y As Integer = 0 To ndx - 1
newBytes.Add(findBytes(y))
Next
End If
ndx = 0
newBytes.Add(bytes(x))
End If
Next
Return newBytes.ToArray
End Function
End Class
|
|
|
|
|
You need to understand the structure and format of a Word file before you can reliably change anything. Changing a number of bytes in the file without knowing exactly what those bytes may be used for is a recipe for disaster.
|
|
|
|
|
Yeah - got it to work after a fashion - by adjusting the empty bytes that are found after the main content of the doc. However handing headers footers and everything else is (as you say) horrible.
I think if I had another couple of years I might take this further, however, I'm off Xmas shopping instead!
|
|
|
|
|
I know it will run somewhat slower, however ...
How about using Office Automation to open each doc, do the string substitution and save the resulting doc. We did some work recently that thankfully involved docs saved in WordML format. Resaving in the middle of your process as WordML may make the substitution easier.
|
|
|
|
|
The '95 versions didn't save an entire document, but they appended changes to the last part of the document. That's a bit faster than writing the entire document anew.
You can find the documentation through the link below. Be warned though, there's dragons there
http://download.microsoft.com/download/0/B/E/0BE8BDD7-E5E8-422A-ABFD-4342ED7AD886/Word97-2007BinaryFileFormat(doc)Specification.pdf
I are Troll
|
|
|
|
|