|
-
Aug 25th, 2006, 06:23 PM
#1
Thread Starter
Hyperactive Member
If my file isn't there load other form???
Sorry, couln't come up with a better title...........
I need a code that when your form loads if a file isn't in a location(its a dll)
It goes to another form.(dllnot.frm)
Is there a way of doing this?????
-
Aug 25th, 2006, 06:33 PM
#2
Re: If my file isn't there load other form???
Do you mean something like this...
VB Code:
If Len(Dir("path and name of your file")) = 0 Then ' File is missing
' load form1
Else
' load form2
End If
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Aug 25th, 2006, 06:35 PM
#3
Re: If my file isn't there load other form???
Hehe, just happened to code this the other day:
VB Code:
' in a module
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function GetModuleHandle Lib "kernel32" (ByVal lpModuleName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function LoadLibrary Lib "kernel32" (ByVal lpLibFileName As String) As Long
Public Function IsFunctionSupported(ByRef FunctionName As String, ByRef ModuleName As String) As Boolean
Dim lngModule As Long, blnUnload As Boolean
' get handle to module
lngModule = GetModuleHandle(ModuleName)
' if getting the handle failed...
If lngModule = 0 Then
' try loading the module
lngModule = LoadLibrary(ModuleName)
' we have to unload it too if that succeeded
blnUnload = (lngModule <> 0)
End If
' now if we have a handle to module...
If lngModule <> 0 Then
' see if the queried function is supported; return True if so, False if not
IsFunctionSupported = (GetProcAddress(lngModule, FunctionName) <> 0)
' see if we have to unload the module
If blnUnload Then FreeLibrary lngModule
End If
End Function
Usage example: we try to see if DrawTextW is supported or not so we know if we need to fallback to ANSI.
VB Code:
If IsFunctionSupported("DrawTextW", "user32.dll") Then
' use DrawTextW
Else
' use DrawTextA
End If
Note that you can declare the APIs like normally (in this case both DrawTextA and DrawTextW would be declared), this just lets you check if you can use a function so you don't need to make a complex error checking workaround. This also works for checking if a DLL is in place, of course.
-
Aug 25th, 2006, 06:46 PM
#4
Re: If my file isn't there load other form???
Hey Merri, that could be very useful code... well done
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Aug 26th, 2006, 05:48 PM
#5
Thread Starter
Hyperactive Member
Re: If my file isn't there load other form???
merrit, your code is very useful but not what i'm after, I tried your pnish and it works great but I dont know how to apply it. When I used a form with border, when you pressed exit it went to form1 anyways and when I make it with no border it doesn't show up in the task bar?????????
-
Aug 26th, 2006, 05:51 PM
#6
Re: If my file isn't there load other form???
 Originally Posted by LawnNinja
merrit, your code is very useful but not what i'm after, I tried your pnish and it works great but I dont know how to apply it. When I used a form with border, when you pressed exit it went to form1 anyways and when I make it with no border it doesn't show up in the task bar?????????
Put it in the sub main, before loading any other module.
-
Aug 26th, 2006, 05:52 PM
#7
Thread Starter
Hyperactive Member
Re: If my file isn't there load other form???
Ok,sorry figured it out....
was me
-
Aug 26th, 2006, 06:35 PM
#8
Re: If my file isn't there load other form???
Why I suggested my longer code is that it also allows you to check that the DLL file is a real loadable DLL file, not an empty, incorrect or corrupted file (it may feel like an overkill, but often too much error prevention is far better than not enough of it).
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
|