Vb Migration (not for the weak of mind) Post 2

14. August 2008 05:50 by Mrojas in General  //  Tags: , , , ,   //   Comments (0)

When people decide to migrate their VB6 applications they eventually end up questioning where they should go. Is VB.NET or C# a good choice?

I have my personal preference, but my emphasis is in developing the technology to take where YOU want to go.

VB.NET is a VB dialect very similar to VB6. It supports several constructs and it makes the changes easier.
C# has several differences from VB6, but it has it a growing language with lots of enthusiasts in its community.
Obviously migrating VB6 to VB dialect is a task far more easier than migrating to a different language.
However we are a research company with years of work in this area and challenges is just what we love.

Let's use a methaphor here.

My beautiful wife, was born in Moscow, Russia. Like her, I really enjoy reading a good book. Some of my favorite authors are
russian authors like Dostoievsky, Tolstoi and Chejov. However I still do not speak russian. I have tried, and I will keep trying but
I still don't know russian. I have read only translations of their books, and I really enjoy them.
As a native speaker my wife always tells me, that it is not the same to read those books in another language besides russian.
And they are phrases (specially in Chejov books that I might not completely understand) but I really got the author
message and enjoyed it.
Translating a book from russian to a more similar language like Ucranian is easier than translating it to English or Spanish.
But I think everybody agrees that is a task than can be done.

You can use terrible works case scenarios, but these scenarios must be analized.
Let see (I took these example from the link in that Francesco put in my previous post http://blogs.artinsoft.net/mrojas/archive/2008/08/07/vb-migration-not-for-the-weak-of-mind.aspx)

If you have code like this:

Sub CopyFiles(ByVal throwIfError As Boolean)
    If Not throwIfError Then On Error Resume Next
    Dim fso As New FileSystemObject
    fso.CopyFile "sourcefile1", "destfile1"
    fso.CopyFile "sourcefile2", "destfile2"
    fso.CopyFile "sourcefile3", "destfile3"
    ' seven more CopyFile method calls …
End Sub

and you translate it to:

void CopyFiles(bool throwIfError)
    Scripting.FileSystemObject fso = new Scripting.FileSystemObjectClass();
        fso.CopyFile("sourcefile1", "destfile1", true);
        if (throwIfError)
        fso.CopyFile("sourcefile1", "destfile1", true);
        if (throwIfError)
        fso.CopyFile("sourcefile1", "destfile1", true);
        if (throwIfError)
    // seven more try-catch blocks

I think that the russian is really keep in this translation.

First of all. When you do a translation, you should try to make it as native as possible. So why will you keep using a COM function when there is an
equivalent in .NET. So why not use System.IO.File.CopyFile("sourcefile1", "destfile1", true); instead?

Second of all. The On Error Resume Next, I agree is a not a natural statement in C#. I really think that using it could provide results that are less predictable.
Why? Becuase after executing it, are you sure that all the CopyFile occurred successfully? I would prefer wrapping the whole code inside a try-catch instead of trying
to provide an implementation that is not natural in C#, will Aspect Oriented programming provide a clean solution for this cases. Maybe?

RPG and COBOL to Object Oriented Programming, PowerBuilder to C#, Hierarquical Databases to Relational Databases are just the kind of challenges we have faced in our research project.
Not everything is easy, and we might not be able to automate all the tasks (commonly due to the cost of implementing the automation not becuase of feasability).

But at the end Could you understand the whole novel?, even if you didn't understand the joke in the one of the paragraphs in the page?

My years of reading make be belive that you can.


C# Console Applications and Ctrl-C

11. August 2008 09:41 by Mrojas in General  //  Tags: , , ,   //   Comments (0)

Console applications are still very useful for me.
I write like 125 console applications in the morning and like 4 or 5 in the afternoon.
In one of these applications that was running a long process I just started wandering:
what will happen with Lost? Will ABC ever finish this series?
And If someone presses Ctrl-C will I be able to catch it?
And indeed, the greate C# provides a very easi way to do it:

 static void Main(string[] args)
            Console.CancelKeyPress += 
            delegate(object sender, ConsoleCancelEventArgs e)
                Console.WriteLine("Process aborted by user!");
            //Long running process

VB Migration (not for the weak of mind)

7. August 2008 05:14 by Mrojas in General  //  Tags: , , , ,   //   Comments (0)


I hate to be disappointed. Specially if it is by a person you had respect for. And that's exactly what Francisco Balena from VB Migration Partner, has done. I have respected him for his books and all his VB6 experience. In terms of legacy VB6 code he is a monster. He is the man.

But in terms of code migration...

I'm not saying this because I work on code migration or maybe I'm biased a little by the fact that I work almost 10 years with a company that has done source code migration research on a big number of legacy languages such as COBOL, RPG, PL\1, Algol, Progress, PowerBuilder and also VB6.

I can tell the difference between a "compiler" and a system that rewrites a expression to the closest equivalent in the target language. We are aware of limitations. We are aware of paradigm differences and functional equivalence, but we talk from experience. We talk about our results. And we have proven those things we talk about.

 Let's says you create a Cobol Library with a "MOVE" function, and a COBOLPicture Type and add minus, divide, and add operators. And I write something like:

CobolPicture x = new CobolPicture("XXXX");



We have things like that, and it works. It's feasible and maybe there are cases where that is a solution. But we are also proud of have researchers that have been able to detect pattern to rewrite something like that like:

int x = 0;

x = 10;


And saying, that something is not possible just because you can't or you dont like it, just seem uneducated to me.

 All of this has motivated me to start a series of chapters I for a small blog book I will call VB Migration (not for the weak of mind).

For those of you, who really are tecnology savvy and are in the process of a VB Migration, this is YOUR book.

Log4NET for C++

19. June 2008 03:45 by Mrojas in General  //  Tags: , , , , , ,   //   Comments (0)

Recently my friend Yoel had just a wonderful idea. We have an old Win32 C++ application, and we wanted to add a serious logging infraestructure so we can provide better support in case the application crashes.

So Yoel came with the idea of using an existing framework for logging: LOG4NET

The only problem was, how can we integrate these two together. One way was problably exporting a .NET object as COM. But Yoel had a better idea.

Create a C++ Managed application that will comunicate with the LOG4NET assemblies, and export functions so the native applications can use that. How great is that.

Well he finally made it, and this is the code of how he did it.

First he created a C++ CLR Empty project and set its output type to Library. In the references we add a refrence to the Log4Net Library. We add a .cpp code file and we call it Bridge.cpp. Here is the code for it:

#include <atlstr.h>

using namespace System;

/// <summary>

/// Example of how to simply configure and use log4net


ref class LoggingExample
// Create a logger for use in this class
static log4net::ILog^ log = log4net::LogManager::GetLogger("LoggingExample");static LoggingExample()

public:static void ReportMessageWarning(char* msg)
String^ data = gcnew String(msg);

static void ReportMessageError(char* msg)
String^ data = gcnew String(msg);

static void ReportMessageInfo(char* msg)
String^ data = gcnew String(msg);
static void ReportMessageDebug(char* msg)
String^ data = gcnew String(msg);


extern "C"

_declspec(dllexport) void ReportMessageWarning(char* msg)

_declspec(dllexport) void ReportMessageError(char* msg)

_declspec(dllexport) void ReportMessageInfo(char* msg)

_declspec(dllexport) void ReportMessageDebug(char* msg)


Ok. That's all. Now we have a managed C++ DLL that exposes some functions as an standard C++ DLL and we can use it with native win32 applications.

Let's do a test.

Lets create a Win32 Console application. And add this code:

// Log4NetForC++.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <atlstr.h>
extern "C"

_declspec(dllimport) void ReportMessageWarning(char* msg);

_declspec(dllimport) void ReportMessageError(char* msg);_declspec(dllimport) void ReportMessageInfo(char* msg); _declspec(dllimport) void ReportMessageDebug(char* msg);


int _tmain(int argc, _TCHAR* argv[])
"hello for Log4NET");
"hello for Log4NET");
ReportMessageInfo("hello for Log4NET");
"hello for Log4NET");
return 0;

Ok. Now we just test it and we get something like:


 Cool ins't it :)

Oh my god I screwed up my VS Menu

15. June 2008 18:33 by Mrojas in General  //  Tags: , ,   //   Comments (0)

Ok Ok. I must admitted I have a weird taste to configure my gui. But recently I took it to a the extreme as I (don't know how) delete my File menu.

I managed to get around this thing for a few weeks but finally I fed up. So this gentleman gave me a solution (reset my settings) http://weblogs.asp.net/hosamkamel/archive/2007/10/03/reset-visual-studio-2005-settings.aspx


Dataset save columns as Attributes

5. June 2008 11:07 by Mrojas in General  //  Tags: , , , ,   //   Comments (0)

This code is so handy that I'm posting it just to remember. I preffer to serialize my datasets as attributes instead of elements. And its just a matter of using a setting. See: 

Dim cnPubs As New SqlConnection("Data Source=<servername>;user id=<username>;" & _
"password=<password>;Initial Catalog=Pubs;")
Dim daAuthors As New SqlDataAdapter("Select * from Authors", cnPubs)

Dim ds As New DataSet()
daAuthors.Fill(ds, "Authors")

Dim dc As DataColumn
For Each dc In ds.Tables("Authors").Columns
dc.ColumnMapping = MappingType.Attribute


Console.WriteLine("Completed writing XML file, using a DataSet")

Visual Studio and the nasty No files found

5. June 2008 08:52 by Mrojas in General  //  Tags: , ,   //   Comments (0)

The find in files options of the IDE is part of my daily bread tasks. I use it all day long to get to the darkest corners of my code and kill some horrible bugs.

But from time to time it happens that the find in files functionality stops working. It just starts as always but shows and anoying "No files found..." and i really irritated me because the files where there!!!! !@#$!@#$!@#$

Well finally a fix for this annoyance is (seriously is not a joke, don't question the dark forces):

1.  Spin your chair 3 times for Visual Studio 2003 and 4 times for Visual Studio 2005

2. In Visual Studio 2003 press CTRL SCROLL-LOCK and in Visual Studion 2005 press CTRL and BREAK.

3. Dont laugh, this is serious! It really works.


ActiveX Controls in .NET and the Enabled bug

18. April 2008 07:04 by Mrojas in General  //  Tags: , , , ,   //   Comments (0)

We found and interesting bug during a migration. The issue was that when there was an iteration through the controls in the forms, and you set the Enabled property, the property didn't get set.

After some research my friend Olman found this workaroung


foreach(Control c in Controls)

  ctrl.Enabled = true;
  if (ctrl is AxHost) ((AxHost)ctrl).Enabled = true;

Install Assembly in GAC with C#

9. April 2008 05:42 by Mrojas in General  //  Tags: , , , ,   //   Comments (0)


Do you want to create a program to install your assembly in the GAC using C#. Well if you had that requirement or you are just curious, here is how.

I read these three articles:

Demystifying the .NET Global Assembly Cache

GAC API Interface 

Undocumented Fusion

What I wanted just a straight answer of how to do it. Well here is how:


using System;
using System.Collections.Generic;
using System.Text;
using System.GAC;
//// Artinsoft
//// Author: Mauricio Rojas orellabac@gmail.com mrojas@artinsoft.com
//// This program uses the undocumented GAC API to perform a simple install of an assembly in the GAC
namespace AddAssemblyToGAC
    class Program
        static void Main(string[] args)
            // Create an FUSION_INSTALL_REFERENCE struct and fill it with data
            FUSION_INSTALL_REFERENCE[] installReference = new FUSION_INSTALL_REFERENCE[1];
            installReference[0].dwFlags = 0;
            // Using opaque scheme here
            installReference[0].guidScheme = System.GAC.AssemblyCache.FUSION_REFCOUNT_OPAQUE_STRING_GUID;
            installReference[0].szIdentifier = "My Pretty Aplication Identifier";
            installReference[0].szNonCannonicalData= "My other info";
            // Get an IAssemblyCache interface
            IAssemblyCache pCache = AssemblyCache.CreateAssemblyCache();
            String AssemblyFilePath = args[0];
            if (!System.IO.File.Exists(AssemblyFilePath))
                Console.WriteLine("Hey! Please use a valid path to an assembly, assembly was not found!");
            int result = pCache.InstallAssembly(0, AssemblyFilePath,installReference);
            //NOTE recently someone reported a problem with this code and I tried this:
            // int result = pCache.InstallAssembly(0, AssemblyFilePath,null); and it worked. I think is a marshalling issue I will probably review it later
            Console.WriteLine("Process returned " + result);

And here's the complete source code for this application: DOWNLOAD SOURCE CODE AND BINARIES

Useful MSBuild Custom Tasks

3. April 2008 08:48 by Mrojas in General  //  Tags: , , , ,   //   Comments (0)

I present here the implementation of some useful tasks
In Artinsoft we perform massive migrations of VB6 code to VB.Net
and C#.

And sometimes after migration there are customizations to be
performed on the code, to add new functionality or to set certain new

 The idea was to provide a couple of very simple and puntual MSBuildTask
 to illustrate how easy it is to create custom tasks and to provide a starting
 point to create new one.

 You can freely use this code, just keep this comments and remember this is just
 a sample code. There are not warranties. ;) And i made it a rush I know it could have
 been written better


The implemented tasks are:

 Removes COMReferences from your project. COM references are for when you are using things thru Interop
 Resets the output paths to bin\Release and bin\Debug
AddProjectReference Add a reference to another project. A nice feature is that it generates RelativePaths the way Visual Studio does
AddSimpleReference Add a reference to a very simple references like the ones you add when you click Add Reference and add System.EnterpriseServices
ChangeCurrentBuildSetting This can be used for a lot of things.

For example to turn on or off the RegisterForComInterop setting

To set conditional compilation variables

To set debug info to pdbonly

The sky is the limit jeje

The following is a sample project file

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- make sure that the Assembly is in a place where msbuild can find it, a simple way is just to put it 
in the same directory of your .proj file -->
<UsingTask TaskName="SomeUsefulTasks.MSBuild.RemoveCOMReference"    
<UsingTask TaskName="SomeUsefulTasks.MSBuild.FixOutputPath"         
<UsingTask TaskName="SomeUsefulTasks.MSBuild.AddProjectReference"   
<UsingTask TaskName="SomeUsefulTasks.MSBuild.AddSimpleReference"    
<UsingTask TaskName="SomeUsefulTasks.MSBuild.ChangeProjectBuildSetting"    
    <VSProjects Include="$(Start)\**\*.*proj" />
Run with 
MSBUILD SampleProject.proj /target:COMReference /p:Start="C:\MyCode"
  <Target Name="COMReference">
    <RemoveCOMReference SourceFiles="@(VSProjects)" ComReferenceName="MSXML2" />
Adds a project reference  
Run with 
MSBUILD SampleProject.proj /target:AddProjectReference /p:Start="C:\MyCode" /p:ProjectPath="C:\MyCode\MyNewSuperProject\Project1.csproj"
   <Target Name="AddProjectReference">
      <AddProjectReference SourceFiles="@(VSProjects)"  AbsolutePathToProject="$(ProjectPath)"/>
Adds a reference to a standard assembly 
Run with 
MSBUILD SampleProject.proj /target:AddSimpleReference /p:Start="C:\MyCode" /p:Reference="System.EnterpriseServices"   
<Target Name="AddSimpleReference">
      <AddSimpleReference SourceFiles="@(VSProjects)" Reference="$(Reference)" />
Resets the OutputPaths to .\bin\Debug and .\bin\Release 
Run with 
MSBUILD SampleProject.proj /target:FixOutput /p:Start="C:\MyCode" /p:Reference="System.EnterpriseServices"   
<Target Name="FixOutput">
    <FixOutputPath SourceFiles="@(VSProjects)"  />
Adds a reference to a standard assembly 
There are several options here for example to set the project debug info to pdb-only do this:
Run with 
MSBUILD SampleProject.proj /target:ChangeSettingToPDBOnly /p:Start="C:\MyCode" 
Or run with 
MSBUILD SampleProject.proj /target:ChangeSettingAddAConstant /p:Start="C:\MyCode" 
Or run with 
MSBUILD SampleProject.proj /target:SettingComInterop /p:Start="C:\MyCode" 
<Target Name="ChangeSettingToPDBOnly">
          NewValue="pdbonly" />
<Target Name="ChangeSettingAddAConstant">
<Target Name="SettingComInterop">
         NewValue="true" />


Get Relative Path

3. April 2008 04:24 by Mrojas in General  //  Tags: , , ,   //   Comments (0)

I had the requirement of creating a MSBuild custom task that opens a .csproj
adds a reference to another project.

The problem I faced is that references in VisualStudio are generated as relative paths,
so I needed something to help me generate relative paths.

After some Googleing I finally found this code. It was in a long forum discussion
and was posted by a guy named something like Marcin Grzabski. And here it is for posterity.

        private static string EvaluateRelativePath(string mainDirPath, string absoluteFilePath)
            firstPathParts = 
            secondPathParts = 
            int sameCounter = 0;
            for (int i = 0; i < Math.Min(firstPathParts.Length,secondPathParts.Length); i++)
                if (
            if (sameCounter == 0)
                return absoluteFilePath;
            string newPath = String.Empty;
            for (int i = sameCounter; i < firstPathParts.Length; i++)
                if (i > sameCounter)
                    newPath += Path.DirectorySeparatorChar;
                newPath += "..";
            if (newPath.Length == 0)
                newPath = ".";
            for (int i = sameCounter; i < secondPathParts.Length; i++)
                newPath += Path.DirectorySeparatorChar;
                newPath += secondPathParts[i];
            return newPath;

And to use is just do somelines like:


            String test = EvaluateRelativePath(@"E:\Source_Code\Code\ProjectsGroup1\Project1", @"E:\Source_Code\Code\ProjecstGroup2\Project2");
//This will genearate something like ..\..\ProjectGroup2\Project2

Pretty Printers / Format Code / for C# VB.NET

4. March 2008 09:49 by Mrojas in General  //  Tags: , , ,   //   Comments (0)

In my past life I spent a few eons writing Java code. And it wasn't bad. We had nice tools like Jalopy! that allowed us to have
code in a very standard way.

And I missed that. I've been looking around for something similar but I havent found anything like that :(

Until I found a great post from Chris Eargle, he improved the original solution from Kelvinpinch

Well here's the code.

Public Sub FormatSolution()
Dim sol As Solution = DTE.Solution
For i As Integer = 1 To sol.Projects.Count
End Sub 
Private Sub FormatProject(ByVal proj as Project)
     For i As Integer = 1 To proj.ProjectItems.Count
End Sub
Private Sub FormatProjectItem(ByVal projectItem As ProjectItem)
     If projectItem.Kind = Constants.vsProjectItemKindPhysicalFile Then
          If projectItem.Name.LastIndexOf(".cs") = projectItem.Name.Length - 3 Then
Dim window As Window = projectItem.Open(Constants.vsViewKindCode)
End If
End If
'Be sure to format all of the ProjectItems.
If Not projectItem.ProjectItems Is Nothing Then
For i As Integer = 1 To projectItem.ProjectItems.Count
End If
'Format the SubProject if it exists.
     If Not projectItem.SubProject Is Nothing Then
End If
End Sub

To use it perform the following steps:

  •  Go to the VS IDE Tools Option
  • Then Select the Macros option and select Macros IDE...
  • This will open the macros IDE
  • In the Macros IDE navigate to the Module1, and Insert the code

To run the Macro go to Tools\Macros\Macro Explorer

And select FormatAll :)

And last but not least if you want to runit from the command line just do:

devenv /command "Macros.MyMacros.Module1.FormalAll" MyProject.csproj or

devenv /command "Macros.MyMacros.Module1.FormalAll" MySol.sln or


ActiveX exceptions when running in .NET

5. February 2008 04:11 by Mrojas in General  //  Tags: , , , ,   //   Comments (0)

During migration to C# or .NET it is easier to keep the same ActiveX.
The VBCompanion does a great work in migrating the ActiveX control using the .NET ActiveX wrappings and fixing all method calls. 
Sadly sometimes those ActiveX do not work properly in .NET.

Well we have good news.
Recently my friend Jose David (who we keep bothering because he is now 
a Project Manager and now he only programs in MS Excel and MS Project, I added the MS by his request :P) fixed a curious bug
we had with an aplication we migrated from VB6 to C#.

The thing is that the aplication had an ActiveX control with a strange runtime behaviour.
We migrated the application keeping the ActiveX control and in most ocasions it worked ok.

But randomly it started throwing exceptions.

During the testing he discovered that if he repeated the steps slowly the bug did not reproduced.

So his idea was that it was due a garbage collection issue. And SURPRINSINLY he was right :P

He added this:




 And the application started to work.

It seems like some of the COM objects needed a little more time for releasing all references :)


IsMissing migration in VB.NET or C#

4. February 2008 11:43 by Mrojas in   //  Tags: , , , , , ,   //   Comments (0)

Recently  we added some support for migrating the IsMissing function to VB.NEt or C#

The thing is. In VB6 the IsMissing Function is TRUE only if you have something like:

Public Sub Foo(Optional str)


Where you dont specify the variable type, or if you have


Public Sub Foo(Optional str as Variant)


And is IsMissing is FALSE for any other case. Including Optional variables whose definition type is not Variant.


So let's see some examples to illustrate the idea:
 Example 1:

Public Sub Foo(str, a As Integer, b As Integer, Optional c As Integer)
    MsgBox (str & "Foo Is missing a " & IsMissing(a))
    MsgBox (str & "Foo Is missing b " & IsMissing(b))
    MsgBox (str & "Foo Is missing c " & IsMissing(c))
End Sub


It occurs that IsMissing is really FALSE in all cases. So it is equivalent to:


Public Sub Foo(str, a As Integer, b As Integer, Optional c As Integer)
    MsgBox (str & "Foo Is missing a " & false)
    MsgBox (str & "Foo Is missing b " & false)
    MsgBox (str & "Foo Is missing c " & false)
End Sub



Example 2:


Public Sub Goo(str, a As Integer, b As Integer, Optional c As Object, Optional d As Byte, Optional e)
    MsgBox (str & "Goo Is missing a" & IsMissing(a))
    MsgBox (str & "Goo Is missing b" & IsMissing(b))
    MsgBox (str & "Goo Is missing c" & IsMissing(c))
    MsgBox (str & "Goo Is missing d" & IsMissing(d))
    MsgBox (str & "Goo Is missing e" & IsMissing(e))
End Sub


All cases EXCEPT "e" are equivalent to FALSE


Public Sub Goo(str, a As Integer, b As Integer, Optional c As Object, Optional d As Byte, Optional e)
    MsgBox (str & "Goo Is missing a" & false)
    MsgBox (str & "Goo Is missing b" & false)
    MsgBox (str & "Goo Is missing c" &false)
    MsgBox (str & "Goo Is missing d" & false)
    MsgBox (str & "Goo Is missing e" & IsMissing(e))
End Sub


So if you are migrating your VB6 Code to C# put attention to these little details it can save you a lot of time.And remember that this is just one feature of VBCompanion tool ;)


Case Sensitive SQL Server

26. October 2007 06:29 by Mrojas in General  //  Tags: , , , ,   //   Comments (0)
Recently a friend at work had a problem querying a SQL server that indicated that the column name was wrong.

The only thing wrong was the the case. For example he had COLUMN1 instead of Column1. I had never seen that problem in SQLServer.
I had seed that in Sybase but not in SQLServer. He solved that by changing the database collating sequence to something like this:

alter database database1 collate SQL_Latin1_General_CP1_CI_AI

the CI in the collating indicates Case Insensitive

For more information on SQL Server collations check: http://msdn2.microsoft.com/en-us/library/aa258233(SQL.80).aspx

And you determine your current database collation use a code like this:

USE yourdb>

print 'My database [' + db_name() + '] collation is: ' + cast( DATABASEPROPERTYEX ( db_name(), N'Collation' ) as varchar(128) )

print 'My tempdb database collation is: ' + cast( DATABASEPROPERTYEX ( 'tempdb', N'Collation' ) as varchar(128) )


Track Changes in VSS (Visual Source Safe)

24. October 2007 06:18 by Mrojas in General  //  Tags: , , , , ,   //   Comments (0)

MS VSS (Visual SourceSafe) is not really my preferred Source Control application, but
sometimes in your company that is what is available and you need to used it to have
at least some versioning of the code.

But haven't you had a situation where last week everything worked and
now everything is broken. And now is up to you to determine what went
wrong? I have it all the time.

VSS have some search tools but I really do not enjoy using them.
The Code Project Site provides an excellent tool called VssReporter

Sample Image - VssReporter.jpg

Do take a look at it, it makes it more easy to track changes. :)


Get GUIDs/CLSIDs from Exe, dll, ocx, tlb, etc

23. October 2007 10:08 by Mrojas in General  //  Tags: , ,   //   Comments (0)

A simple way of getting the GUID from an exe, dll, ocx, tlb is using the  TLBINF32.dll

This file is in the system path and it must be registered
(Remember to use regsvr32 if you haven't registered).

            TLI.TLIApplicationClass a = new TLI.TLIApplicationClass();

                TLI.TypeLibInfo inf = a.TypeLibInfoFromFile(@"c:\windows\system32\MSHFLXGD.OCX");
                "TypeLibrary Name " +  inf.Name + "\r\n" + //name of (Type Library)
                "Tlb ID " +  inf.GUID + "\r\n" + // GUID for Library
                "LCID "  + inf.LCID + "\r\n" + // Language / Country
                "Major Version "+ inf.MajorVersion + "\r\n" + // Major Version
                "Minor Version "+ inf.MinorVersion); // Minor Version
                for (short i = 1; i < inf.TypeInfoCount; i++)

                    TLI.TypeInfo inf2 = inf.TypeInfos[i];
                    MessageBox.Show("CLSID " + inf2.Name + " - " + inf2.GUID,i + " of " +

            catch (Exception ee)
                MessageBox.Show("No guid");



MAN for .NET

5. October 2007 03:32 by Mrojas in General  //  Tags: , , , ,   //   Comments (0)
Microsoft recently published the MTPS Content Service

In brief, the MTPS Content Services are a set of
web services for exposing the content in
Microsoft/TechNet Publishing System (MTPS).

And Craig Andera, has develop a swift nice tool
called msdnman that you use from the command line to
get information from the MSDN

Also I recommend you to see this cool video of a Human LCD that Hugo sent me

VB6 Printer Object and PrintForm migration

1. October 2007 10:55 by Mrojas in General  //  Tags: , , ,   //   Comments (0)

If you ever had any problems while migrating from VB6 Printer Object or the PrintForm functionality
we have goods news for you the Microsoft Visual Basic 2005 Power Pack 2.0.
Our version of the Visual Basic Companion already provides and extended migration of the Printer Object,
and we're now updating it to use this new implementation. This Printer Compatibility Library makes it a
breeze to migrate Printer Functionality.

This is the description of the PowerPack:

"The new Line and Shape controls included in this version of the Visual Basic 2005 Power Packs are
a set of three graphical controls that enable you to draw lines, ovals, and rectangles on forms and
containers at design time making it much easier to enhance the look of your user interface.
These new shape controls also provide events such as click and double-click allowing developers
to respond and interact with end users.

The Printer Compatibility Library allows projects that used the Printer and Printers Collection in Visual Basic 6.0
 to be upgraded without having to re-write your printing logic. By simply adding a reference to the library, declaring a
Printer and making a few minor syntax changes, your project will be able to print using the Printers collection
and Printer object as it did in Visual Basic 6.0. This version adds a new Write method to the Printer object which
allows you to print text without a forced carriage return similar to the semicolon syntax used by Print method in Visual Basic 6.0.

The PrintForm component is designed to bring back the ability to easily print a Windows Form.
With this the new PrintForm component you can once again layout the Windows Form exactly as
you want it and allow your users to print the form as a quick report."

You can download the PowerPack from here

NOTE: there's is another link that only includes the Printer Library but MS recommends to download the PowerPack
because minor upgrades and fixes will be done on the PowerPack distribution


VB6 API calls to .NET

27. September 2007 10:06 by Mrojas in General  //  Tags: , , , ,   //   Comments (0)
Every SERIOUS VB6 application, ended up requiring
that you import some functionality from the windows API or another DLL.
However if you were looking for a .NET equivalent and
google did not take you to the right page,
there is a document (a little old I might say) called
Microsoft Win32 to Microsoft .NET Framework API Map

I remember a couple of other pages that were even more complete,
but right know I can only remember http://pinvoke.net that gives some info about APIs