How can I change the Microsoft Dynamic 365 X++ class template in Visual Studio 2017? - visual-studio-2017

I've currently set up a environment for learning Microsoft Dynamics 365.
While I am playing around with code, I am getting a million warnings about missing documentation.
As:
I am a strong believer in "Clean Code"; and
I especially don't want to document all these things while just messing about to learn; and
I want visibility of other warnings which may be more important or at least interesting; and
I prefer explicit code.
I want to suppress all the warnings and always include the "public" keyword by default for all my classes.
So, I want to change the template from:
class AssetConsistencyCheck
{
}
to
[SuppressBPWarning("BPXmlDocNoDocumentationComments", "Prefer clean code!")]
public class AssetConsistencyCheck
{
}
Is this possible, and if so how?

Related

What's the easiest way to generate type-variant C++ code when templates and macros aren't possible?

In Unreal Engine, I've created a series of structs in C++ that let me generate a replicated version of the TMap struct. It relies on a number of engine resources like Fast Array Serialization, and the structs needs to be recognized by the engine like a normal USTRUCT.
For example, here's there starting piece of one of the structs:
USTRUCT(BlueprintType)
struct FReplicatedTMap_GuidToGuid_Array : public FFastArraySerializer
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadOnly, NotReplicated, VisibleAnywhere)
TMap<FGuid, FGuid> ReplicatedMap;
Long story short, my implementation works. However, due to UHT (Unreal Header Tool) constraints, I cannot use templates
USTRUCT(BlueprintType)
template<>
because it isn't supported by the engine, and I can't use macros
#define \
USTRUCT(BlueprintType) \
because the UHT pre-processor doesn't expand macros before looking for its own macros like USTRUCT(), and this prevents pre-processor generated code from being evaluated by the engine.
In the first code example, you can see that each set of struct/function definitions only apply to one key type - value type pair. The code itself is only ~150 lines or so, but I'd like to not have to change multiple dozens of definitions every time I need to tweak these struct templates, let alone create additional copies whenever I need new types.
Is there a solution within Unreal, or using C++? What's the best way to autogenerate the code I need?
In case anyone stumbles across this post, the best solution I found is using Visual Studio's T4 Text Templating engine, despite it not being included in C++ project files. In the case of UE4, you can use the UProject file to prebuild a Text Template.
Important Resources:
T4 in C++
UE4 PreBuild
My UProject Code addition to run the T4 engine with VS2019:
"PreBuildSteps":
{
"Win64": [
"\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Common7\\IDE\\TextTransform.exe\"
$(ProjectDir)\\Source\\<YOUR_FILE_LOCATION>\\<YOUR_TEMPLATE_FILE>.tt","echo T4 Executions Complete"
]
}

DLL fails to load if unused ref class is removed

I'm running into a very strange problem trying to compile and use a windows runtime component within an UWP application (VS2017 community 15.9.13 with NetCore.UniversalWindowsPlatform 6.2.8, compiled without /clr but with /ZW).
It is basically something like the Grayscaletransform. The runtime component is actually working as expected, now I wanted to remove some unused code. However, as soon as I remove it from a particular file and recompile, it indeed compiles, links, but the DLL does not load any more.
Here's some example code that I have to put in:
ref class DummyU sealed
{
public:
DummyU() {}
};
DummyU^ CreateDummyU()
{
return ref new DummyU();
}
The code just makes it work, although it is a) not referenced at all and b) does not do anything useful.
The result of removing it:
Exception thrown at 0x0EFF322F (vccorlib140d_app.dll) in TestAppUWP.exe: 0xC0000005: Access violation reading location 0x00000000.
in
STDAPI DllGetActivationFactory(_In_ HSTRING activatibleClassId, _Deref_out_ IActivationFactory** ppFactory)
{
return Platform::Details::GetActivationFactory(Microsoft::WRL::Details::ModuleBase::module_, activatibleClassId, ppFactory);
}
function in dllexports.cpp which is part of VS. The module_ becomes NULL.
Does anyone have an idea if there are any known bugs with respect to the windows runtime not being initialized/used properly if there is no explicit instantiation of a ref class in a file?
EDIT 1:
Here's the link to the full source code:
What's happening here is that you're mixing modes a bit. Since you've compiled your C++ code with the /CX flag, you've told the compiler to enable winrt extensions to produce a WinRT DLL. In practice though, none of your code is actually using the CX extensions to implement classes. You're using WRL and standards C++. The compiler looks at the DLL, finds no CX-style WinRT classes, and doesn't set up the module, accordingly.
This is basically an untested & unsupported case, since you've chosen to say that you want to expose ref classes by picking a UWP component library project type, but then didn't actually provide any ref classes. It happens that under the hood, /CX effectively uses WRL, so you can nudge it along and initialize the state to work correctly, but you're kinda hacking the implementation details of the system.
There are two options I would recommend, either works: just make the project a non-CX Win32 DLL and init the module as described above. Or, better yet, flip over to C++ /WinRT, which will give you better support for the WinRT types than /CX and allow you to more easily mix in the classic COM types in your implementation. You can get started by just turning off the /CX flag in the compiler switches, then start updating the code accordingly.
Ben
You might have wrong .winmd file for your component. WinRT components made in C++ produce two outputs, dll and winmd. Both must match. It's possible you have them from different builds.
Another possible reason is error in manifest. The manifest of the app must include all referenced runtime components.
BTW, for native DLLs written in classic C++ and exposing C API, deployment is simpler, you include a DLL in the package and they just work, with [DllImport] if you're consuming them from C#.
Update: You can replace that ref class with the following code, works on my PC.
struct ModuleStaticInitialize
{
ModuleStaticInitialize()
{
Microsoft::WRL::Module<Microsoft::WRL::InProc>::GetModule();
}
};
static ModuleStaticInitialize s_moduleInit;
Probably a bug in Microsoft's runtime somewhere.

How to get autocompletion coding support writing winapi c++

I have been writing Java for a long time using Eclipse, now trying to switch to C++ in Visual Studio. From Eclipse/Java I know such auto-complete features: I write
bar = Foo.valueOf(x);
bar.doSomething(y, z);
and Eclipse offers me both to import whatever Foo I might mean, and declare bar as local variable, field, or parameter. Or create the function doSomething() with the appropriate signature, auto-adding missing imports to Foo. I am missing a corresponding feature on Visual Studio 2015, which does for example
add the corresponding #include and #pragma comment(lib, statements,
add these statements in a clear order, so that they work as expected (something like organize imports),
add namespace statements
declare variables, fields, and parameters on click/keypress
create function bodies, adding the corresponding foreward declarations to the respective header files, adding missing includes required by the declaration
…
The only things that I found so far is the “add class” dialog. When writing an unknown function name, right clicking and choosing “quick actions and refactorings” → Create declaration / definition, a window opens with the text
int main(int argc, char * argv[]);
but it does not create a definition for that function.
Are there some better “save me typing work” functions available in Visual Studio 15, and if yes, how can I benefit from them? Is there another way I could go, such as writing the C++ program (Windows API) in an other IDE (are there any for Winapi C++ which do better?)
Resharper by JetBrains does what you are asking for more or less. It will notice an error in your code, whether it being that something wasn't fully initialized, or something that you needed to include, or a host of other things.
It is not free though, but you can try it on a 30 day trial.
I don't know of an IDE that supports winapi functions like you're asking though. I think you'll just have to pick your favorite IDE and get used to it.

How to teach Visual Assist to assist me with smart pointers?

We usually define classes that are often used like this:
class SomeClass
{
// Some code here
};
typedef std::shared_ptr<SomeClass> SomeClassPtr;
Because frankly having to type std::shared_ptr<SomeClass> every time is a suicide.
However Visual Assist, addon that my company paid for on top of Visual Studio, cannot cope with either SomeClassPtr or std::shared_ptr<SomeClass> and give member suggestions. Strangely though, I noticed that it handles QPointer<SomeClass> without any problems and gives SomeClass member suggestions as expected.
I noticed that status bar shows these two messages after I type pointer-> (right after typing > character):
IntelliSense: 'No additional information available' (See 'Troubleshooting IntelliSense in C++ projects' for further help.)
Which is weird because IntelliSense (I prefer to call it DumbSense) is turned off. Second message that appears only for 200ms:
VA X: Parsing D:\ ... \myFile.cpp
myFile.cpp here refers to the file being currently edited.
Can I do anything at all to teach Visual Assist to properly give suggestions on std::shared_ptr smart pointers?

Convert C++/MFC from visual studio.net 2002 to visual studio 2010

We will convert a number of programs written in C++ and MFC in Visual Studio.NET 2002 to Visual Studio 2010. What problems can we expect to encounter? What changes are there in the libraries that are worth knowing?
MFC has had a number of breaking changes over those releases. All the changes are documented on MSDN, and usually they're pretty straightforward - function signature changes and the like (which can often be fixed simply by inspecting the compiler error message and working out what it wants instead).
I've been through this moving a project to VS 2008 and the two big ones were the "secure CRT" functions and the for loop scope change. (I can't remember precisely when that happened, but it might affect you.) Basically the compiler is your friend ... build the whole thing and it will find the problems, which you can then fix. You can suppress the secure CRT warnings but you might as well get them taken care of.
I'm not aware of any "I'm happy to compile but I won't do quite what I used to do at runtime, thus ruining your world" breaking changes in MFC or C++ over the last decade. So once you make the compiler happy you should be confident your app still works.
dynamic_cast will behave differently at runtime
class A
{
}
class B : public A
{
}
class C : public A
{
}
//...
C* c = new C();
//This used to work, i.e. didn't return NULL, with 2002
B* b = dynamic_cast<B*>(c); //... won't work any more --> returns NULL.