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????? :D
Printable View
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????? :D
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
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.
Hey Merri, that could be very useful code... well done :thumb:
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.Quote:
Originally Posted by LawnNinja
Ok,sorry figured it out....
was me ;)
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).