1.Any code you write to call a function pointer from Visual Basic must be placed in a standard .BAS module — you can't put the code in a class module or attach it to a form.

解决方案 »

  1.   

    CreateThread是通过第四个参数(你用了lnull)给function传递参数的,而不用在AddressOf 后面加上MyFunction(Val)
      

  2.   

    .FRM调用Option ExplicitPrivate Sub Command1_Click()
    Dim lpThreadId As Long
    Dim THandle As Long
    Dim myNull As Long
    myNull = 0
    THandle = CreateThread(myNull, 0, AddressOf ThreadFunc, 123, 0, lpThreadId)
    If THandle = 0 Then
        MsgBox "Cannot create thread"
    End IfEnd Sub.BAS模块
    Option Explicit
    Public Type SECURITY_ATTRIBUTES
            nLength As Long
            lpSecurityDescriptor As Long
            bInheritHandle As Long
    End TypePublic Type PARAM_TYPE
        lValue As Long
    End TypePublic Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Public Declare Function CreateThread Lib "kernel32" (ByRef lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long
    Public Declare Function GetCurrentThreadId Lib "kernel32" () As Long
    Function ThreadFunc(ByRef lpParam As PARAM_TYPE) As Long
    Dim szStr As String
    szStr = "Thread value:" & CStr(lpParam.lValue) & vbNewLine & _
    "Thread ID: " & CStr(GetCurrentThreadId)MsgBox szStr, , "Function Cool!"ThreadFunc = -2
    End Function
      

  3.   

    我这段程序在VB的IDE里运行正常,但编译成exe后就是无法建立线程。各位大侠,帮帮忙。
      

  4.   

    注册这些控件的任意一个,看看源码就知道了:http://www.csdn.net/cnshare/soft/8/8268.htmlhttp://www.csdn.net/cnshare/soft/8/8269.htmlhttp://www.csdn.net/cnshare/soft/5/5704.html
      

  5.   

    多于一个参数要把参数放在一个结构体里,传给线程函数这个结构体的地址(AddressOf),应该可以,我没有试过。
    另外,线程函数没办法返回你需要的值,但是可以用PostMessage给窗口发消息。
      

  6.   

    1.好象不行;
    2.CreateThread(lnull, lstacksize, (AddressOf MyFunc), lnull, lCreationFlags, 
                                                          ^^^^^参数是放在这的,注意它只是一个指针。
    lpThreadID)