Posts Tagged ‘Visual Studio’

Visual Studio 2015 – What’s new?

So, finally MS looks to wake up from its long hibernation.
This time they are very aggressive and I believe Apple and Google ( not as much as Apple ) should get alarmed.

VS 2015 has many good things, however, as many of us know by now, it contains open source version of .NET. I didn’t check which .NET it’s referring, but mostly it looks to contain APIs for server-side functionality at this moment.
Also, it embraced Xamarin, which is Mono-based Android/iOS cross platform development solution.
if MS gets involved in development of Mono more actively, Apple should get notified about it.

So, please try to read and see what’s new about VS 2015!

How not to build with “ClickOnce” deployment option?

“ClickOnce” deployment is cleaner and easier option than “InstallShield” option. Also, it is free.
However, there is one glitch. ( MS people will call it a “feature”. )
“ClickOnce” doesn’t allow execution level higher than “AsInvoker”. So, it means that you can’t include a call to some functionality which requires “Administrator” privilege.
What? Isn’t it totally different thing to elevate execution level when launching, and building/deploying an executable? Right. However, it’s the approach MS people chose, and when building a project, it will warn and stop building.
In my code ( I got rid of “s” here, because my native English speakers said it was wrong if you wrote/speak codes. Well, a language keeps changing. According to English grammar book, you should not say, “Give me (a) milk”. A correct one will be “Give me a cup of blah blah”. But one very surprising thing I found in living here is that there has been virtually no person who ordered like “give me one cup of Cafe Mocha”, “Give me one glass of Coke” etc. They always say “Two Cokes”, etc ) I call WMI method to enable/disable network interface. It requires “Administrator” privilege.

So, I had to change a deployment method not to use ClickOnce.

However, how not to use ClickOnce? Isn’t it enough not to click “Publish” menu item?
Visual Studio still spit out the error message.

How to solve it is to turn off “Security Option” like shown below.

How to turn-off checking “ClickOnce” in building

 

The following is when the option is on.

ClickOnce doesn’t support “Administrator” level

 

 

Rethinking Visual Studio as a development tool

Well, I have used Visual C++ or Visual Studio for about 20 years.
On Windows platform, Visual C++/Studio was the tool you should choose to create Windows apps on Windows. Borland C++ was very good, but to me Visual C++ was the right tool because it was MS which created the Windows and introduced technologies for Windows. Borland should talked with MS to implement the latest MS technology for Windows.

However, since I used the Visual C++, I got impression that coding for Windows was kind of dirty job. Why? I didn’t “recognize” the reason clearly so far. However, recently I started to open my eyes and finally saw the reason.

If you override member functions, windows message handler, event handler and so on, the Visual Studio automatically generates those and put those in header files and implementation files. What makes things dirty is that Visual Studio just put new methods and new variable to the last line of the header file of interested classes. For the Visual Studio developers, it would be the easiest way of implementing the code generation.

class CMYClass
{
    // Member Variables
private :

protected :

public :

   // Member Functions
private:

protected :

public :

}

or

class CMYClass
{
private :
    // Member Variable
    ...

    // Member Functions
    ....

protected :
    // Member Variable
    ...

    // Member Functions
    ....

public :
    // Member Variable
    ...

    // Member Functions
    ....
}

Things can be complicated because there are Windows Message handlers, event handlers, overriden functions, the methods of the class itself.

Whatever it is, the above two organizations make it easy to figure out what the class does.
Maybe it is not Visual Studio developers’ concern. Any programmers who use VS should not rely on the automatically generated codes completely. Once they are generates, individual programmers should organize the codes better way or more manageable way.

Also, I found out that #pragma mark used by Xcode was very convenient and very good to manage codes.
Especially when you migrate old codes to a new codes, you need to make sure if there will be any missing functionality. Then marking group of methods with #pragma mark in Xcode helps a lot. It provides easier way to figure out what existing classes do and how they are organized.
It also DRIVES people to organize their codes. With Visual Studio, it is very easy to have related methods placed here and there in implementation file, *.cpp. However, if #pragma mark is introduced, people will start organize their member functions under related mark tags.

Fast Open… for Visual Studio 2005/2008

When there are a lot of files in a project, it is pretty hard to find where the file is. In such case, I desperately wanted to have Xcode’s Fast Open… feature for Visual Studio 2005/2008.

So, while finding some plugins for Visual Studio, I found one tip.

What you should do is to type

>of [file name]

in the Find field.

Even intellisense works there!

Inconsistent GUI programming of Visual Studio

    The Visual C++ 6.0 has existed for long time compared to unfortunate Visual Studio .NET 2003. The 2000 versin changed a lot in respect to GUI and it introduced .NET. The 2005 version was somewhat stabilized, and 2008 version looks to continue its tendency.

    With this Visual Studio products, there are some problems. They are :

  1. GUI was changed too much.
  2. Approach in respect to GUI programming is not consistent

    The GUI was changed too much. Visual C++ 6.0 provided easy approach for dynamic data exchange on its class view dialog box. You could select what messages would be handled by a selected class on the same dialog box.

    2003 version was changed a lot, so adoption rate was not good.
From 2005 version, things were streamlined well. However there are still lots of difference.

    For example, does the 2005/2008 version provide a way to set up window message handler? It is pretty difficult to find it.
But here it is.

Inconsistent_VC

After selecting a class, open its property pane. Then you can find where you can set up message handlers.

    Second, the way to add / modify event handler is different.
At least adding one is same.

EventHandler

    However, to browse existing event handler, you cannot double click a button. As far as I remember, Visual C++ 6.0 allowed it, existing event handler was opened.
Also, most importantly, the way to add message handler and event handler are very different. Why classes like dialog is in resource file to be represented visually and thus provides a way to add event handler by clicking, while those for views are not visually represented in resource file and its message handler can’t be added/modified by clicking?
This is very important inconsistency.

    So, for .NET, MS introduced “form” programming, whcih is property programming. With property programming paradigm, setting properties, or class member variable, is enough to set up things, e.g. fonts, etc. Also, view classes in .NET framework are also visualized in its resource file.
This was originally pushed by Borland. As far as I know, MS hired a Borland programmer to implement “form programming” paradigm for Visual Studio.

    Because this difference, it is confusing to prepare code with VS from time to time. However, thanks to .NET framework, programming for Windows feels similar to that for Mac nowadays. For last two years, I tried .NET programming. It was quite easy to learn it and found out that .NET classes and its approach is very similar to that of Cocoa/Objective-C.
So, I decided that I could easily start writing in .NET. So, I kept focusing on MFC.

    By the way, I couldn’t decide whether to post this to my Hot Potato blog or here, but this is more about development. So I decided to post it here.

Debugging a release build with the Visual C++ 2005

Sometimes debug build doesn’t crash but release build crashes. This usually happens when memory area which is not valid is accessed. Debug build usually has some fence around allocated memory area.

However, recently I suffered somewhat different case. In this case, you need to debug a release build.
Yeah.. It is quite easy. Just enable debug information for a release build. However, in my recent case, doing so didn’t reveal symbols or display correct values for variables.
At first, I thought a stack is corrupted. However, I found out that optimization option did affect the symptom.

So, disabling optimization was the solution to check content of variables.
coptimization

The cause of the crash was due to #pragma pack.
In one of its header file, #pragma pack (push, 1) is used, and at the end of the file #pragma pack(pop, 1).
It should have been #pragma pack(pop) to reverting.

So, in a influenced class implementation file, it used correct alignment, while in other source file which included a troubled header file, the alignment of this class is not interpreted as it should have been.
So, it caused a vtable evasion in a source file which includes the troubled header file. Therefore, it crashed when it called one of the method of the influenced class.

It is strange that this didn’t cause problem with a debug build. There is not explanation on the MSDN site whether this is disabled in debug build or not.

%d bloggers like this: