eswarpabolu wrote:
I have the source code for C++ solution. But what iI though was not to touch C++ source. If there is any possibility to do it in C#, it would be great.
I still suggest you to modify C++ source, because it would give you a serious benefit. But you don't need to modify any code. You could do a lot better: only add some new file(s) to the code in most unobtrusive way, so your present functionality would not be compromised.
The idea is: you can use C++/CLI (not just native C++) and essentially use "CLI" part of it to expose some code as managed. You can make you C++ project mixed-mode (managed+unmanaged) C++/CLI module and .NET assembly at the same time, with possibility of dual use: .NET assemblies can reference your C++/CLI assembly as any other assembly, and unmanaged native units can just keep using its executable module (DLL, in this case) as any other native DLL.
As you can freely mix managed and unmanaged code in C++/CLI, you could wrap you native class(es) into managed "
ref
" CLI types and exposed those you need to expose to other assemblies using
public
access modifier. It's better not to change any existing files, just add some separate ones.
This way, despite of some code overhead, seems to most beneficial, because it is the most reliable and maintainable: you won't be dependent on the subtleties of marshaling and internal representation of types; moreover, modification of the types to be exposed can be painless.
Please see:
https://msdn.microsoft.com/en-us/library/ms235282.aspx[
^].
See also:
http://en.wikipedia.org/wiki/C%2B%2B/CLI[
^],
http://www.ecma-international.org/publications/standards/Ecma-372.htm[
^],
http://www.gotw.ca/publications/C++CLIRationale.pdf[
^],
http://blogs.msdn.com/hsutter/archive/2003/11/23/53519.aspx[
^].
And see also my past answers:
How to invoke C++ DLL in ASP.NET?[
^],
How do I catch native c++ exception in managed c++ class?[
^],
Dealing with windows form application[
^].
—SA