Solved

Create a DLL and call a dll procedure using RUNDLL32

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

820 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