dlls 
Author Message
 dlls

I have a dll name hardcoded in my declares. The problem is that the dll
name changes with an update every two months. Is there a way to load
this dll from a variable that I can load the changed name in ?
Otherwise I have to recompile every two months. I need to dynamically
load this dll without hardcoding the name in the declares.
Please help!!!

Sent via Deja.com
http://www.*-*-*.com/



Fri, 27 Jun 2003 23:05:36 GMT  
 dlls

Quote:
> I have a dll name hardcoded in my declares. The problem is that the dll
> name changes with an update every two months.

You have two options here. The first is tested, the second is something you
can try:
1) Do the LoadLibrary/GetProcAddress yourself. To call the function pointer
you get back, use the FunctionDelegator object described in the February
2000 VBPJ black-belt article, or in my book. There are others out there who
use similar techniques, but mine is the only one that works without external
Dlls or lots of extra (and often dynamically generated) asm overhead. (It's
hard to beat the performance and cost of 4 assembly instructions, which is
all the FunctionDelegator uses)
2) Define all of your the declares for the given Dll in a typelib to force
the functions into the import table of your executable. If the number of
characters in the dll name doesn't change, a simple edit of the import table
will bind you to the modified Dll (I'd also recommend updating the CheckSum,
see code below). Of course, you need to make this change before launching
the exe. The update is pretty easy by hand in a binary editor, but can also
be automated. The sources for the CheckImportCasing add-in in the source
code for the latest CD Updates for my book (http://www.PowerVB.com) contain
code to read the import table dll names. You could easily rip this down and
add writing capabilities as well, the key is finding the correct string in
the first place (the source is more than a snippet, so I'm not including it
here). Note that there aren't any secrets about the PE header format, you
can find out about it in MSDN if you don't want to start with mine.

-Matt

'Code for updating a CheckSum in a file. This assumes UNICODE API support,
'but is easily modified for ANSI only. If you edit the file by hand, you
should run this
'afterwards to bring the checksum back in line.
Private Declare Function MapFileAndCheckSumW Lib "ImageHlp.dll" (ByVal
FileName As Long, HeaderSum As Long, CheckSum As Long) As Long
Private Sub UpdateCheckSum(TargetFile As String)
Dim CheckSum As Long
Dim HeaderSum As Long
Dim fNum As Integer
Dim fFileOpen As Boolean
    'With the file closed, we can now map it and get
    'a new checksum. With the current state, a virus
    'scanner will think that this executable is infected
    'because the checksum doesn't match the header information.
    On Error GoTo Error
    MapFileAndCheckSumW StrPtr(TargetFile), HeaderSum, CheckSum
    If HeaderSum <> CheckSum Then
        fNum = FreeFile
        Open TargetFile For Binary Access Read Write As fNum
        fFileOpen = True
        'Read the PE header offset at &H3C (Get is 1-based, so add 1)
        Get #fNum, &H3D, HeaderSum
        Put #fNum, HeaderSum + 89, CheckSum
        fFileOpen = False
        Close #fNum
    End If
    Exit Sub
Error:
    If fFileOpen Then Close fNum
End Sub



Sat, 28 Jun 2003 03:32:55 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. DLL DLL DLL DLL DLL DLL

2. Problems building install file - AutPrx32.dll, AutMgr32.dll, RACMGR32.dll, CLIREG32.exe NOT FOUND

3. REQ: OLEPRO32.DLL, MFC40.DLL, MSVCRT40.DLL from VB4.0 Standard CD

4. MSVCRT.DLL, MSVCRT20.DLL and MSVCRT40.DLL

5. Anyone knows where I can find declarations for shell32.dll, kernel32.dll, comcat.dll and gdi32.dll?

6. Jet VBA File (VBAJet.dll VBAJet32.dll) Initialization failure

7. Vbajet32.dll & vbajet.dll

8. DLL MSLDBUSR.DLL

9. DLL MSLDBUSR.DLL

10. Check DLL-File (Exist DLL-File?)

11. Office2k: vbe6intl.dll / Sprach-dll

12. VB6 DLLs and Windows 2000 DLLs

 

 
Powered by phpBB® Forum Software