Figure 1 Example of VB6 Type with Fixed Length Strings
There are some ways to model this structures in .NET using the FixedLengthString defined in Microsoft.VisualBasic.Compatibity.
Here I will present another approach.
This approach uses character arrays (char[]) to model this structures.
Ok. Let’s get down to business. To model a vb6 type like the one in Figure 1, we will use this approach:

First

All fixed length strings are declared as char[]. A MarshalAs attribute is applied to each field. Like this:

[MarshalAs(UnmanagedType.ByValArray, SizeConst=n)]

Where n is the number of characters in the fixed length strings. Note that character arrays must be initialized. However structs do not allow field initializers. So they will need to be initialized on a constructor.

Second

A DebuggerDisplay attribute

[DebuggerDisplay("{s(<AttributeName>)}")]

is added to each field, just to make the developer experience. That makes that instead of showing this field as a character array it will be shown as a string.

This attribute uses a small helper function used s that just converts the character array to string.

Third

A constructor is added. Structs do not accept parameter-less constructors. This struct receives a Boolean indicating whether you want to initialize the character array fields.

As a requirement character arrays fields should at least be initialized to null. Character arrays could have been initialized here but I opted to create a helper function. Why? Well I think it is better if this arrays are initialized using the SizeConst attribute. So if I want to change their size I do not have to update both the SizeConst and the constructor.

Forth>

In VB6 the common approach is to use the StrConv and CopyMemory functions to copy memory to and from structs and send them as strings or event to copy data between structs of different types.
To solve that utility methods have been created:

/// <summary>
/// Takes a bytearray and uses it to create a struct of the given type
/// and populate it with the data of the byte array.
/// NOTE: this method only works withs Structs which have a fixed size
/// </summary>
/// <param name="bytearray"> The data that will be used to initialize the struct</param>
/// <param name="type">The type of the expected struct</param>
/// <returns>A new struct instance with its fields initialized with the bytes from bytearray</returns>
public static object ByteArrayToStructure(byte[] bytearray, Type type)
{
int len = Marshal.SizeOf(type);
IntPtr i = Marshal.AllocHGlobal(len);
Marshal.Copy(bytearray, 0, i, len);
var obj = Marshal.PtrToStructure(i,type);
Marshal.FreeHGlobal(i);
return obj;
}
/// <summary>
/// Returns the contents of an struct as a byte array.
/// It only works with fixed length structs.
/// </summary>
/// <param name="obj">the struct that holds the data that will be returned in the byte array</param>
/// <returns>A byte array with the contents of the struct</returns>
public static byte[] StructToByteArray(this object obj)
{
int len = Marshal.SizeOf(obj);
byte[] arr = new byte[len];
IntPtr ptr = Marshal.AllocHGlobal(len);
Marshal.StructureToPtr(obj, ptr, true);
Marshal.Copy(ptr, arr, 0, len);
Marshal.FreeHGlobal(ptr);
return arr;
}

Fifth

And finally how to you easily get/set data from these structs?
Very easy. We will add an extension method:

const string IF_VALUE_NOT_PROVIDED_THEN_RETURN_VALUE = "\0\0internal";
/// <summary>
/// This method is used to get/set the values of a char array as an string.
/// It has been implemented in a way similar to that used in the jquery .val function.
/// If called without parameters it will return the character array value as an string.
/// If called with parameters will use the given string to set the character array value.
/// If the given string is bigger that the character string the value is truncated
/// </summary>
/// <param name="array"></param>
/// <param name="value"></param>
/// <returns></returns>
public static string val(this char[] array, String value = IF_VALUE_NOT_PROVIDED_THEN_RETURN_VALUE)
{
if (value == IF_VALUE_NOT_PROVIDED_THEN_RETURN_VALUE)
return new string(array);
else
{
var source = value.ToCharArray();
Array.Copy(source, array, Math.Min(source.Length, array.Length));
return value;
}
}

With that if you want to set a field you will do something like:

hostData.UserName.val(“Mauricio”)

And if you want to get the contents of the field you will do something like:

I have a development computer with Windows 8 and Visual Studio 2012, and I was planning on doing some tests with MSMQ. Everybody will tell you that you should just (in Visual Studio) open the references tab and add a COM reference to Microsoft Message Queue, but (yes there is always a but) the component was not present.

I looked for it in C:\Windows\System32 and C:\Windows\SysWOW64 and nothing there was nothing called mq*.tlb. So I found this thread in StackOverflow and it was pretty obvious :| I just had to go to Add Programs \ Turn on Windows Features and select it:

Figure 1. Adding MSMQ COM components

And after that I could find a file called C:\Windows\System32\mqoa30.tlb and added that reference.

An error ocurred... well this is not very document issue with the TLBIMP tool which creates the interop assemblies. See StackOverflow Answer. The workaround is to right click on your type library, select properties, and change Embed interop Types to false.

A lot of companies developed this kind of software in VB6, and they faced a lot ofof similar issues specially when dealing with POS devices.

It's nice that the industry has made the effort of developing standards as the UPOS orUnified POS (http://en.wikipedia.org/wiki/UnifiedPOS) and Microsoft also did a great workby providing the COM and .NET implementations.

It was nice to move VB6 applications to POS for .NET, but times have change and so has the UPOS grown to interesting proposals like WS-POS.

"The fundamental benefit of WS-POS is the ability to provision POS peripherals asservices that can be accessed by remote POS applications, including mobile POS solutions. Retailers can then use the power of Service-Oriented Architecture (SOA) to allow access to their existing peripherals anywhere in the store through these services. WS-POS holds potential benefits for all members of the retail ecosystem." from http://www.ibm.com/developerworks/webservices/library/ws-pos-retail/index.html

So you can now think about leveraring your VB6 POS to Silverlight or HTML5 and consume WS-POS services to provide for example tablet-based implementations. Imagine your POS application running in Silverlight or WinFX on a Windows 8 Tablet or in HTML5 in iPads or Androids. Does it sound appealing? Well that is exactly the kind of experience that our migration solution brings to the table.

You can download a working implementation of WS-POS from the Association for Retail Technology Standards (ARTS) web site. Go to http://www.nrf-arts.org/arts_download/schema-non-member Download the UnifiedPOS 1.13 pdfs and reference implementation from the WS-POS Addendum link (http://www.nrf-arts.org/download/file?f=http://www.nrf.com/Attachments.asp?id=30476&rid=227810) There are Java and WCF implementations. It is also very easy to modify the WCF implementation so it can receive and respond JSON and work with your HTML5 implementations.

I always appreciate feedback, so if you have any more toughts or questions about HTML5 or Windows 8 POS implementations just let me know.

This is a very strange error that you can find sometimes when working with ADO.NET.

David McKean from MSFT says:

This occurs when you have multiple DataReaders open concurrently on the same connection, ie you call SqlCommand.ExecuteReader but don't close the SqlDataReader returned by this method before calling it again (either on the same command or another command on the same connection).

It requires a feature called MultipleActiveResultSets which is not available in all providers.

For example SQL2000 does not support it, it was implemented starting from SQL2005.

I just came back from executing a Ready assessment for a company in Minnesota, where I analyzed 740,000 lines of code in a VB6 application, of which 660,000 belonged to a single Visual Basic project (.vbp). This is actually the largest single .vbp I have seen so far, beating the previous record of about 500,000 lines of code held by an European company. We have migrated plenty of applications that contain 1+ million lines of code, but they are usually distributed across many .vbp’s.

Though unusual, single vbp’s of this size are perfectly manageable from a migration standpoint, and here are some things that can be done to deal with them:

Ensure that the migration computer has at the very minimum, 3GB of RAM.

Look for customization opportunities before you start migrating the code. Customizing the VBUC for this specific VBP can reduce manual effort drastically.

When making manual changes, start with a small team until you get the project to compile, especially if migrating to VB.NET as the compiler has a maximum of build errors that it can show at any given time.

Once the application compiles, increase the team size and go for Visual Equivalence by distributing the different forms and user controls across your developers.

Visual Basic 6.0 property pages allow you to work around the limitations of the Visual Basic Property Browser. For example, you can use property pages to give users a way to add a collections of colors to a color list user control.

In the property page you would write code that manages the collection, something beyond the capabilities of the Visual Basic Property Browser. In contrast, the Visual Basic .NET Property Browser can be used to edit any .NET variable type or class. Property Pages are no longer needed.

The Upgrade Wizard and the VBUC do not automatically upgrade your Visual Basic 6.0 property pages but they can sure be of help. What if you really what to keep those property pages? Is there any workaround. mmmm Sure there is.

2. Rename the file from .pag to .frm. 3. Remove the .pag from the VB6 project 4. Add the .frm file to the VB6 project 5. Run the VBUC tool.

Once migrated you have a close migration of your original Property Page. Remember however that some things change in .NET and you will need to manually finish some details. For example, you need to review code in the PropertyPage_ApplyChanges(), PropertyPage_EditProperty(PropertyName As String) PropertyPage_SelectionChanged().

Ok. Once you take your Property Page to .NET how do you integrate it with your control. Well that’s easy. There you could create a ControlDesigner or just use an UITypeEditor.

Let’s see the UITypeEditor aproach.

The general idea with this aproach is to provide an UITypeEditor (this is just a way to provide an editor in the property Browser that is not supported by default. And taking advantage of that editor we will show the form that was produced after migrating out Property Pages. If you want an interface more similar to what you had on Visual Basic 6.0 you can modify the property page and add a TabControl.

Ok. So these are the steps to follow:

1. First you need to create a type for which you will provide a Type Editor. We will call this type CustomData

5. In the previous put attention to the highlighted details. What we are doing is getting a reference to the WindowsFormEditor service so we property open the PropertyPage that has now been turned into a form. It is important that you add a public property to the migrated PropertyPage like:

public MyControl control { get; set; };

because that will give you a reference to the actual control that is on the form. The property page is just an interface you will need to set the values into properties on your control, in order for them to be serialized.

6. Once you do that, when you see the property editor for your control you will see something like:

Here is a list of some things that you should consider for Internationalization of Applications.

1. CurrentUICulture and CurrentCulture.

Is is better if you don’t change CurrentUICulture form the the Operating System

2. Windows Forms Layout

Forms must be set Localizable property to true. This will allow you to define different layouts for your forms depending on the current culture.

3. Strongly Typed Resources.

Instead of something like MessageBox.Show(“Invalid code”) use something like:

MessageBox.Show(resourceManager.GetString(“InvalidCode”)) or even better if you strongly type it: MessageBox.Show(Form1Resources.InvalidCode);

4. Localize Exceptions messages.

If you include messages in your exceptions that will be shown somehow on the user interface it is better if your localize those strings also. If exceptions messages are only for developers then you might not need this.

6. Right To Left

In some languages Right to Left is important and is an important aspect to consider. In your forms you have to set the RightToLeftLayout to true and RightToLeft to Yes.

However some controls do not have rtl layoout when RightToLeft=yes: Panel, GroupBos, TabPages and SplitContainerPanels. You need to rearrange the items in these controls to flow from RightToLeft manually. This is an example of rearranging the layout of the controls programmatically at runtime, without changing the Form at design-time:

In case you implement your own drawing, you need to specify how your digits would appear in your DrawString. This is achieved using the StringFormat.SetDigitSubstitution. For more info to this method please refer to the documentation . Below is a code snippet that shows how to display digits using the different enums.

I was playing around with dumpbin trying to figure out some problems with a 32-bit dll and in order to make dumpbin run from the command line I just copied the mspdb100.dll file to C:\Program Files\Microsoft Visual Studio 10.0\VC\bin>

Something simple right! No harm can be gotten from something like that? WRONG!!!

After that some of my C++ project stop compiling with the annoying message: Program database manager mismatch!!.

Luckily I remembered copying that file, so I just gave it a try, and guest what? Everything works fine now.

Well I’m posting it just a reminder that for VS C++ you must put attention on all the details

e. Another typical thing to do in Windows Service is to add a Timer Control, you you can have your windows service performs some actions every number of seconds. To do that, drag a Timer Control on your Service component, execute the Start method of the timer control on the OnStart method and handle the Tick event:

On a previous post I was describing how some basic Objective-C elements were mapped to C#. In particular I showed how the @interface and @implementation definitions are to be mapped in .Net, including basic properties. In this post I will show a little about how methods are migrated.

There are several things to analyze when moving Objective-C code to C# it might be simple but can be a complicated task. Objective-C is a language created under the inspiration of SmallTalk. And in Smalltalk programmer do not think of method calls but instead of message sending and that is something to keep in mind when doing this migration. Also all methods are virtual and even if there are access restriction in Objective-C I will map those methods to public for simplicity sake.

This little example shows some of the particularities of Objective-C. In Objetive-C all parameters starting from the second parameter can have what is called a label and labels are similar to namedParameter. Ok lets go ahead and map that class.

using System;
publicclass MethodsExample
{
publicvirtual print() {
Console.WriteLine("Hola mundo\n");
}
publicvirtualint multiplyByTwo(int n)
{
return n * 2;
}
//AproachOnepublicvirtualint multiplyTwoNumber(int a,int andSecondNumber)
{
return a * andSecondNumber;
}
//AproachTwo//I just renamed as multiplyTwoNumber2 to avoid compilation errors.//The idea is that you will choose one of the two aproaches//or define a criteria for the instances where aproach one should be used//instead of approach twopublicvirtualint multiplyTwoNumber(int a,int andSecondNumber)
{
int n = andSecondNumber;
//This aproach will be better if you have a lot of code in the method//and you prefer to keep the original arg namereturn a * n;
}
}

So the thing here is what to use as the parameter name, the label or the argument name. In the example you can see the two approaches in the multiplyTwoNumbers case.

And calling the methods is simple and the named parameters syntax can be exploited.

REMEMBER: This is just a glimpse of some mapping concepts from Objective-C to C#. There are many subtle details in this kind of migration and is my belief that onlyan automated tool is able to process all those details in an effectively and more error-freethan a manual approach. For example in objective-c if m is null that will not cause any error if youdo something like [m print] and in C# that will throw an error. However a migration tool could determineif the variable will have a value before its use and avoid adding unnecessary if (m!=null) statements.

We will examine this and other details in following posts. I hope this little examples give you enough information

for playing around migrating some Objective-C code. And if it gets too complicated just send me an email!!!

Windows Phone 7 (WP7) is out! and it’s a great platform for developing new Apps. After being involved with Silverlight for a while I am glad to have now the option to deploy apps to Windows Phone 7.

But we have to recognize that there are tons of great Apps for iPhone already. You might even have some of them. So it’s porting time. Here at Artinsoft we love to upgrade/port application to all platforms. So I will provide here some basic thoughts to help you upgrade your code.

For this post let’s discuss a little about applications written for XCode.