Warning fixes.
[wine/multimedia.git] / programs / rundll32 / rundll32.c
blob16f56e5fd12a5ac76b36424c16c5e251e61fcff3
1 /*
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
21 * windows version.
26 * rundll32 dllname,entrypoint [arguments]
28 * Documentation for this utility found on KB Q164787
32 /**
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
36 * support.
39 #include "config.h"
40 #include "wine/port.h"
42 #include <stdio.h>
43 #include <string.h>
44 #include <windows.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);
49 /**
50 * Loads procedure.
52 * Parameters:
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)
59 FARPROC proc;
61 *DllHandle = LoadLibrary(strDll);
62 if(!*DllHandle)
64 exit(-1);
66 proc = GetProcAddress(*DllHandle, procName);
67 if(!proc)
69 FreeLibrary(*DllHandle);
70 return NULL;
72 return proc;
75 int main(int argc, char* argv[])
77 char szDllName[MAX_PATH],szEntryPoint[64],szCmdLine[2048];
78 char* comma;
79 EntryPointW pfEntryPointW;
80 EntryPointA pfEntryPointA;
81 HMODULE DllHandle=NULL;
83 comma=strchr(argv[1],',');
84 if(comma==NULL)
85 return 0;
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);
91 if(argc>2)
93 int i;
94 for(i=2;i<argc;i++)
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);
111 else
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)
121 return 0;
123 pfEntryPointA(NULL,DllHandle,szCmdLine,SW_HIDE);
125 if(DllHandle)
126 FreeLibrary(DllHandle);
127 return 0;