Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Writing Inside a dll

Posted on 1998-12-14
Medium Priority
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.

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


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 dll...is 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 180 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 3 hours left to enroll

572 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