473,503 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2828

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

Similar topics

4
8657
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
16683
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
4429
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
3968
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
4149
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
3460
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
5760
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
11332
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
6296
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
10389
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...
0
7271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6979
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5570
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4998
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
373
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.