How to do when VB. NET API function or external DLL functions work abnormally?

Posted by NosaLee in .NET Programming on 27-07-2012. Tags: , , , , , , , ,

Author: Nosa Lee
Original Address:
To reprint this article, please indicate the source, thank you.


Sometimes, you may find that an API function or an external DLL function can work normally in VB6 but work abnormally in VB .NET.

Yesterday, I also encountered this problem, after debugged, I found that the Long data type in VB6 should be declared as Integer in VB .NET (in fact, the ranges are same).

For instance, the following VB6 API function:

Declare Function ShellExecuteEx Lib "shell32" (ByRef lp As SHELLEXECUTEINFO) As Long

Should be declared as below in VB .NET

Declare Function ShellExecuteEx Lib "shell32" (ByRef lp As SHELLEXECUTEINFO) As Integer

Please note the different between above two sentences (bold text).

Besides, VB .NET IDE also provides this feature, just click "Tools –> Upgrade Visual Basic 6 Code…" menu item, paste the API declaration, and then click <Upgrade> button, you can get the right VB .NET API declaration sentences.

At last, I need to say: above experience is applicable for the declaration of third-party DLL’s functions, and also applicable for other languages in .NET platform, such as C#.

Post a comment