views:

61

answers:

2

I am writing a C# program in Microsoft Visual Studio 2010 that stores some information inside of the local user settings like so:

Properties.Settings.Default.userActive.Add(connection.Active);  
Properties.Settings.Default.Save();

I also have a Visual C++ application that would like to read these stored user settings. Is it possible for my Visual C++ application to read the C# application's user settings?

Similarly, how would I go about accessing the local user settings directory in C++?

A: 

You can make the c# class COM callable through .NET COM Interoperability and COM callable wrappers.

Check out http://blogs.msdn.com/b/deeptanshuv/archive/2005/06/26/432870.aspx

Mamta Dalal
I looked into your suggestion but ran into another impediment. Even if I were to try to call C# functions from C++, I cannot find an easy way to read a separate program's user settings from C#. It seems that Properties.Settings.Default saves/read from a Folder that seems pretty unique to the calling program.As far as a visual C++ implementation one of my friends suggested using something along the lines of: char path[250]; ExpandEnvironmentStrings("%userprofile%",path,250);But how could figure out what I need to append to that path to make it to the correct user.config?
hobodbobo
A: 

It seems like there is no Microsoft sanctioned way to do what I am attempting to do. In case anyone else comes across this I will briefly explain what I've decided to do. Here was a helpful guide. I am ultimately just populating an xml file from the C# and placing it within the users AppData folder located at:

Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

I am then using my C++ to locate it using:

TCHAR myCharArray[MAX_PATH];
SHGetFolderPath(NULL,CSIDL_LOCAL_APPDATA,(HANDLE)-1,SHGFP_TYPE_DEFAULT, myCharArray);

I then parse the XML file using C++ and read in the settings. This was a much more manual process than I would have liked, and leaves room for a lot of error unfortunately. Anyways, thanks everyone and good luck!

hobodbobo
Also note if you are using std::cout to print myCharArray and debug SHGetFolderPath: TCHAR sometimes uses Unicode encoding rather than multi byte character set in which case you would need to use std::wcout. Wasted a good half hour of my life, haha.
hobodbobo