T
Tim Menninger
Just started working on this and have not found any real good resources out
there. We have a lot of native C++ Dll code that we use for our app. We want
to share the code so that C# ASP.net code can use the same business logic as
our C++ client. Here are some questions:
1) Is there a way to call into native C++ classes directly? Meaning we do
not have C API. I believe we could use a C API using the [DllImport] in C#.
2) If can't do #1, do we need to write custom marshalers for all the data
types. I believe that this is the P/Invoke method. Is there any other
methods besides custom marchaling.
3) We have played with wrapping a native C++ class with managed C++ but as
soon as you include c runtime or stl in the .cpp of our unmanaged C++ the
managed DLL exposes every type in the C runtime and stl. We obviously do not
want to expose these types since the caller of the managed C++ will never
need them. This managed wrapper will also be given to customers so we would
like to only have the 1 or 2 managed classes exposed and nothing else.
4) How do exceptions work when wrapping unmanaged with managed. Some of the
exposed objects in #3 are exceptions. If an exception gets thrown in
unmanaged how does it get propagated through the managed. a) if the managed
catches the exception what does it throw and b) what happens if the managed
does not catch the exception?
There seems to be alot of people wanting to do the same thing but I haven't
found a good example that shows how.
Thanks,
Tim
there. We have a lot of native C++ Dll code that we use for our app. We want
to share the code so that C# ASP.net code can use the same business logic as
our C++ client. Here are some questions:
1) Is there a way to call into native C++ classes directly? Meaning we do
not have C API. I believe we could use a C API using the [DllImport] in C#.
2) If can't do #1, do we need to write custom marshalers for all the data
types. I believe that this is the P/Invoke method. Is there any other
methods besides custom marchaling.
3) We have played with wrapping a native C++ class with managed C++ but as
soon as you include c runtime or stl in the .cpp of our unmanaged C++ the
managed DLL exposes every type in the C runtime and stl. We obviously do not
want to expose these types since the caller of the managed C++ will never
need them. This managed wrapper will also be given to customers so we would
like to only have the 1 or 2 managed classes exposed and nothing else.
4) How do exceptions work when wrapping unmanaged with managed. Some of the
exposed objects in #3 are exceptions. If an exception gets thrown in
unmanaged how does it get propagated through the managed. a) if the managed
catches the exception what does it throw and b) what happens if the managed
does not catch the exception?
There seems to be alot of people wanting to do the same thing but I haven't
found a good example that shows how.
Thanks,
Tim