Murlex
Murlex

Reputation: 239

Preventing WritePrivateProfileString going to the registry

Is there any way to disable WritePrivateProfileString from writing to the registry and instead use the ini file that we provide to it? I see from the MSDN that you can disable file writes and exclusively use Registry, but not vice versa. I want to keep my program portable, at the same time, use standard win apis to store configuration data (instead of creating something new)..

Thanks

Upvotes: 2

Views: 1734

Answers (3)

Stefan
Stefan

Reputation: 43575

I assume you're using MFC, since only that has its own versions of WritePrivateProfileString and similar functions. When you compile your code with newer Versions of MFC, you're automatically using the MFC equivalents of those APIs, and MFC simply uses the information you pass to the 'API's and writes/reads them from the registry. To avoid this, don't write

WritePrivateProfileString

in your code but

::WritePrivateProfileString

instead.

Upvotes: 1

Carey Gregory
Carey Gregory

Reputation: 6846

If your ini file is getting mapped to the registry, then you've apparently added it to HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\IniFileMapping. Delete that entry and your ini file will end up where you expect it. Your line of code works as expected on my machine.

MSDN Link

Upvotes: 3

user2058002
user2058002

Reputation:

Yes. Hook it (which you can do easily with a library such as Microsoft Detours).

Upvotes: 0

Related Questions