API GetPrivateProfileString and WritePrivateProfileString don't work. 
Author Message
 API GetPrivateProfileString and WritePrivateProfileString don't work.

This code example doesn't works. It seems to me that the recognizing of the
string at buffer level fails. Does anyone know why?

 '---------------------------------------------------------------------
 Public Const INI_FILE_NAME = "D:\Andrea\Axia\Dde\DDEClient.ini"
 Public Const ABSENT = "Absent"

 Public g_sDSNConnection As String

 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

 Sub Main()

       Dim lResult As Long

       lResult = WritePrivateProfileString("Database", "DSN",
"ConnectionString",
  NOME_INI_FILE)

       g_sDSNConnection = String$(255, Chr(0))

       lResult = GetPrivateProfileString("Database", "DSN", ABSENTE,
 g_sDSNConnection, Len(g_sDSNConnection) + 1, INI_FILE_NAME)

       MsgBox g_sDSNConnection

 End Sub



Tue, 26 Nov 2002 03:00:00 GMT  
 API GetPrivateProfileString and WritePrivateProfileString don't work.
Try these wrappers

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
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

Function WriteIniString(lpAppName As String, lpKeyName As String, lpString
As String, lpFileName As String) As Integer
    Dim Status%
    Status% = WritePrivateProfileString(lpAppName, lpKeyName, lpString,
lpFileName)
    WriteIniString = Status%
End Function

Function GetIniString(lpAppName As String, lpKeyName As String, lpDefault As
String, nSize As Integer, lpFileName As String) As String
    Dim RetLen%, lpReturnedString As String

    lpReturnedString = Space$(nSize)
    RetLen% = GetPrivateProfileString(lpAppName, lpKeyName, lpDefault,
lpReturnedString, nSize, lpFileName)
    GetIniString = Left$(lpReturnedString, RetLen%)
End Function



Tue, 26 Nov 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. GetPrivateProfileString, GetPrivateProfileInt, WritePrivateProfileString API call problem

2. Can't get GetPrivateProfileString API to work

3. API calls of winamp don't work in vb 6

4. MovePrevious don't work but the MoveNext work's fine

5. WritePrivateProfileString won't work

6. WritePrivateProfileString Doesn't Work

7. Script works, script don't work

8. Need help with WritePrivateProfileString and GetPrivateProfileString

9. Using WritePrivateProfileString and GetPrivateProfileString

10. Need help with WritePrivateProfileString and GetPrivateProfileString

11. GetPrivateProfileString and WritePrivateProfileString functions

12. VB 3.0: Help with GetPrivateProfileString and WritePrivateProfileString

 

 
Powered by phpBB® Forum Software