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
24 * rundll32 dllname,entrypoint [arguments]
26 * Documentation for this utility found on KB Q164787
31 * FIXME - currently receives command-line parameters in ASCII only and later
32 * converts to Unicode. Ideally the function should have wWinMain entry point
33 * and then work in Unicode only, but it seems Wine does not have necessary
38 #include "wine/port.h"
44 typedef void (*EntryPointW
) (HWND hWnd
, HINSTANCE hInst
, LPWSTR lpszCmdLine
, int nCmdShow
);
45 typedef void (*EntryPointA
) (HWND hWnd
, HINSTANCE hInst
, LPSTR lpszCmdLine
, int nCmdShow
);
51 * strDll - name of the dll.
52 * procName - name of the procedure to load from dll
53 * pDllHanlde - output variable receives handle of the loaded dll.
55 static FARPROC
LoadProc(char* strDll
, char* procName
, HMODULE
* DllHandle
)
59 *DllHandle
= LoadLibrary(strDll
);
64 proc
= GetProcAddress(*DllHandle
, procName
);
67 FreeLibrary(*DllHandle
);
73 int main(int argc
, char* argv
[])
75 char szDllName
[MAX_PATH
],szEntryPoint
[64],szCmdLine
[2048];
77 EntryPointW pfEntryPointW
;
78 EntryPointA pfEntryPointA
;
79 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
);