Solved

Writing Inside a dll

Posted on 1998-12-14
13
213 Views
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.
0
Comment
Question by:jss99
  • 5
  • 3
  • 2
  • +2
13 Comments
 
LVL 4

Expert Comment

by:chabaud
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...
0
 
LVL 3

Expert Comment

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

0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1450161
In NT you have the following functions.

Resource Functions
The following functions are used with resources.
 
BeginUpdateResource  
CopyImage  
EndUpdateResource  
EnumResLangProc  
EnumResNameProc  
EnumResourceLanguages  
EnumResourceNames  
EnumResourceTypes  
EnumResTypeProc  
FindResource  
FindResourceEx  
LoadImage  
LoadResource  
LockResource  
SizeofResource  
UpdateResource  

0
 

Expert Comment

by:RUSH
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:
http://www.experts-exchange.com/topics/comp/lang/visualbasic/Q.10093744
as I have been able to make it work in this instance.

0
 

Author Comment

by:jss99
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)

thanx
0
 
LVL 4

Expert Comment

by:chabaud
ID: 1450164
With vb you can work on "any file" (ie binary files or text files) with this statements:
  Open
  Close
  Print
  Input
  Get
  Put
Look into vb help for more detail or explain your real problem.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 13

Expert Comment

by:Mirkwood
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?
0
 

Expert Comment

by:RUSH
ID: 1450166
0
 
LVL 13

Expert Comment

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

Expert Comment

by:RUSH
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

     Rush





0
 

Author Comment

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

Expert Comment

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

Accepted Solution

by:
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.


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now