20
20
* This should create the dynamic link library "shell.dll" which you can call
21
21
* from Vim using for example :call libcall('c:/shell.dll', 'fullscreen', 'enable').
22
22
*
23
- * Happy vimming !
23
+ * Happy Vimming !
24
24
*
25
25
* - Peter Odding <peter@peterodding.com>
26
26
*/
33
33
#include <stdio.h>
34
34
#include <shellapi.h> /* ShellExecute? */
35
35
36
- /* Dynamic strings are returned using a static buffer to avoid memory leaks */
37
- static char buffer [1024 * 10 ];
36
+ /* Dynamic strings are returned using static buffers to avoid memory leaks. */
37
+ static char message_buffer [1024 * 10 ];
38
+ static char rv_buffer [512 ];
38
39
39
40
#undef MessageBox
40
41
#define MessageBox (message ) MessageBoxA(NULL, message, "Vim Library", 0)
@@ -44,13 +45,13 @@ static const char *GetError(void) /* {{{1 */
44
45
size_t i ;
45
46
46
47
FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS ,
47
- NULL , GetLastError (), 0 , buffer , sizeof buffer , NULL );
48
- i = strlen (buffer );
49
- while (i >= 2 && isspace (buffer [i - 2 ])) {
50
- buffer [i - 2 ] = '\0' ;
48
+ NULL , GetLastError (), 0 , message_buffer , sizeof message_buffer , NULL );
49
+ i = strlen (message_buffer );
50
+ while (i >= 2 && isspace (message_buffer [i - 2 ])) {
51
+ message_buffer [i - 2 ] = '\0' ;
51
52
i -- ;
52
53
}
53
- return buffer ;
54
+ return message_buffer ;
54
55
}
55
56
56
57
static const char * Success (const char * result ) /* {{{1 */
@@ -76,14 +77,13 @@ static const char *execute(char *command, int wait) /* {{{1 */
76
77
if (!wait ) {
77
78
return Success (NULL );
78
79
} else {
79
- char rv [500 ];
80
80
DWORD exit_code ;
81
81
if (WaitForSingleObject (pi .hProcess , INFINITE ) != WAIT_FAILED
82
82
&& GetExitCodeProcess (pi .hProcess , & exit_code )
83
83
&& CloseHandle (pi .hProcess )
84
84
&& CloseHandle (pi .hThread )
85
- && sprintf (rv , "exit_code=%u" , exit_code )) {
86
- return Success (rv );
85
+ && sprintf (rv_buffer , "exit_code=%u" , exit_code )) {
86
+ return Success (rv_buffer );
87
87
}
88
88
}
89
89
}
0 commit comments