Autor
|
Tema: problema escribiendo archivo vb6 api(caracteres raros) (Leído 3,821 veces)
|
z_ane_666
Desconectado
Mensajes: 64
|
buenos dias ,he implementado un code para escribir contenido en un archivo (que ha de estar creado con el nombre ajhgk.txt y en la c:\ antes de usar el programa), realmente funciona, pero escribe caracteres extraños Option Explicit Const MOVEFILE_REPLACE_EXISTING = &H1 Const FILE_ATTRIBUTE_TEMPORARY = &H100 Const FILE_BEGIN = 0 Const FILE_SHARE_READ = &H1 Const FILE_SHARE_WRITE = &H2 Const CREATE_NEW = 1 Const OPEN_EXISTING = 3 Const GENERIC_READ = &H80000000 Const GENERIC_WRITE = &H40000000 Const CREATE_ALWAYS As Long = 2 Const FILE_ATTRIBUTE_ARCHIVE As Long = &H20 Const GENERAL_WRITE = 1073741824
Private Declare Function SetFilePointer Lib "kernel32.dll" (ByVal hfile _ As Long, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh _ As Long, ByVal dwMoveMethod As Long) As Long Private Declare Function WriteFile Lib "kernel32" (ByVal hfile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Any) As Long Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long Private Declare Function ReadFile Lib "kernel32" (ByVal hfile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Any) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function GetFileSize Lib "kernel32" ( _ ByVal hfile As Long, _ lpFileSizeHigh As Long) As Long Private Sub Command1_Click()
Dim sSave As String, hOrgFile As Long, hNewFile As Long, bBytes() As Byte Dim sTemp As String, nSize As Long, Ret As Long Dim charbuffer As String charbuffer = "Anonymous!" hNewFile = CreateFile("c:\ajhgk.txt", GENERIC_WRITE, FILE_SHARE_READ, ByVal 0&, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, 0) WriteFile hNewFile, charbuffer, 10, Ret, ByVal 0&
CloseHandle hNewFile End Sub
en vez de escribir Anonymous! escribe ¼NÇT:# espero que me ayuden saludos
|
|
|
En línea
|
|
|
|
$Edu$
Desconectado
Mensajes: 1.842
|
Usas el api por algo en especial?
|
|
|
En línea
|
|
|
|
z_ane_666
Desconectado
Mensajes: 64
|
felizmente hace poco halle la solución, era pasar por byval el buffer, aca el codigo Option Explicit Private Const GENERIC_READ = &H80000000 Private Const GENERIC_WRITE = &H40000000 Private Const FILE_SHARE_READ = &H1 Private Const FILE_SHARE_WRITE = &H2 Private Const OPEN_ALWAYS = 4 Private Const FILE_BEGIN = 0
Private Declare Function SetFilePointer Lib "kernel32.dll" (ByVal hfile _ As Long, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh _ As Long, ByVal dwMoveMethod As Long) As Long Private Declare Function WriteFile Lib "kernel32" (ByVal hfile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Any) As Long Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long Private Declare Function ReadFile Lib "kernel32" (ByVal hfile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Any) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function GetFileSize Lib "kernel32" ( _ ByVal hfile As Long, _ lpFileSizeHigh As Long) As Long Private Sub Command1_Click()
Dim sSave As String, hOrgFile As Long, hNewFile As Long, bBytes() As Byte Dim sTemp As String, nSize As Long, Ret As Long Dim charbuffer As String charbuffer = "Anonymous!" hNewFile = CreateFile("c:\ajhgk.txt", GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_ALWAYS, 0, 0) WriteFile hNewFile, ByVal charbuffer, 10, Ret, ByVal 0&
CloseHandle hNewFile End Sub
Disculpen por desviar el tema, pero creo que es mas comodo usar las funciones de visual basic . lo de arriba lo postee ya que las funciones de vb no escriben archivos de manera secuencial, sino linea por linea (caso append) y decici usar el api, pero veo que es complicadito... ¿alguna idea de poder hacer que la salida de append, la haga concatenada y no por linea a linea? saludos
|
|
|
En línea
|
|
|
|
raul338
Desconectado
Mensajes: 2.633
La sonrisa es la mejor forma de afrontar las cosas
|
No recuerdo exactamente cual era el metodo que lo hacia sin poner salto de linea, Print lo hace, creo que era Put o Write
|
|
|
En línea
|
|
|
|
x64core
Desconectado
Mensajes: 1.908
|
bueno yo mas o menos tenia el mismo problemas hace un tiempo pues lo que puedes hace es eso, concatenar las cadenas creo que tendras que obtener primero el valor de la cadena y luego unirla con la nueva cadena para que el resultado quede asi: ABCDEFG y no asi: A B C D E F pero aun asi, si lo haces asi es vergonzoso
|
|
|
En línea
|
|
|
|
|
Mensajes similares |
|
Asunto |
Iniciado por |
Respuestas |
Vistas |
Último mensaje |
|
|
Pasar caracteres raros a texto normal
Dudas Generales
|
GN1000
|
8
|
7,821
|
28 Agosto 2013, 22:24 pm
por Esgrimidor
|
|
|
[Duda] Ayuda archivo con caracteres raros... D;
« 1 2 »
Programación Visual Basic
|
Psyke1
|
10
|
5,131
|
25 Febrero 2011, 18:49 pm
por Edu
|
|
|
Problema escribiendo un archivo en Python
Scripting
|
Arnau27
|
7
|
4,993
|
8 Enero 2012, 12:46 pm
por Arnau27
|
|
|
Error escribiendo en un archivo de texto C#
.NET (C#, VB.NET, ASP)
|
The_Saint
|
2
|
3,692
|
3 Mayo 2013, 22:59 pm
por The_Saint
|
|
|
Escribiendo un struct en un archivo en binario
Programación C/C++
|
skan
|
2
|
2,799
|
13 Agosto 2013, 22:04 pm
por skan
|
|