Writing Inside a dll

Posted on 1998-12-14
Last Modified: 2010-05-03
Can i change data stored in .dll file through any program at run time. I want make the change permanent.
Question by:jss99
  • 5
  • 3
  • 2
  • +2

Expert Comment

ID: 1450159
Give more details.
What kind of data would you change into the dll ?

If it is resource data (icon, string, ...), there sould be a solution through API calls.

Else it is more difficult...

Expert Comment

ID: 1450160
No. You cannot write into a running DLL.
You need the source of the DLL and Recompile it.

LVL 13

Expert Comment

ID: 1450161
In NT you have the following functions.

Resource Functions
The following functions are used with resources.

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.


Expert Comment

ID: 1450162
I know you can do it in vb 3.0 before you make any calls to the dll(depending on the circumstances)please see:
as I have been able to make it work in this instance.


Author Comment

ID: 1450163
What i want is a inputbox in which i will enter some value and it should be written inside there any method to make such dll or any file (i do not want .mdb file)


Expert Comment

ID: 1450164
With vb you can work on "any file" (ie binary files or text files) with this statements:
Look into vb help for more detail or explain your real problem.
LVL 13

Expert Comment

ID: 1450165
Nope, you cannot do it in an easy way on both NT or 95.
See my other comment as well.

BTW: Did you ever wonder why you need this functionality and nobody else does?

Expert Comment

ID: 1450166
LVL 13

Expert Comment

ID: 1450167
Well Russ, copy the important information to this thread so we don't have to buy it.

Expert Comment

ID: 1450168
This is the final code from Q.10093744. In the original exchange I tried several different variations with different effects. This code modifies a baudrate divisor table inside a 3rd party communications .dll.
     Here is the final code:

     Sub menu_user_Click ()
     Dim x As Integer
     x = InputBox("Enter User Value")   'get user input
     Open "mydll.dll" For Binary As #10 'open the dll
     Put #10, 7540, x                   'write user data to location  
     Close #10                          'close the dll
     End Sub

     Operator issues:

     This is a sample app I made just to get the mechanics of the editing worked out. The
     "real" program has a function that allows the user to select a "target" baud rate and the
     application calculates the nearest valid divisor, so this keeps the operator from trying to
     input an oddball value.

     I am glad to have learned this.

     Thanks for your help Mark



Author Comment

ID: 1450169
hi mirk..
can u send some implemented code for these functions...
LVL 13

Expert Comment

ID: 1450170
No, I'm sorry. I don't have VB code to demonstrate.
LVL 13

Accepted Solution

Mirkwood earned 90 total points
ID: 1450171
Buy the book "hardcode VB".

Here is a sample:
Resource callbacks
Most of the real work of finding resources is done by UpdateResources. It looks like this:

Private Sub UpdateResources(ByVal hMod As Long)    ‘ Turn on hourglass, turn off redrawing    HourGlass Me    Call LockWindowUpdate(lstResource.hWnd)    lstResource.Clear        Call EnumResourceTypes(hMod, AddressOf ResTypeProc, Me)        Call LockWindowUpdate(hNull)    HourGlass MeEnd Sub
The EnumResourceTypes API function sets up a callback function named ResTypeProc. As described in “Limits of Procedure Pointers,” page 99, the callback procedure must reside in a BAS module, although it would be a lot handier to put it in WINWATCH.FRM with the UpdateResources procedure. The callback procedure will need access to the form so that it can fill the Resources list box and inspect the Filter Resources check box. How can we make these controls available to the standard module containing the callback? Well, we could always use global variables, but there is a better way. Like most callback functions, EnumResourceTypes has an extra parameter for user-defined data. We can use that parameter to pass the whole form. Here’s how it works:

Function ResTypeProc(ByVal hModule As Long, ByVal lpszType As Long, _                     frm As Form) As Long    ResTypeProc = True      ‘ Always return True    If lpszType <= 65535 Then        ‘ Enumerate resources by ID        Call EnumResourceNamesID(hModule, lpszType, _                                 AddressOf ResNameProc, frm)    Else        ‘ Enumerate resources by string name        Call EnumResourceNamesStr(hModule, PointerToString(lpszType), _                                  AddressOf ResNameProc, frm)    End IfEnd Function
First look at that ByRef Form parameter. Windows expects that parameter to be a ByVal Long, but Long is the size of a pointer, so we can pass anything we want here as long as we pass it by reference. We couldn’t be so fast and loose with types if ResTypeProc were going to be called by Visual Basic, but it’s not. Windows is the only caller and as long as it gets 32 bits, it doesn’t care what they point to. Notice that the only thing the procedure does with the frm parameter is pass it on to EnumResourceNames (which sets up ResNameProc as a callback).

An unusual thing about ResTypeProc is how it handles the string pointer lpszType. Actually, this isn’t all that unusual. Windows often overloads string pointers to represent integers in some situations. For reasons that need not concern us, pointers always have a non-zero high word. That means that Windows can use a high word of zero to signal that a pointer isn’t really a pointer. With resources, Windows uses the low word for standard resource types. There are constants with values of less than 65,536 for common resource types such as icons, bitmaps, and cursors. Unusual and user-defined types have string names. When you’re enumerating resource types, you don’t know whether you’re going to get a real string pointer or one of these constants. The Windows API type library provides EnumResourceNamesID and EnumResourceNamesStr as aliases for the EnumResourceNames API function so you can enumerate the resource names for constants or strings. Here’s the callback function:

Function ResNameProc(ByVal hModule As Long, ByVal lpszType As Long, _                     ByVal lpszName As Long, frm As Form) As Long    Dim sType As String, sName As String    ResNameProc = True      ‘ Always return True    If lpszName <= 65535 Then        sName = Format$(lpszName, “00000”)    Else        sName = PointerToString(lpszName)    End If    If lpszType <= 65535 Then        sType = ResourceIdToStr(lpszType)    Else        sType = PointerToString(lpszType)    End If    If frm.chkFilter = vbChecked Then        If Not ValidateResource(hModule, sName, sType) Then Exit Function    End If    frm.lstResource.AddItem sName & “   “ & sTypeEnd Function
Once again, you have to check the values of lpszType and lpszName to see if they are strings or integers. Windows uses integers to represent standard resources such as the stop sign icon or the arrow cursor. In this case, if we get an integer ID for the resource name, we format it as a zero-aligned string so that it will line up correctly in the list box. If we get an integer ID for the type, we look up the type name with the ResourceIdToStr function, which is just a Select Case block that returns string names for the standard type names.


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question