Accessing C# user settings from a C++ Application - c#

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++?

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!

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

Related

How to execute open office cal (macro) in asp.net core application

I am developing asp.net core application that downloads some excel files and executing macro on it.
Macro is performing some data validation and data formatting and generating new excel file. I need to save this file in a specific folder on the server.
I have hosted this application on centos 7 so obviously Microsoft interop service will not work. So, I have to execute macro using open office.
If anyone can help then it will be very much appreciated.
As you said, COM interop will not work on CentOS, so you probably want to use Java or Python instead.
However, it may work to do a C# system call and execute a Basic macro. An example from https://ask.libreoffice.org/en/question/150565/execute-macro-in-calc-from-terminal/:
soffice "macro:///Standard.Module1.Ora(2,3)" "/home/lim/Scrivania/Test.ods"
With this setup, much of the code will be in Basic. If you are not familiar with the language, a good place to start is http://www.pitonyak.org/oo.php.

Share code between office applications

I have written two addins , 1 for excel and 1 for word. However these addins have a lot of duplicates: Database handling, file handling,array handling which I would like to update 1 place instead of two.
We do have access to sharepoint, and could get access to visual studio. The thing is that people like to use file explorer and find the correct word or excel file, then open it then press a button inside the application which then should do things with the active document.
This is why we haven't written it as a .Net application yet, because that requires that people browse for the file inside the .NET application uless I am mistaken.
Is it possible to make an Addin which works both excel and word, or a dll? AnAnother important thing is that it should be easy to roll out a new version to the user, like stored on a network drive or similar.
Yes it is possible
The Hard Way
You can create a .Net DLL and call it from VBA. In visual studio a lot of people use Unmannaged Exports by Robert Giesecke to create DLLs that don't need to be registered (that way the DLL can be shipped with your document, and as long as it can be found you can use it).
Alternatively you might be able to do it manually as shown here by Hans Passant.
The Easy Way
Once the DLL is created you can declare it in a VBA module the same way you declare any other DLL for Late Binding and then call it from your code.
OR if you're happy to create the DLL and add it as a reference (possibly less portable) you can make it COM visible and register it for COM Interop in Visual Studio; this is probably the easiest way to go because you can then use Early Binding.
This is a walk through that might help: http://www.geeksengine.com/article/create-dll.html
But if you want to store the DLL on a network drive, well it might be that you really want to look at doing it the 'hard way', in which case look here: https://stackoverflow.com/a/5934745/3451115 and here: https://msdn.microsoft.com/en-us/library/bb687915.aspx

C# Windows Search: how to detect that a location is in search index without interop library?

We use Windows Search in our application and need a way to detect is folder indexed.
I know 2 ways to do it:
1. Using Microsoft.Search.Interop.dll library.
2. Using Windows Search Sample Code (maybe a bit changed) as an .exe file called from C# application.
These two solutions need using an external file (.dll or .exe) but I need a simpler solution because it will be simple new optional SEARCH feature to a WebDAV server generated by wizard for our clients. Besides Microsoft.Search.Interop.dll is for .NET 2.0 and there can be a problem using it from IIS under .NET 4.0 pool (depending on pool settings).
Is there any way to use ISearchCrawlScopeManager interface without linking to any .dll (just to COM) like it was made in Crawl Scope Command Line C++ example?
UPDATE1: Looks like ISearchCrawlScopeManager interface is located in Search Interface Type Library. It isn't done yet, but I'm close. Thanks to Hans Passant.

Call VB method in C# using Interop

Okey here's the situation: I've got a microsoft excel macro in vb that I want to call using C#. I've already tried creating a workbook using Microsoft.Office.Interop.Excel, however I don't want to have to run an excel process to run the macro.
So then I thought why not make a vb class library with my code in it so i can still run it and have a clean dll file. It's not needed to keep any sheet related functions since the macro reads a .lua(UTF-8)text file with some advanced regex functions that I just can't get recreated in C#.
Is it possible for me to make the library use interop as well so i can just call the function in my C#? Any examples would be greatly appreciated.
First I assume you are working with VB6 and not VB Script?
I have never worked with VB 6 or earlier, but I think your best be will be to create a COM object and then you can call the COM object from .NET using C#. Here is a quick link I found through BING that I believe will help you get started if this in an option for you.
Walkthrough: Implementing Inheritance with COM Objects (Visual Basic)
I noticed these two statements:
I don't want to have to run an excel process to run the macro
and
the macro reads a .lua(UTF-8)text file with some advanced regex functions that I just can't get recreated in C#
Those two goals are incompatible. The macro relies on excel functions to run. The only way provided by Microsoft to accomplish this is to completely load the Excel app. There is no way to only run the macro.

vba Extentiblity, com addin guidance?

Does anyone know of good reference material for creating a com addin for the VBA Editor enviroment, i know its exactly the same as writing a com addin for common enviroments using the addin model provided by microsoft using the IDTExtensibility2 interface. just registering the com registry keys to a different location, Where is that location?
Also any examples on .net interop code for how to reference the code editor, in as much detail as possible, add custom menu items to the context menu. you know normal customization code. Also if anyone knows how to hook up visual studio for debugging said project. If you know of anyone of these, id be very much indebted.
It looks like the person who put together the MZ Tools has a small section on their site with some resources on building VBE Addins
http://www.mztools.com/resources_vs60_addins.aspx
This could be the registry location - HKCU\Software\Microsoft\VBA\VBE\6.0\Addins
I found this by running Process Monitor from sysinternals.
Capture Events using Process Monitor
Ran Excel, Alt+F11, Tools -> Addins
EDIT: I don't know much about .net interoping with addin code.
But, I would open the addin project, set the necessary breakpoints, keep it in run mode, open the VBA editor, load the addin & take actions which will make me break into the code of the addin.
"Microsoft Office 2000 Visual Basic Programmer's Handbook" (ISBN 3-86063-289-2) has four (!) pages on this subject. I only have the German edition, but I could translate the important bits if you think it might help. Obviously, nothing about .Net Interop in there, but some basic info about writing VBE Add-ins.
Check out O'Reilly's Developing Visual Basic Add-ins: The VB IDE Extensibility Model
The book, while an excellent resource, is mostly based on the normal VB Editor -- but combined with digging through the Object Browser, and references like those # MzTools (as Jon pointed out), you should be good to go.
I used both of these resources when dealing with the VBA IDEin EMC-Captiva's InputAccel and FormWare environments, which only expose portions of the VBA IDE.

Categories

Resources