2 * PURPOSE: Load a DLL and run an entry point with the specified parameters
4 * Copyright 2002 Alberto Massari
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * This version deliberately differs in error handling compared to the
26 * rundll32 dllname,entrypoint [arguments]
28 * Documentation for this utility found on KB Q164787
33 * FIXME - currently receives command-line parameters in ASCII only and later
34 * converts to Unicode. Ideally the function should have wWinMain entry point
35 * and then work in Unicode only, but it seems Wine does not have necessary
40 #include "wine/port.h"
46 typedef void (*EntryPointW
) (HWND hWnd
, HINSTANCE hInst
, LPWSTR lpszCmdLine
, int nCmdShow
);
47 typedef void (*EntryPointA
) (HWND hWnd
, HINSTANCE hInst
, LPSTR lpszCmdLine
, int nCmdShow
);
53 * strDll - name of the dll.
54 * procName - name of the procedure to load from dll
55 * pDllHanlde - output variable receives handle of the loaded dll.
57 static FARPROC
LoadProc(char* strDll
, char* procName
, HMODULE
* DllHandle
)
61 *DllHandle
= LoadLibrary(strDll
);
66 proc
= GetProcAddress(*DllHandle
, procName
);
69 FreeLibrary(*DllHandle
);
75 int main(int argc
, char* argv
[])
77 char szDllName
[MAX_PATH
],szEntryPoint
[64],szCmdLine
[2048];
79 EntryPointW pfEntryPointW
;
80 EntryPointA pfEntryPointA
;
81 HMODULE DllHandle
=NULL
;
83 comma
=strchr(argv
[1],',');
86 /* Extract the name of the DLL */
87 memset(szDllName
,0,MAX_PATH
);
88 strncpy(szDllName
,argv
[1],(comma
-argv
[1]));
89 /* Merge the other paramters into one big command line */
90 memset(szCmdLine
,0,2048);
96 strcat(szCmdLine
,argv
[i
]);
97 if(i
+1<argc
) strcat(szCmdLine
," ");
101 /* try loading the UNICODE version first */
102 strcpy(szEntryPoint
,comma
+1);
103 strcat(szEntryPoint
,"W");
104 pfEntryPointW
=(EntryPointW
)LoadProc(szDllName
, szEntryPoint
, &DllHandle
);
105 if(pfEntryPointW
!=NULL
)
107 WCHAR wszCmdLine
[2048];
108 MultiByteToWideChar(CP_ACP
,0,szCmdLine
,-1,wszCmdLine
,2048);
109 pfEntryPointW(NULL
,DllHandle
,wszCmdLine
,SW_HIDE
);
113 strcpy(szEntryPoint
,comma
+1);
114 strcat(szEntryPoint
,"A");
115 pfEntryPointA
=(EntryPointA
)LoadProc(szDllName
, szEntryPoint
, &DllHandle
);
116 if(pfEntryPointA
==NULL
)
118 strcpy(szEntryPoint
,comma
+1);
119 pfEntryPointA
=(EntryPointA
)LoadProc(szDllName
, szEntryPoint
, &DllHandle
);
120 if(pfEntryPointA
==NULL
)
123 pfEntryPointA(NULL
,DllHandle
,szCmdLine
,SW_HIDE
);
126 FreeLibrary(DllHandle
);