Solved

How to delete a shared windows DLL

Posted on 1998-10-04
9
181 Views
Last Modified: 2010-04-06
I want to replace an older DLL ( comctl32.dll ) with a new version with my own setup program. When I try to replace this file an error occured : Sharing violation. Is there any solution to erase shared DLL or even make it non-shared ?

Motaz from Sudan.
motaz1@yahoo.com
0
Comment
Question by:Motaz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 20

Accepted Solution

by:
Madshi earned 20 total points
ID: 1341670
I think this DLL is in use by another (or by some other) process(es). So you just can't delete or replace this file on the fly. You cannot change the share mode, either. What you can do is what every setup program does: Restart Windows and make Windows replace this DLL right after the restart.

Win95:
Create/Edit the file "c:\windows\wininit.ini". Add this:
   [Rename]
   c:\windows\comctl32.dll=c:\windows\comctl32.$$$

WinNT:
MoveFileEx('c:\windows\comctl32.dll','c:\windows\commctl32.$$$',MOVEFILE_DELAY_UNTIL_REBOOT or MOVEFILE_REPLACE_EXISTING);

Win95/WinNT:
Now copy the new DLL version to "c:\windows\comctl32.$$$" and restart Windows (using ExitWindowsEx).

Regards, Madshi.
0
 
LVL 5

Expert Comment

by:inter
ID: 1341671
You are faster man ;-) here is my contribution

Yes you can,
however you should restart the windows in order your DLL be copied succesfully. Because every body uses comctl32(even windows shell) it is not advisable to kill those processes and copy comctl32. So it can be done with the following API but different for Win95 and NT

FOR NT:
-------------

 MoveFileEx('c:\temp\myinstall\comctl32.dll','c:\winnt\system32\comctl32.dll',
    LPCTSTR lpNewFileName,      // address of new name for the file
    MOVEFILE_DELAY_UNTIL_REBOOT );

FOR 95+
---------------

procedure MoveFileEx95(src, dest : string);
var
  inif : array[0..255] of char;
  inif : array[0..255] of char;
begin
  GetWindowsDirectory(szWinInitFile, uSize);
  StrCat(inif, '\WININIT.INI');
  WritePrivateProfileString('Rename', 'NUL', PChar(dest), inif);
  WritePrivateProfileString('Rename', dest, src, inif);
end;
//do not forgetto reboot! You can do this with the following API call

ExitWindowsEx(EWX_REBOOT, 0);

regards, igor
0
 
LVL 7

Author Comment

by:Motaz
ID: 1341672
Thanks all of you. A very nice solution... but need some clearifications :

-[Rename] not exist in Win.ini.. Must I add it ?.. and what happend if it is already exist?
- Is it posible to append win.ini.. no error will occure if I try to do so ?..
- After that did the windows remove this lines from win.ini after finishing this task ?

Thanks for your help.
Motaz
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:inter
ID: 1341673
Yes, combine the info we supplied and windows automatically handles the rest.
0
 
LVL 7

Author Comment

by:Motaz
ID: 1341674
Inter, you don't mention the file name which I must replace ?
0
 
LVL 5

Expert Comment

by:inter
ID: 1341675
You are right,
for WinNT do exactly what Madshi wrote, for Win95 call my proc

MoveFileEx95('source file name','dest file name'); and reboot.

I strongly recomend you to test those on a dummy file. For example create a file called x.dat on c:\ and replace it with the above method. Once succesful you try the actual replacement. In addition if in MoveFileEx95 proc NUL does not work try NULL instead.
regards, igor
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1341676
Hi Igor. I thought you wanted to call me "madshi" instead of "Madshi"!?  :-)

Motaz, ATTENTION!!!!!! It is NOT "Win.ini", but "WinInit.ini"!!!
The file "WinInit.ini" is handled from Windows at startup and then renamed to "WinInit.bak".

BTW, I think you don't need to delete the old file before replacing it. At least I don't do this in my programs...
Also you don't need to give in the windows path to WritePrivateProfileString. So I think you can shorten igor's nice procedure like the following:

procedure MoveFileEx95(src, dest: string);
begin
  WritePrivateProfileString('Rename', pchar(dest), pchar(src), 'WinInit.Ini');
end;

Regards, Madshi.
0
 
LVL 7

Author Comment

by:Motaz
ID: 1341677
Thanks Igor and Madshi... it did work.

Motaz
0
 
LVL 7

Author Comment

by:Motaz
ID: 1341678
Sorry I mean Inter and Madshi
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

695 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