Writing Inside a dll

Can i change data stored in .dll file through any program at run time. I want make the change permanent.
Who is Participating?

Improve company productivity with a Business Account.Sign Up

MirkwoodConnect With a Mentor Commented:
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.

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...
No. You cannot write into a running DLL.
You need the source of the DLL and Recompile it.

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

In NT you have the following functions.

Resource Functions
The following functions are used with resources.

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.

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

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.
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?
Well Russ, copy the important information to this thread so we don't have to buy it.
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


jss99Author Commented:
hi mirk..
can u send some implemented code for these functions...
No, I'm sorry. I don't have VB code to demonstrate.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.