Solved

WritePrivateProfileString Function

Posted on 2001-08-11
10
261 Views
Last Modified: 2008-01-16
I am attempting to update the initialization file that I use for my ACCESS database application.  I identify it in the shortcut and use the SystemDB= line to strip off the location of the back-end database.mdb so that a ReAttach routine knows where to refresh the links to.  This is done routinely whenever a new front-end is sent out.

As a result of new servers being installed and the systems engineers renaming the servers with a slighly different naming convention I just test for the ability to read a file at the old location and if unsuccessful then update the .ini file on the PC c:\winnt location with the new naming convention and trigger the reattachment routine.

Problem is I am having a hard time getting the Declaration and call to the function correct.  I need a little help.

app.ini file

[Options]
SystemDB=\\GH9010_1\data\system.mdw

I want to change the underscore to a hyphen: -

What I have done so far:

General Declarations
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpAppName, ByVal lpKeyName, ByVal lpString, ByVal lpFileName) As Long


Dim xReturnedIniWriteValue As Long

xReturnedIniWriteValue = WritePrivateProfileString("[Options]", "SystemDB", "\\GH9010-1\data\system.mdw", "app.ini")

After executing the above statement I get a Dr. Watson error and system crashes.

Anyone awake out there.

Bob Scriver


0
Comment
Question by:Bob Scriver
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 2

Expert Comment

by:BozzoCage
ID: 6377011
didn't checked, but I'm quite sure you shouldn't use backslash with API's. Replace each \ with \\
...SystemDB", "\\\\GH9010-1\\data\\system.mdw", ...


0
 
LVL 3

Author Comment

by:Bob Scriver
ID: 6377142
I don't understand how that could be.  The parameter is just a string represenation of exactly what I want to be placed behind the SystemDB= in the [Options] section of the app.ini.  To put double backslashes will just place exactly that in the app.ini.

Does the API call analyze the string going to be written before it writes it? What is the final product of the write call.  four backslashes or two?   It must be two to represent the network representation of where the system.mdw file is located.

Bob Scirver
0
 
LVL 3

Author Comment

by:Bob Scriver
ID: 6377171
I have solved my own problem.  Amazing what 5 hours of sleep will do for one's logic.  

The declaration statement was not appropriate for 32-bit NT.  
16-bit:


32-bit:
Declare Function apiWritePrivateProfileString Lib _
         "kernel32" Alias "WritePrivateProfileStringA"
         (ByVal lpApplicationName As String, ByVal         lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
0
 
LVL 3

Author Comment

by:Bob Scriver
ID: 6377172
I have solved my own problem.  Amazing what 5 hours of sleep will do for one's logic.  

The declaration statement was not appropriate for 32-bit NT.  
16-bit:


32-bit:
Declare Function apiWritePrivateProfileString Lib _
         "kernel32" Alias "WritePrivateProfileStringA"
         (ByVal lpApplicationName As String, ByVal         lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
0
 
LVL 3

Author Comment

by:Bob Scriver
ID: 6377181
Sorry I wasn't done with the explaination.  Fatfingered the enter key by mistake.

There is a difference between the 16-bit and 32-bit API Declaration statements. The following link to MSKB will list the common calls and their appropriate conversions.

http://support.microsoft.com/support/kb/articles/Q147/7/81.asp?LN=EN-US&SD=gn&FR=0&qry=writeprivateprofilestring&rnk=1&src=DHCS_MSPSS_gn_SRCH&SPR=ACC97 

See WritePrivateProfileString near the bottom.

After updating my Declaration statement with the changes it all worked correctly.  I will leave this question posted for a while so others may benefit from what I have found but then I will be deleting it.  

BozzoCage:  Thanks for the comeback but that was not the answer.  As I stated earlier the \\ were just string characters and shouldn't have been analyzed by the API  call.

Bob Scriver  



0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 2

Expert Comment

by:BozzoCage
ID: 6377190
You'r right. \\ shouldn't be analyzed by APIs. I do remember that somewhere it is... I read about this, so I blindly guessed here with no real testing of your example.

I'm glad you figured this out yourself :-)

Best wishes,
  BozzoCage
0
 
LVL 7

Expert Comment

by:Nosterdamus
ID: 6377616
Hi scriverb,

I posted this http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20167228 request at CS TA to PAQ this question and return the question point back to you.

Congrats for solving the problem by your self.

Nostedamus
0
 
LVL 3

Author Comment

by:Bob Scriver
ID: 6377633
Nostedamus:
Thanks for the assistance.  I didn't want to delete the question because I felt that it might be helpful to others.  Thanks again.

Bob Scriver
0
 
LVL 7

Expert Comment

by:Nosterdamus
ID: 6377634
;-)
0
 
LVL 1

Accepted Solution

by:
Moondancer earned 0 total points
ID: 6378031
Thank you all.  Rather than deleting this, I will refund points and move this to our PAQ so others can find the excellent help within this question.
Moondancer
Community Support Moderator @ Experts Exchange
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now