-
April 13th, 2000, 05:17 PM
#1
Using FreeLibrary API
Sometimes I get an error stating "The instruction at 'address' referenced memory at 'address'. The memory could not be read." when calling FreeLibrary. Could somebody show me the correct syntax for using FreeLibrary? Here is the code I wrote that sometimes generates this error:
private Function IsDllRegisterable(byval strPath as string) as Boolean
Dim lb as Long, pa as Long
Dim lReturn as Long
' Format our string
strPath = strPath & Chr(0)
' Map dll into the calling process
lb = LoadLibrary(strPath)
If lb = 0 then
IsDllRegisterable = false
Exit Function
End If
' Retrieve the address of the DLLRegisterServer
pa = GetProcAddress(lb, "DllRegisterServer")
' If no address found, not registereable
If pa = 0 then
IsDllRegisterable = false
else
IsDllRegisterable = true
End If
' unmap the library's address
lReturn = FreeLibrary(lb)
End Function
-
April 14th, 2000, 07:42 AM
#2
Re: Using FreeLibrary API
I can't tell what's wrong with your code but the following works:
private Function CanOLERegister(byval sFilename as string) as Boolean
Dim lModule as Long
Dim lProcAddress as Long
Dim bUnload as Boolean
lModule = GetModuleHandle(sFilename)
If lModule = 0 then
lModule = LoadLibrary(sFilename)
bUnload = true
else
'\\ Module handle could not be retrieved...show the error:
If Err.LastDllError > 0 then
MsgBox "GetModuleFilename failed for: " & sFilename & " - error code " & Err.LastDllError
End If
End If
If lModule > 32 then
'\\ Module loaded OK
lProcAddress = GetProcAddress(lModule, RegisterProc)
CanOLERegister = (lProcAddress <> 0)
If bUnload then
Call FreeLibrary(lModule)
End If
else
'\\ Module library could not be loaded...show the error:
If Err.LastDllError > 0 then
MsgBox "LoadLibrary failed for: " & sFilename & " - error code " & Err.LastDllError
End If
End If
DoEvents
If Err.LastDllError > 0 then
Debug.print Err.LastDllError
End If
End Function
HTH,
Duncan Jones
Clearcode Development Ltd
-
April 14th, 2000, 09:16 AM
#3
Re: Using FreeLibrary API
Thanks alot! I'll try your method.
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
|
Click Here to Expand Forum to Full Width
|