473,219 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,219 software developers and data experts.

How to use API writefile in vb.net

db
I am trying to convert an API writefile instruction from a vb6 app to a
vb.net app. I cannot determine how to get the instruction to execute. I do
not get any runtime errors, however the data is not written to the file. I
want to use the API because I need to write the data quickly and synchrously
to a file. In the real app I will be writting ~ 10Mbytes every 5 seconds.

ANY help would be greatly appreciated.

Code follows:
-----

Public Class Form1
Inherits System.Windows.Forms.Form

Public Const GENERIC_READ As Long = &H80000000
Public Const GENERIC_WRITE As Long = &H40000000
Public Const FILE_FLAG_WRITE_THROUGH As Long = &H80000000
Public Const FILE_FLAG_NO_BUFFERING As Long = &H20000000
Public Const OPEN_EXISTING As Long = 3
Public Const CREATE_ALWAYS As Long = 2
Public Const CREATE_NEW As Long = 1
Public Const FILE_SHARE_READ As Long = &H1
Public Const FILE_SHARE_WRITE As Long = &H2
Public Const MB_OKCANCEL As Long = &H1
Public Const MB_ICONHAND As Long = &H10

Public Declare Function WriteFile Lib "kernel32" (ByVal hFile As
Integer, ByVal lpBuffer As Integer, _
ByVal nNumberOfBytesToWrite As Integer, ByVal
lpNumberOfBytesWritten As Integer, _
ByVal lpOverlapped As Integer) As Integer
Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA"
(ByVal lpFileName As String, _
ByVal dwDesiredAccess As Integer, ByVal dwShareMode As
Integer, ByVal lpSecurityAttributes As Integer, _
ByVal dwCreationDisposition As Integer, ByVal
dwFlagsAndAttributes As Integer, _
ByVal hTemplateFile As Integer) As Integer
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As
Short) As Short

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'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.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Name = "Form1"
Me.Text = "Form1"

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim lSize As Integer
Dim iDetailedTimingIndex As Short
Dim lApiTimingMissHandle As Integer
Dim lApiReturn As Integer
Dim bytArray2(1024) As Byte
Dim sApiTimingMissFileName As String = "e:\apibin.test"
Dim overlap As Integer = 0

lSize = 512

lApiTimingMissHandle = CreateFile(sApiTimingMissFileName,
GENERIC_WRITE, FILE_SHARE_READ _
Or FILE_SHARE_WRITE, 0&, CREATE_ALWAYS,
FILE_FLAG_NO_BUFFERING, 0)

WriteFile(lApiTimingMissHandle, bytArray2(0), lSize, lApiReturn,
overlap) ''CBCount& * 2, Ret, ByVal 0&
If lApiReturn <> lSize Then
MsgBox("Error writing error information to binary error file
...." & vbCrLf & _
"Requested = " & lSize & vbCrLf & _
"Written = " & lApiReturn)
End If

CloseHandle(lApiTimingMissHandle)

End Sub
End Class
Jul 21 '05 #1
0 2818

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: dim | last post by:
Copied directly from exaple book but not working.... All i get is an empty 0 byte file Call to GetLastError directly after the call to WriteFile returns 0 (NO_ERROR) but no data sees to be written...
1
by: Chuck Rittersdorf | last post by:
Hi There I am having a problem using the win32 API from VB6. I am trying to send a command string to a printer(zebra TLP 2742) on LPT1 using the folowing API functions CreateFile and...
1
by: Paul | last post by:
Hi, I am extending an existing MFC app to use Unicode (for a Japanese version of the interface elements). The app's purpose is to control a peripheral device through the serial port, and the...
2
by: Jerry J | last post by:
I am using Response.WriteFile to send file streams back to web clients. My question is this: Can I use Response.WriteFile(SomeFilePath) for any size file? Will it handle chunking the data...
2
by: David Union | last post by:
Hi. I'm posting this here because I don't know exactly what the best group is. This is for an aspx page with Visual Basic as the code-behind page. I am doing very simple code... in the middle...
5
by: Tim Greenfield | last post by:
Hi, I have a problem I'm hoping is not too unusual. I'm trying to push a large file (50MB) out to the client from an ASP page. The reason I'm using an ASP page is so I can start the reading at a...
8
by: Scott C. Reynolds | last post by:
I want to serve a PDF right to a web page (cannot link browser directly to PDF file). Stumbled across Response.WriteFile this morning. On my machine (XP Pro) this worked fine: private void...
11
by: Random | last post by:
I have tried all the Response methods I can think of (WriteFile, BinaryWrite, OutputStream) to write the byte array of a pdf file to the response. The result looks like it's trying, it comes up as...
3
by: Buddy Ackerman | last post by:
I'm trying to write files directly to the client so that it forces the client to open the Save As dialog box rather than display the file. On some occasions the files are very large (100MB+). On...
3
by: MJP | last post by:
I have a button which kicks off the generation of a report after which the file will be downloaded. The report generation can take a long time, so client side onclick event of the button also...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.