Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Sep 2006
    Messaggi
    181

    [VB6] gestione dei file ini

    Errore di run-tim '453'; Impossibile trovare il punto di ingresso della DLL GetPrivateProfileStringA in kernel 32

    Salve a tutti,
    sto cercando di imparare a gestire i file ini con VB6 e per questo ho letto qualche procedura per tal fine. In pratica ho provato a fare un'applicazione di prova con un modulo che permettesse la gestione di un file ini.
    il modulo iniModule.bas e' il seguente:

    Public Declare Function GetPrivateProfileString Lib "kernel32" Alias _
    "GetPrivateprofileStringA" (ByVal lpApplicationName _
    As String, ByVal lpKeyName As Any, ByVal lpDefault _
    As String, ByVal lpReturnedString As String, ByVal _
    nSize As Long, ByVal lpFileName As String) As Long

    Public Declare Function WritePrivateProfileString Lib "kernel32" Alias _
    "WritePrivateProfileStringA" (ByVal lpApplicationName _
    As String, ByVal lpKeyName As Any, ByVal lpString As Any, _
    ByVal lpFileName As String) As Long



    Public Function sGetINI(sINIFile As String, _
    sSection As String, sKey _
    As String, sDefault As String) As String
    Dim sTemp As String * 256
    Dim nLenght As Integer
    sTemp = Space$(256)
    nLenght = GetPrivateProfileString(sSection, _
    sKey, sDefault, sTemp, 255, sINIFile)
    sGetINI = Left$(sTemp, nLenght)
    End Function

    Public Sub writeINI(sINIFile As String, sSection As String, _
    sKey As String, sValue As String)
    Dim n As Integer
    Dim sTemp As String
    sTemp = sValue
    For n = 1 To Len(sValue)
    If Mid$(sValue, n, 1) = vbCr _
    Or Mid$(sValue, n, 1) = vbLf Then
    Mid$(sValue, n) = " "
    End If
    Next n
    n = WritePrivateProfileString(sSection, _
    sKey, sTemp, sINIFile)
    End Sub

    mentre il metodo che usufruisce di tale modulo e':
    Private Sub Leggi_Click()
    Dim iniFile, section As String
    Dim str_val As String * 50
    Dim val_ritorno As Long
    iniFile = App.Path & "\prova.ini"
    section = "Folder"
    str_val = "prova"
    val_ritorno = GetPrivateProfileString(section, _
    str_val, "", str_val, Len(str_val), _
    iniFile)
    If (val_ritorno = 0) Then
    MsgBox "errore"
    Else
    outfile.Caption = Trim(str_val)
    End If
    End Sub

    il file prova.ini e' fatto in questo modo:
    [Folder]
    ;cartella di prova
    provafolder = '.\prova'

    [Files]
    ;file di prova
    provafile = '.\primo.txt'

    Qualcuno pu; aiutarmi a capire come risolvere l'errore scritto in testa a questo post
    Grazie in anticipo

  2. #2
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480
    Succede perche' hai scritto

    "GetPrivateprofileStringA"

    mentre deve essere

    "GetPrivateProfileStringA"

    con la P maiuscola in Profile

  3. #3
    Utente di HTML.it
    Registrato dal
    Sep 2006
    Messaggi
    181
    Si infatti era la p che non permetteva l'accesso alla DLL.
    Però c'è una cosa che non mi è chiara.

    Supponiamo di sostituire il metodo che richiama la funzione di lettura dal file ini con il seguente(per comodità ho visualizzato i valori ch emi intereessano con una MsgBox):


    Dim iniFile, section As String
    Dim str_dir As String * 50
    Dim str_file As String * 50
    Dim val_ritorno As Long
    Dim str_out As String

    iniFile = App.Path & "\prova.ini"
    section = "Files"
    str_file = "provafile"
    val_ritorno = GetPrivateProfileString(section, _
    str_file, "", str_file, Len(str_file), _
    iniFile)
    If (val_ritorno = 0) Then
    outfile.Caption = "errore"
    Else
    'la funzione Trim elimina gli spazi superflui
    str_out = Trim(str_file)
    outfile.Caption = str_out
    MsgBox "str_out = " & str_out
    MsgBox "Len(str_out) = " & Len(str_out)
    End If

    section = "Folder"
    str_dir = "provafolder"
    val_ritorno = GetPrivateProfileString(section, _
    str_dir, "", str_dir, Len(str_dir), _
    iniFile)
    If (val_ritorno = 0) Then
    outfile.Caption = "errore"
    Else
    'la funzione Trim elimina gli spazi superflui
    str_out = Trim(str_dir)
    outfile.Caption = str_out
    MsgBox "str_out = " & str_out
    MsgBox "Len(str_out) = " & Len(str_out)
    End If

    str_out = "\" & Trim(str_dir) & "\" & Trim(str_file)
    MsgBox "str_out = " & str_out
    MsgBox "Len(str_out) = " & Len(str_out)

    e il file .ini modificato come segue:
    [Folder]
    ;cartella di prova
    provafolder = 'prova'

    [Files]
    ;file di prova
    provafile = 'primo.txt'

    I valori che mi ritornano le varie MsgBox mi risultano poco chiari, infatti, i relativi valori ritornati da ogni MsgBox sono:

    str_out = primo.txt 'OK
    Len(str_out) = 10 '?
    str_out = prova 'OK
    Len(str_out) = 11 '?
    str_out = \prova '?
    Len(str_out) = 23 '?

    Ovviamente questo può comportarmi problemi in seguito ad una stesura di un dato codice se i valori non sono proprio quelli che cerco. Come potrei risolvere il problema?
    Grazie in anticipo


    P.S. : in altri termini desidero che l'ultimo str_out sia uguale a \prova\primo.txt e che la sua lunghezza sia quella effettiva

  4. #4
    Utente di HTML.it
    Registrato dal
    Sep 2006
    Messaggi
    181
    Problema risolto in parte

    nelle chiamate della Get relative al valore di ritorno inserivo la stringa str_file ed str_dir al posto della stringa di ritorno, quindi la dimensione della stringa di ritorno era fissata già precedentemente quando inizializzavo tali variabili. Allora ho usato due variabili diverse sempre di tipo stringa
    Dim str_out_file As String
    Dim str_out_dir As String
    ed inserite in posizione stringa di ritorno
    Il problema è che le due dichiarazioni fatte considerano stringhe di lunghezza 0 per cui le ho moltiplicate per un valore arbitrario (50).
    Facendo la Trim però, non vengono tolti gli spazi vuoti ma restano due stringhe di lunghezza 50 e quella definitiva che forma \directoty\file è una stringa di 102, se si considera anche "\".
    Come fare?

  5. #5
    Utente di HTML.it
    Registrato dal
    Sep 2006
    Messaggi
    181
    Infine ce l'ho fattaaaaaaaaaaaaa
    La funzione split è davvero potente

    Dim iniFile, section As String
    Dim val_ritorno As Integer
    Dim str_file As String
    Dim str_dir As String
    Dim str_out_file As String * 50
    Dim str_out_dir As String * 50
    Dim dir
    Dim file
    Dim out_dir As String
    Dim out_file
    Dim str_out As String

    iniFile = App.Path & "\prova.ini"
    section = "Folder"
    str_dir = "provafolder"
    val_ritorno = GetPrivateProfileString(section, _
    str_dir, "", str_out_dir, Len(str_out_dir), _
    iniFile)
    If (val_ritorno = 0) Then
    outfile.Caption = "errore"
    Else
    dir = Split(str_out_dir, "")
    out_dir = dir(0)
    End If

    section = "Files"
    str_file = "provafile"
    val_ritorno = GetPrivateProfileString(section, _
    str_file, "", str_out_file, Len(str_out_file), _
    iniFile)
    If (val_ritorno = 0) Then
    outfile.Caption = "errore"
    Else
    file = Split(str_out_file, "")
    out_file = file(0)
    End If

    str_out = "\" & out_dir & "\" & out_file
    MsgBox "str_out = " & str_out
    MsgBox "Len(str_out) = " & Len(str_out)

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.