kernel32 String and Visual Basic

I have a legacy custom application written in VB that uses an ODBC connection to an Oracle dbs. The dbs is set in an .ini file, but I'm learning that the app doesn't always check the .ini file. There is a custom function in the app as follows, and I think this is storing the dbs string somewhere.

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

My problem is that the application is set up using the dev dbs. I'm trying to switch to the test environment, and I've updated my .ini file, but it's not even checking it. I can rename the file and nothing happens. If I could determine where this private profile string is stored and reset that, maybe I can get it to check the .ini file again. Can anyone please help me understand more about the kernel32 library and custom functions using it?
                        Thanks!
oneDayAtaTimeAsked:
Who is Participating?
 
Martin LissOlder than dirtCommented:
BTW, here is a description of the parameters from the API Guide which I believe you can download from here.

· lpAppName
Points to a null-terminated string that specifies the section containing the key name. If this parameter is NULL, the GetPrivateProfileString function copies all section names in the file to the supplied buffer.

· lpKeyName
Pointer to the null-terminated string containing the key name whose associated string is to be retrieved. If this parameter is NULL, all key names in the section specified by the lpAppName parameter are copied to the buffer specified by the lpReturnedString parameter.

· lpDefault
Pointer to a null-terminated default string. If the lpKeyName key cannot be found in the initialization file, GetPrivateProfileString copies the default string to the lpReturnedString buffer. This parameter cannot be NULL.
Avoid specifying a default string with trailing blank characters. The function inserts a null character in the lpReturnedString buffer to strip any trailing blanks.
Windows 95: Although lpDefault is declared as a constant parameter, Windows 95 strips any trailing blanks by inserting a null character into the lpDefault string before copying it to the lpReturnedString buffer.
Windows NT: Windows NT does not modify the lpDefault string. This means that if the default string contains trailing blanks, the lpReturnedString and lpDefault strings will not match when compared using the lstrcmp function.

· lpReturnedString
Pointer to the buffer that receives the retrieved string.

· nSize
Specifies the size, in characters, of the buffer pointed to by the lpReturnedString parameter.

· lpFileName
Pointer to a null-terminated string that names the initialization file. If this parameter does not contain a full path to the file, Windows searches for the file in the Windows directory.
0
 
Martin LissOlder than dirtCommented:
lpFileName should be the path to the ini file. What does lpFileName contain?
0
 
oneDayAtaTimeAuthor Commented:
MartinLiss,
    Thanks for the info! That helps a lot! I'm still flying somewhat blind, though, because my work computer is locked down and I can't download that API guide! I'll have to get it from home. Can you tell me where these parameters are saved? I've determined how to put the .ini file where I need it to be. But my app saves the username using this API. My issue now is that I'm putting the app on a locked-down Citrix server, and I think the server isn't allowing access to wherever this is writing to. If I knew where I'm trying to write, I could ask the Citrix guy to allow permissions there. Any ideas?
                                Thanks!
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Martin LissOlder than dirtCommented:
I'm not sure I understand what you are asking because the parameters are not 'saved' but rather they are values that you assign. Do a Find in your code for GetPrivateProfileString and show me what you find.


-------------------------------------------------------------------------------------------------------------------------------
My Articles:
Using the VB6 DebuggerAutomatic Insertion of Procedure Names
A Textbox ActiveX Control That Limits Input to NumbersSpell Check a Textbox
Improved Formatting TagsConditional Compilation

Marty - MVP 2009, 2010, 2011
0
 
oneDayAtaTimeAuthor Commented:
Thanks, Marty. I think I've got a clue now. I was able to download the API Guide, and learned I was missing the whole concept! I thought the .ini file read/write was related, but different from this API. When I read the description from the guide, "The WritePrivateProfileString function copies a string into the specified section of the specified initialization file", I realized that they're both working together! DOH!

I also figured out my issue. My .ini file was in a place where the Citrix environment won't allow writing, so my user IDs were not being saved. I've moved it to a writable place, and now it seems to be working properly. Thanks for the help!
                                      Joyce
0
 
Martin LissOlder than dirtCommented:

You're welcome and I'm glad I was able to help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.