Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

registery

when we use setregisterkey("myplace");
we get a place under HKEY_CURRENT_USER, Software,
myplace, "app title".

question 1, can I make the last dir "app title"  any arbitrary text
without changing the actual app.title. ?

question 2, this is under current user, so what if some other user
logs in and want to access this  same information ?
How to write to  a common place for the machine for all users ?

0
hasmet
Asked:
hasmet
  • 2
1 Solution
 
anichiniCommented:
1) use CWinApp:m_pszProfileName - be sure to put this code AFTER the call to SetRegistryKey:

//First free the string allocated by MFC at CWinApp startup.
//The string is allocated before InitInstance is called.
free((void*)m_pszProfileName);
//Change the name of the .INI file.
//The CWinApp destructor will free the memory.
m_pszProfileName=_tcsdup(_T("d:\\somedir\\myini.ini"));

Note   If you assign a value to m_pszProfileName, it must be dynamically allocated on the heap. The CWinApp destructor calls free( ) with this pointer. You many want to use the _tcsdup( ) run-time library function to do the allocating. Also, free the memory associated with the current pointer before assigning a new value. For example:

2) You want to put stuff that's common to all users in HKEY_LOCAL_MACHINE/Software/yourplace/profile. Unfortunately, MFC doesn't have any handy utility routines for accomplishing this, so you have to use the API registry functions - look in the SDK docs for RegOpenKeyEx and it's companions.



0
 
anichiniCommented:
Oh, and I realize the code says "change the name of the INI file" but trust me, it'll affect the registry key!

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now