vb点虐 主入口函数 vbnet invoke

如何正确理解VB.NET函数调用

1. Shared Function System.Runtime.

创新互联服务项目包括辽阳网站建设、辽阳网站制作、辽阳网页制作以及辽阳网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,辽阳网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到辽阳省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

InteropServices.DLLimport("user32.dll")

2. MessageBoxA(ByVal hwnd As Integer,

ByVal text As String, ByVal

lpcaption As String, ByVal

wtype As Integer) As Integer

3. End Function

首先integer被作为32位数据替代了long(long是64位)

System是Net语言中的一个族,System.Runtime.InteropServices是system中的一个类。System.Runtime.InteropServices.DLLimpor是其中的一个方法。调用DLL的API

接口,这个的意思就是vb6的lib"user32", share是共享的意思,例如:

1. Public Class classA

2. Shared Function System.Runtime.

InteropServices.DLLimport("user32.dll")

MessageBoxA(ByVal h As Integer,

ByVal m As String, ByVal c As

String, ByVal type As Integer) As Integer

3. End Function

4. End Class

你可以这样调用 classA.MessageboxA 但是如果没有这个share 在class后打点就没有MessageboxA的成员出现了 ,现在你就象以前一样的使用他吧。

其实上面这个VB.NET函数调用方法并不正确,我们仍旧要使用API声明,只是换了一各形式

如果你认为这就是VB.NET就错了,看看这个:

system.WinForms.MessageBox.Show("对话内容写在这里", "标题写在这里", messagebox.OK BitOr messagebox.IconAsterisk)

这就是面向对象,你已经完成了所有的任务。不需要任何的API声明。不需要写多余的代码。

1. messagebox.IconAsterisk=惊叹号图标

2. messagebox.IconError=错误图标

3. messagebox.IconExclamation=警告图标

4. messagebox.IconHand=错误图标

5. messagebox.IconInformation=提示图标

所经点NET就是打点到达,在族后面打点,在类后面打点,在对象后面打点。第二个问题就是类与类之间相互的关系,Net在网上处理人与人的关系,在程序语言中处理类与类的关系。倒底是加不加share,倒底是类后面打点,还是Dim成一个对象(把他当一个变量吧)再说,是等于class,还是New class.是dim xxx as class=new class 还是dim xxx as new class

就是这样VB.NET函数调用将更简单,不须要研究一些很难的东西。

详细阐述 vb点虐 中main

每个 Visual Basic 应用程序均必须包含一个称为VB.NET Main过程。该过程为应用程序的起始点并为应用程序提供总体控制。.NET Framework 在已加载应用程序并准备将控制传递给它时,将调用 Main 过程。除非您要创建 Windows 窗体应用程序,否则就必须为自运行的应用程序编写 Main 过程。

Main 中包含首先运行的代码。在 Main 中,可以确定在程序启动时首先加载的窗体,确定系统上是否已在运行您的应用程序副本,为应用程序建立一组变量,或者打开应用程序需要的数据库。

VB.NET Main过程的要求

独立运行的文件(扩展名通常为 .exe)必须包含 Main 过程。库(例如,扩展名为 .dll)不独立运行,因而不需要 Main 过程。可以创建的不同类型的项目的要求如下:

控制台应用程序可以独立运行,而且您必须提供至少一个 Main 过程。

Windows 窗体应用程序可以独立运行。但是,Visual Basic 编译器会在此类应用程序中自动生成一个 Main 过程,因而您不需要编写此过程。

类库不需要 Main 过程。这些类库包括 Windows 控件库和 Web 控件库。作为类库部署 Web 应用程序。

声明VB.NET Main过程

有四种方法可以声明 Main 过程。它可以使用参数或不使用参数,可以返回值或不返回值。

注意

如果在类中声明 Main 过程,则必须使用 Shared 关键字。在模块中,Main 不必是 Shared。

最简单的方法是声明一个不使用参数或不返回值的 Sub 过程。

Module mainModule

Sub Main()

MsgBox("The Main procedure

is starting the application.")

' Insert call to appropriate

starting place in your code.

MsgBox("The application

is terminating.")

End Sub

End ModuleMain

还可以返回一个 Integer 值,操作系统将其作为程序的退出代码。其他程序可以通过检查 Windows ERRORLEVEL 值来测试该代码。若要返回退出代码,必须将VB.NET Main过程声明为 Function 过程而不是 Sub 过程。

Module mainModule

Function Main() As Integer

MsgBox("The Main procedure

is starting the application.")

Dim returnValue As Integer = 0

' Insert call to appropriate

starting place in your code.

' On return, assign appropriate

value to returnValue.

' 0 usually means successful

completion.

MsgBox("The application is

terminating with error level " _

CStr(returnValue) ".")

Return returnValue

End Function

End ModuleMain

还可以采用一个 String 数组作为参数。数组中的每个字符串均包含一个用于调用程序的命令行参数。您可以根据它们的值采取不同的操作。

Module mainModule

Function Main(ByVal cmdArgs()

As String) As Integer

MsgBox("The Main procedure is

starting the application.")

Dim returnValue As Integer = 0

' See if there are any arguments.

If cmdArgs.Length 0 Then

For argNum As Integer = 0 To

UBound(cmdArgs, 1)

' Insert code to examine cmdArgs

(argNum) and take

' appropriate action based on its value.

Next argNum

End If

' Insert call to appropriate starting

place in your code.

' On return, assign appropriate

value to returnValue.

' 0 usually means successful completion.

MsgBox("The application is

terminating with error level " _

CStr(returnValue) ".")

Return returnValue

End Function

End Module

可以声明VB.NET Main过程来检查命令行参数而不返回退出代码,如下所示。

Module mainModule

Sub Main(ByVal cmdArgs() As String)

MsgBox("The Main procedure is

starting the application.")

Dim returnValue As Integer = 0

' See if there are any arguments.

If cmdArgs.Length 0 Then

For argNum As Integer = 0 To

UBound(cmdArgs, 1)

' Insert code to examine cmdArgs

(argNum) and take

' appropriate action based on its value.

Next argNum

End If

' Insert call to appropriate

starting place in your code.

MsgBox("The application is

terminating."

End Sub

End Module

vb点虐 工程的main函数在哪个文件

看来您不了解vb点虐 的程序结构。vb点虐 的Windows方面的工程分为两种:窗体应用程序和控制台应用程序。窗体应用程序没有Main函数,直接从一个窗体启动(例如启动对象设置为Form1),启动时会自动加载Form1.Designer.vb获得控件信息(窗体设计器自动生成),Form1.vb获得你编写的代码和事件处理程序。控制台应用程序需要从一个Module启动。一个控制台应用程序可以含有多个模块,但启动时只调用选择的启动对象里面的Sub Main()。


当前题目:vb点虐 主入口函数 vbnet invoke
本文地址:http://myzitong.com/article/ddedjjh.html