I think I have something real cool now and something to soon write an article about (I am doing one for Wrox right now on Web Forms and Managed C++). I have been doing a lot of work on an advanced development environment that will become a part of VS.NET (not an add-in). As I talked about much earlier, there is VSIP and the Automation model. VSIP is a real complicated beast. I can't talk much about it because of the agreements other than to see its big and complex. Productivity in creating things with it has been low. So I decided to use the Automation model in VS.NET to do stuff that I could do. I originally was doing things in the automation model with VB.NET, port to C# and then port back to ATL/C++ COM because VSIP is all COM based still. That's the weird thing about VSIP. There is this wonderful. modern XML-everything, whizzy environment for users to develop managed (and unmanaged C++) code in but the guts of VS.NET are still years of accumulated COM and old code!
.NET (which I have been working in for 2 years) has made me forget just how hard and tedious all this COM stuff is. When I ported, the one line of C# that went through 4 objects down in the automation model become a couple dozen lines of ATL COM (yes thats with Smart pointers too). Unfornately, VSIP is not managed code in any way and you can't even create an RCW for the Interfaces either! So, I ended up leaving the VSIP code in the COM component that implements IDTWizard and it launches the C# or VB.NET wizard that creates a User Control project. Now I needed to add default implementations of methods for the thing I was creating and a custom toolbar and tools. Time for automation.
I ended up coding a VB.NET component that manipulates the VS.NET DTE model to find the right place in the UserControl1.cs file and stick in the code on the fly. Why VB.NET? Because, believe or not, the Automation model in VS.NET has problems too! The NewLine() method for instance works in VB.NET but "is not implemented for V1 in C#!" Then I wrote a C# component to grab the VS.NET Toolbox, add a custom tab and some tools. Now to call it from ATL/C++ COM unmanaged code. Here are the steps:
- Create a C# or VB.NET class
-
Generate a key for it - sn -k keyfile.snk
-
Put an assembly directive at top of file
[(Assembly: AssemblyKeyFile("keyfile.snk")]
-
Compile
-
regasm file.dll /tlb to generate the COM Type Library
-
gacutil -i file.dll to place file in GAC
-
Copy the generated typelibraries into the directory of your C++ project
-
#import file.tlb no_namespaces named_guids and one other I can't remember
-
Compile C++ code and you will have access to the CCW through the types in the imported tlb
Whew! After that, I now have a COM/ATL/C++ native component making calls to two different managed components in two different languages each handling the parts they are good in. Pretty cool?
10:57:20 PM
|
|