Solved

Create a DLL and call a dll procedure using RUNDLL32

Posted on 2001-07-02
6
372 Views
Last Modified: 2010-08-05
How can I create a DLL with a procedure that let me to call another program ( .EXE ) and check if the program ( .EXE ) was realy loaded. After the program was loaded, the DLL mat be free ?
Thank's a lot.
0
Comment
Question by:alinepb
  • 3
6 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 6247454
Something like this?

library testLib;

uses Windows, ShellAPI;

function Execute(file_, params: string) : boolean;
begin
  result := ShellExecute(0, nil, pchar(file_), pchar(params), nil, SW_SHOWNORMAL) > 32;
end;

exports Execute;

end.

Who is supposed to load that dll? It is the resposibility of that one to free the library again. The library can't free itself.

Regards, Madshi.
0
 

Author Comment

by:alinepb
ID: 6249443
Ok. But I want to call a procedure in a DLL using RUNDLL32 that call an application and wait until the application load was finished.
0
 
LVL 20

Accepted Solution

by:
Madshi earned 300 total points
ID: 6249639
I'm sorry, I'm not sure what you mean. Do you:

(a) write a dll, that can be called by rundll32?

Or do you

(b) want to call rundll32 from your dll?

In case you want to do (a), look here for documentation about how your dll must look like if you want it to be callable by rundll32:

http://support.microsoft.com/support/kb/articles/Q164/7/87.asp

In short, you have to export one (or more) function(s) from your dll which has to have this parameters:

procedure ExampleFunction(window, hinst: dword; cmdLine: pchar; show: integer); stdcall;

So your dll could look like this:

library testLib;

uses Windows, ShellAPI;

procedure Execute(window, hinst: dword; cmdLine: pchar; show: integer); stdcall;
var si : TStartupInfo;
    pi : TProcessInformation;
begin
  ZeroMemory(@si, sizeOf(si));
  if CreateProcess(nil, cmdLine, nil, nil, false, 0, nil, nil, si, pi) then begin
    WaitForInputIdle(pi.hProcess);
    CloseHandle(pi.hThread);
    CloseHandle(pi.hProcess);
  end;
end;

exports Execute;

end.

This dll should be callable from rundll32 like this:

rundll32 c:\path\testLib,Execute c:\windows\calc.exe

As a result your testLib will execute calc, wait until it has finished loading (for the most part at least) and then return.

Regards, Madshi.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6249645
P.S: If you need more info please try to express it clear & detailed enough, so that I understand what you need. Thank you...  :-)
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 8701610
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept Madshi's comment as answer

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Thank you,
Russell

EE Cleanup Volunteer
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

808 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