Fixed compilation problems.
[wine/multimedia.git] / programs / rundll32 / rundll32.c
blob338085c52d07b518666ea2ed541d699fb4cf871a
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
24 * rundll32 dllname,entrypoint [arguments]
26 * Documentation for this utility found on KB Q164787
30 /**
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
34 * support.
37 #include "config.h"
38 #include "wine/port.h"
40 #include <stdio.h>
41 #include <string.h>
42 #include <windows.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);
47 /**
48 * Loads procedure.
50 * Parameters:
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)
57 FARPROC proc;
59 *DllHandle = LoadLibrary(strDll);
60 if(!*DllHandle)
62 exit(-1);
64 proc = GetProcAddress(*DllHandle, procName);
65 if(!proc)
67 FreeLibrary(*DllHandle);
68 return NULL;
70 return proc;
73 int main(int argc, char* argv[])
75 char szDllName[MAX_PATH],szEntryPoint[64],szCmdLine[2048];
76 char* comma;
77 EntryPointW pfEntryPointW;
78 EntryPointA pfEntryPointA;
79 HMODULE DllHandle=NULL;
81 if(argc<2)
82 return 0;
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;