Does anyone know how to implement the DynamicEnumProperty type for C++ Project Property rules - dynamic

I am trying to add a property to our custom build configuration for a C++ project. I want the property combo box to display a dynamic list of values that I can set in code. I think that this should be done using the DynamicEnumProperty type but I am unsure of its implementation. Has anyone worked with this property before that can point me in the right direction?
Thanks

I know it's a bit old question... but you might still enjoy the solution ;)
Beside referencing the assemblies and exporting desired type via MEF as Dmitry explained above, you also need to mark the VSPackage as MEF-enabled to make it scan though your contracts. Do it by editing source.extension.vsixmanifest:
for VS2010:
<Content>
<VsPackage>|%CurrentProject%;PkgdefProjectOutputGroup|</VsPackage>
<MefComponent>|%CurrentProject%|</MefComponent>
</Content>
for VS2012 / VS2013:
<Assets>
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project"
d:ProjectName="%CurrentProject%" Path="|%CurrentProject%|" />
</Assets>
This should let you hit a breakpoint set in an exported class.
Additionally, if you need to create an object at runtime 'manually', you can use VisualStudio's internal composition container. The simplest way to access it from anywhere is:
var container = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel)) as IComponentModel;
var service = container.GetService<SVsXYZ>();
I will shortly add a sample here: https://github.com/phofman/vs-plugin, so just putting the link for future reference.

In your VSPackage (or any MEF-exposed DLL referenced by it) create a class implementing IDynamicEnumValuesProvider and add [Export(typeof(IDynamicEnumValuesProvider)), DynamicEnumCategory("MyCategory")] to that class's attributes. Then add EnumProvider="MyCategory" to the DynamicEnumProperty definition and your class will be used as the values provider.
Make sure your package references Microsoft.VisualStudio.ProjectSystem.Utilities.v12.0.dll and Microsoft.VisualStudio.ProjectSystem.V12Only.dll (for VS2013) or similar assemblies for earlier versions.

Related

Custom XAML Applications (non-WPF and non-WWF)

This question is likely a particular XAML application. XAML is a custom markup to instantiate objects and, as such, define custom applications. Note that, it serves to both declare WPF user interfaces and WWF workflows. It would also help to specify, e.g., a custom source-code change detection solution. To avoid getting in deeper in unnecessary details. I need to design a custom XAML-based model that, like the one for WPF and the one for WWF do, allows me to declare a custom application on top of XAML, without having to create a WPF or WWF project. Is this sort of third-part XAML-like provider possible to build?
<Approach>
<PrimitiveExample
OriginalType={Type syntax:LiteralSyntax}
ModifiedType={Type syntax:LiteralSyntax}
Propagation.Matched={Binding MatchedPropagationCommand}>
...
</PrimitiveExample>
...
<Approach/>
Let us see it this way. Is there a way to get a stand-alone XAML file that works as follows?
a) There will be a project item, e.g., named "Stand-alone XAML".
b) I create a new "Stand-alone XAML" item named, e.g., "Solution.sccd", and I add it to a console application, class library, or many other projects. This because it will be a sort of smart .config.
c) I can set up a root instance in "Solution.sccd" (likely containing a lot of nested instances) - this is natural for XAML.
d) When declaring instances in "Solution.sccd", I can use features like attached properties, binding, and many other smart features or markup extensions that can be used with WPF or WWF, but this will not be a WPF or WWF project.
e) I can instantiate the declared root instance, e.g., with simple code line like "var rootObject = XAMLInstanceCreator.Create(Solution.sccd)", and use that object.
Does this make sense now?
Regards, Guillermo.

Implements vs Binary Compatibility

I have one VB6 ActiveX DLL that exposes a class INewReport. I added some new methods to this class and I was able to rebuild it and keep binary compatibility.
I have a second DLL that exposes a class clsNewReport, which implements the first class using:
Implements RSInterfaces.INewReport
Since I added new methods to INewReport, I had to also add those new methods to clsNewReport.
However, when I try to compile the second DLL, I get the binary-compatibility error "...class implemented an interface in the version-compatible component, but not in the current project".
I'm not sure what is happening here. Since I'm only adding to the class, why can't I maintain binary compatibility with the second DLL? Is there any way around this?
I think this is a correct explanation of what is happening, and some potential workarounds.
I made up a test case which reproduced the problem in the description and then dumped the IDL using OLEView from the old & new DLL which contained the interface.
Here is a diff of the old (left) and new IDL from INewReport:
Important differences:
The UUID of interface _INewReport has changed
A typedef called INewReport___v0 has been added which refers to the original UUID of the interface
(I assume that this is also what is happening to the code referred to in the question.)
So now in the client project the bincomp DLL refers to the original interface UUID; but that UUID only matches against a different name (INewReport___v0 instead of INewReport) than it did originally. I think this is the reason VB6 thinks there is a bincomp mismatch.
How to fix this problem? I've not been able to do anything in VB6 that would allow you to use the updated interface DLL with the client code without having to break bincomp of the client code.
A (bad) option could be to just change the client DLL to use project compatibility... but that may or may not be acceptable in your circumstances. It could cause whatever uses the client DLL to break unless all the consumers were also recompiled. (And this could potentially cause a cascade of broken bincomp).
A better but more complex option would be to define the interface in IDL itself, use the MIDL compiler to generate a typelib (TLB file), and reference that directly. Then you would have full control over the interface naming, etc. You could use the IDL generated from OLEView as a starting point for doing this.
This second option assumes that the interface class is really truly an interface only and has no functional code in it.
Here's how I setup a case to reproduce this:
Step 1. Original interface definition - class called INewReport set to binary compatible:
Sub ProcA()
End Sub
Sub ProcB()
End Sub
Step 2. Create a test client DLL which implements INewReport, also set to binary compatible:
Implements INewReport
Sub INewReport_ProcA()
End Sub
Sub INewReport_ProcB()
End Sub
Step 3: Add ProcC to INewReport and recompile (which also registers the newly built DLL):
(above code, plus:)
Sub ProcC()
End Sub
Step 4: Try to run or compile the test client DLL - instantly get the OP's error. No need to change any references or anything at all.
I was able to recreate your problem, using something similar to DaveInCaz's code. I tried a number of things to fix it, probably repeating things you've already tried. I came up with a possible hypothesis as to why this is happening. It doesn't fix the problem, but it may throw some additional light on it.
Quoting from This doc page:
To ensure compatibility, Visual Basic places certain restrictions on changes you make to default interfaces. Visual Basic allows you to add new classes, and to enhance the default interface of any existing class by adding properties and methods. Removing classes, properties, or methods, or changing the arguments of existing properties or methods, will cause Visual Basic to issue incompatibility warnings.
Another quote:
The ActiveX rule you must follow to ensure compatibility with multiple interfaces is simple: once an interface is in use, it can never be changed. The interface ID of a standard interface is fixed by the type library that defines the interface.
So, here's a hypothesis. The first quote mentions the default interface, which suggests that it may not be possible to alter custom interfaces in any way. That's suggested by the second quote as well. You're able to alter the interface class, because you are essentially altering its default interface. However, when you attempt to alter the implementing class in kind, to reflect the changes in your interface, your implementation reference is pointing to the older version of the interface, which no longer exists. Of course, the error message doesn't hint at this at all, because it appears to be based on the idea that you didn't attempt to implement the interface.
I haven't been able to prove this, but looking at DaveInCaz's answer, the fact that the UUID has changed seems to bear this idea out.

which reference should be added to wcf project so that program recognize requestUrl.GetComponents()?

I have copied a sample code to a wcf project and it contains $requestUrl.GetComponents$ ... the program don't recognize it ( there is red line under it) ... which reference should I add to solve the problem ...?
GetComponents is a method of the System.Uri class. You only need to reference the System.dll (which is on the great majority of the projects by default) to use that.

How to get Imported type libraries from an OCX or TLB file?

I was convinced that there is no way to find COM dependencies of an ActiveX but to my surprise OLEVIEW shows some comments Like:
// TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb");
// TLib : Visual Basic runtime objects and procedures : {EA544A21-C82D-11D1-A3E4-00A0C90AEA82}
importlib("3");
I tried to extract the same information using TypeLibInfoFromFile but based on what I find in MSDN, there is no Api that provides this information. Are you aware of a method to extract this information from OCX or it's Tlb file? Knowing that all my ocxes are compiled with vb6 can I trust this informaion for Imported(Explicitly not in code) interfaces?
Well, I've found the answer to this question. I'll write it here just in case someone would search for the same question. It's possible to find some of dependencies but you can never be sure if you have found them all. Basically you must enumerate every type and interface, and every member of each type to find all types in the module and for every type you find you should check to see if it's in an external TypeLib. in the end you have a List of Typelibs referenced.
The problem with this method lays in the fact you find only the types that are used in the public interface (fields, return values and parameters) and you miss every local object or dynamically created ones. That said you can check this link for an implementation or better yet this one.

How to find and remove unused class files from a project

My XCode project has grown somewhat, and I know that there are class files in there which are no longer being used. Is there an easy way to find all of these and remove them?
If the class files just sit in your project without being part of a target, just click on the project itself in the tree view, so you see all files in the table. Make sure you see the "Target" column in the table view, iterate through your targets and find the files that don't have a check anywhere -> they are no longer compiled.
But if you still compile the classes and they are no longer used, that case is a bit more difficult. Check out this project
http://www.karppinen.fi/analysistool/#dependency-graphs
You could create a dependency graph and try to find orphaned classes that way.
Edit: Link went dead, but there still seem to be projects of Objective-C dependency graphs around, for example https://github.com/nst/objc_dep
if they are C or C++ symbols, then you can just let the linker do the work for you.
if you're looking to remove objc symbols, then try to refactor the class name (e.g. to rename the class), and preview the dependencies that it turns up. if you reference classes/selectors/etc. by strings then... it may not be so effective. unfortunately, you often have to also test manually, to verify that removing a class does not break anything. remember that resources (like xibs) may reference/load objc classes as well.
This is a tricky question due to how dynamic objective-c is as you can never guarantee that a class is not going to be used.
Consider if you generate a class name and a selector at run time and then look up that class, instantiate that class and then call a method on that newly created object using that newly created selector. No where in your code do you explicitly name and instantiate that object but you are able to use it anyways. You could get that class name and selector name from anywhere outside of your code, even from some data from a server some where. How would you ever know which class is not going to be used? Because of this there are no tools that are able to perform what you are requesting.
Searching the project with the class name might be an option, thought it may not be the best solution. Specially it might be time consuming when you have many classes.