Solved

Create a DLL and call a dll procedure using RUNDLL32

Posted on 2001-07-02
6
358 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

10 Experts available now in Live!

Get 1:1 Help Now