为什么这个VB API程序在2000下运行会出错?

JLBB102 2009-02-03 09:20:08
窗体和模块代码如下,直接copy到VB6环境下即可,我用VB6环境在xp和2000下调试时均没有问题,但是生成EXE可执行文件在2000下运行报错是怎么回事?


窗体代码:
Private Sub Command1_Click()
Dim hThread, lpThreadID As Long
Dim a As String
g_bDone = False
g_strTitle = "Set Option"
hThread = CreateThread(ByVal 0&, ByVal 0&, AddressOf HookInputBoxThread, ByVal 0&, 0, lpThreadID)
a = Trim(InputBox("Please input the correct Password!" + vbCrLf + "Operator can not close it!", g_strTitle))
If a <> "" Then
If a = "bmpadmin" Then
'***************************
isSetting = True
cmdSend.Visible = False
CmdClr.Visible = False

frmnetSend.Height = FrmSettingHeight
SettingFrame.Top = 480
SettingFrame.Visible = True
BgBottom.Top = 2280
back.Visible = True
'***************************
Else
MsgBox "The Password isn't correct!", 0 + 16, "Warning"
'Cancel = 1
End If
Else
' Cancel = 1
End If
End Sub




模块代码如下:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function GetDlgItem Lib "user32" (ByVal hDlg As Long, ByVal nIDDlgItem As Long) As Long
Public Declare Function CreateThread Lib "kernel32" (ByVal lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, ByVal lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
Public Declare Function SetFocus Lib "user32.dll" (ByVal hwnd As Long) As Long

Public Const EM_SETPASSWORDCHAR = &HCC
Public Const HWND_TOPMOST& = -1
Public Const SWP_NOSIZE& = &H1
Public Const SWP_NOMOVE& = &H2

Public g_bDone As Boolean
Public g_strTitle As String



Public Sub HookInputBoxThread()
Do Until g_bDone
Dim h As Long, hText As Long
h = FindWindow("#32770", g_strTitle)
If h <> 0 Then
hText = GetDlgItem(h, &H1324)
If hText <> 0 Then
SendMessage hText, EM_SETPASSWORDCHAR, Asc("*"), 0
g_bDone = True
End If
End If
Loop
End Sub


补充:
1,在其它2000系统一样有问题,不知道是不是API的问题?
2,没有提示任何ocx和dll文件缺少,有提示的话早就解决了.
3,我没有打包操作,我想知道问题的根本
4,提示信息:"工程1.exe has generated errors and will be closed by Windows.You will need to restart the program.
An error log is being created."
...全文
188 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
PctGL 2009-02-10
  • 打赏
  • 举报
回复
....
我倒啊
JLBB102 2009-02-10
  • 打赏
  • 举报
回复
谢谢,因为比较急,我已经曲线解决问题了!
m60a1 2009-02-10
  • 打赏
  • 举报
回复
LZ,多线程有问题
hThread = CreateThread(ByVal 0&, ByVal 0&, AddressOf HookInputBoxThread, ByVal 0&, 0, lpThreadID)

这在IDE里面是没有问题的,但成了PE文件后,执行就有问题,因为VB6.0的多线程是不安全的,很正常LZ

建议楼主如果一定要用多线程,用VC++写一个,然后VB调
JLBB102 2009-02-09
  • 打赏
  • 举报
回复
CoInitializeEx 0, 0 ' >>>>>>> <> 0

WriteProcessMemory -1, ByVal i, &HC3, 1, 0 '这个忘了...
以上两句都问题,哎
PctGL 2009-02-07
  • 打赏
  • 举报
回复

从你的代码来看... 要说是不应该的...
JLBB102 2009-02-06
  • 打赏
  • 举报
回复
运行中.......
失败,再次运行中.......
PctGL 2009-02-05
  • 打赏
  • 举报
回复
代码都给你了,你为什么不去试试
JLBB102 2009-02-05
  • 打赏
  • 举报
回复
其实我这个程序的本意是想实现inputbox输入时显示“×”米字,比如输入的是密码,显示的不是字母或数字,所以采用上面的做法。
如果上面不是好的方法,那么有没有除了画个类似inputbox窗体以外的其他方法可以实现inputbox输入时显示“×”米字。请各位赐教?
Tiger_Zhao 2009-02-05
  • 打赏
  • 举报
回复
见鬼,刚才的回复不成功!
控制对话框不需要多线程,CBT Hook 就可以了,参考:
http://vbworld.sxnw.gov.cn/articles/openfile.asp?kind=api&id=67&filename=htmapi67.htm
netsocket 2009-02-05
  • 打赏
  • 举报
回复
up
嗷嗷叫的老马 2009-02-05
  • 打赏
  • 举报
回复
貌似这种多线程不是VB6支持的.....
PctGL 2009-02-04
  • 打赏
  • 举报
回复
创建线程部分的代码,这样写

CoInitializeEx 0, 0 ' >>>>>>> <> 0
i = GetProcAddress(GetModuleHandle("msvbvm60"), "__vbaSetSystemError") '<> 0
WriteProcessMemory -1, ByVal i, &HC3, 1, 0 '这个忘了...
hThread = CreateThread(ByVal 0&, ByVal 0&, AddressOf HookInputBoxThread, ByVal 0&, 0, lpThreadId)
If hThread Then MsgBox "线程创建成功,线程句柄: " & hThread & vbCrLf & vbCrLf & " 线程 ID: " & lpThreadId

如果有错,检查一下api调用的返回值都对不对
注释的东西就是那个api应该返回的值,如果执行成功的话
JLBB102 2009-02-04
  • 打赏
  • 举报
回复
谢谢PctGL & Tiger_Zhao ,我只有到公司才可以调试,家里电脑xp系统。另外由于公司网络禁止登录论坛,所以在公司又无法浏览此贴,真是一点不方便!唉
Tiger_Zhao 2009-02-04
  • 打赏
  • 举报
回复
[Quote=MSDN:]
DWORD WINAPI ThreadProc(
LPVOID lpParameter // thread data
);[/Quote]
你的 HookInputBoxThread() 不符合 ThreadProc
还有 HookInputBoxThread() 不应该使用任何全局变量,要通过 lpParameter 传递参数。
JLBB102 2009-02-04
  • 打赏
  • 举报
回复
楼上两位大虾能否帮小弟修改一下源代码,跪拜,谢谢,小弟HOOK和创建线程这块不是太熟!

邮箱:jlbb102@yahoo.com.cn
JLBB102 2009-02-03
  • 打赏
  • 举报
回复
虽然提示有错误日志产生,但是我并没有看见错误日志文件的存在。
jsnjfzm 2009-02-03
  • 打赏
  • 举报
回复
帮顶
noenoughmemory 2009-02-03
  • 打赏
  • 举报
回复
帮顶
SYSSZ 2009-02-03
  • 打赏
  • 举报
回复
"工程1.exe has generated errors and will be closed by Windows.You will need to restart the program. An error log is being created."
工程1.exe发生错误,将被Windows关闭,你需要重新启动程序,一个错误日志正在建立.
在工程所在目录下查找错误日志,看错误日志怎么说.
JLBB102 2009-02-03
  • 打赏
  • 举报
回复
不是很理解楼上所说含义,能够具体一点,或者如何修改源码2000下不出错?
加载更多回复(1)

1,488

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧