Solved

Create a DLL and call a dll procedure using RUNDLL32

Posted on 2001-07-02
6
363 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

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

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

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

20 Experts available now in Live!

Get 1:1 Help Now