So one thing I wanted to do was use C# windows forms (and other stuff) with C++ code. The first thing I needed to find out was how to debug such a monstrosity in Visual Studio. Here's how you set up your project to step from C# into C++ land seamlessly:
Debugging in Visual Studio .NET
So the other weird thing I ran into was linker errors. I was trying to reference a mixed code .dll (compiled with /clr) from another native code .dll. Doing Properties->Linker->Input->Additional Dependencies for the project and adding the .dll causes a linker error: LNK1302. Apparently you have two options: compile the .dll with /clr:safe OR include every stupid .obj file for every .cpp file that you have in the .dll you want to include. Another option that I found was to give up on the .dll thing, and just make a statically linked library (change the configuration to produce a .lib instead) for the mixed-code library and then include this in the other native code .dll. Then, I can include the Additional Dependency without difficulty. My project compiles and works as expected for now, though I read somewhere you can get weird initialization problems sometimes when you have mixed-mode libraries. I'll be on the lookout for that gotcha, but for now using .lib's seems to work for me.
In summary, I have C#->C++/CLI .dll -> C++ & C++/CLI .lib
I say C++ & C++/CLI .lib because in some .cpp files I use .NET types (declared as a
public ref class
), and in others I do not (these are declared as public class
).C++/CLI is very weird... it's sort of like a computer version of Esperanto.
Anyway, this pdf file has some useful general info on C++/CLI etc:
link It's from a book, Expert C++/CLI
No comments:
Post a Comment