Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Create a DLL and call a dll procedure using RUNDLL32

Posted on 2001-07-02
6
Medium Priority
?
509 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 1200 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

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!

Question has a verified solution.

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

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 video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

916 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