-
Why reading from memory at runtime cause crash but works fine in debug
The code below works fine if I run it from vb but causes this error at runtime:
S caused an invalid page fault in
module OLEAUT32.DLL at 0177:7fe81543.
It gets a string from a listbox. It does this in Win98/95/2000
Any idea why? I'm desperate!!!
===================
Option Explicit
Declare Function GlobalAlloc Lib "KERNEL32" (ByVal wFlags As Long, ByVal
dwBytes As Long) As Long
nIDDlgItem As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam
As Long) 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
Declare Function agGetStringFromPointer$ Lib "apigid32.dll" Alias "agGetStringFromLPSTR"
(ByVal ptr&)
Declare Function agGetAddressForLong& Lib "apigid32.dll" Alias "agGetAddressForObject"
(intnum&)
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal
wCmd As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetDlgItem Lib "user32" (ByVal hDlg As Long,
ByVal nIDDlgItem As Long) As Long
Public Const GW_CHILD = 5
Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDLAST = 1
Public Const GW_HWNDNEXT = 2
Public Const BM_SETCHECK = &HF1
Public Const BM_SETSTATE = &HF3
Public Const WM_SETFOCUS = &H7
Public Const WM_KILLFOCUS = &H8
Public Const LB_SETCURSEL = &H186
Public Const LB_GETTEXT = &H189
Public Const LB_GETCOUNT = &H18B
Public Const GMEM_FIXED = &H0
Public Sub Main()
Dim pStr As Long
Dim filesProcessed, fileName, errDesc As String
Dim hStorageButton, hLB, hRFDlg, LBFileCount, fileSelectedIdx, res, hwnd
As Long
Dim done, match As Boolean
pStr = GlobalAlloc(GMEM_FIXED, 256)
hRFDlg = FindWindow(vbNullString, "Recall file")
hLB = GetDlgItem(hRFDlg, &H5E2)
Debug.Print SendMessage(GetWindow(hLB, GW_CHILD), LB_GETTEXT, fileSelectedIdx,
pStr)
Debug.Print agGetStringFromPointer(agGetAddressForLong&(pStr))
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks