3 static char * makePluginExeName( const char * name )
\r
5 char buf[ MAX_PATH ];
\r
9 strcat( buf, "plugins\\" );
\r
10 strcat( buf, name );
\r
11 strcat( buf, ".exe" );
\r
13 return strdup( buf );
\r
16 WbPlugin * wbpCreate( const char * name )
\r
21 // Create the plugin
\r
22 WbPlugin * plugin = (WbPlugin *) malloc( sizeof(WbPlugin) );
\r
24 memset( plugin, 0, sizeof(WbPlugin) );
\r
26 plugin->name_ = strdup( name );
\r
27 plugin->exe_name_ = makePluginExeName( name );
\r
28 plugin->hPipe_ = INVALID_HANDLE_VALUE;
\r
29 plugin->hProcess_ = INVALID_HANDLE_VALUE;
\r
31 // Create the named pipe for plugin communication
\r
33 strcpy( buf, "\\\\.\\pipe\\" );
\r
34 strcat( buf, name );
\r
36 plugin->hPipe_ = CreateNamedPipe( buf,
\r
42 1000, // Default timeout
\r
45 if( plugin->hPipe_ == INVALID_HANDLE_VALUE ) {
\r
46 DWORD err = GetLastError();
\r
51 // Create the plugin process
\r
54 PROCESS_INFORMATION pi;
\r
56 ZeroMemory( &si, sizeof(si) );
\r
57 ZeroMemory( &pi, sizeof(pi) );
\r
61 strcpy( buf, "\"" );
\r
62 strcat( buf, plugin->exe_name_ );
\r
63 strcat( buf, "\"" );
\r
65 strcpy( buf, "\"C:\\Program Files\\Borland\\Delphi5\\Projects\\History\\History.exe\"" );
\r
67 if( CreateProcess( NULL,
\r
71 FALSE, // Inherit handles
\r
72 0, // Creation flags
\r
73 NULL, // Environment
\r
74 NULL, // Current directory
\r
78 CloseHandle( pi.hThread );
\r
79 plugin->hProcess_ = pi.hProcess;
\r
86 // Destroy the plugin instance if something went wrong
\r
88 wbpDelete( plugin );
\r
95 void wbpDelete( WbPlugin * plugin )
\r
98 if( plugin->hPipe_ != INVALID_HANDLE_VALUE ) {
\r
99 CloseHandle( plugin->hPipe_ );
\r
102 if( plugin->hProcess_ != INVALID_HANDLE_VALUE ) {
\r
103 CloseHandle( plugin->hProcess_ );
\r
106 free( plugin->name_ );
\r
108 free( plugin->exe_name_ );
\r
111 plugin->exe_name_ = 0;
\r
112 plugin->hPipe_ = INVALID_HANDLE_VALUE;
\r
113 plugin->hProcess_ = INVALID_HANDLE_VALUE;
\r
119 int wbpSendMessage( WbPlugin * plugin, const char * msg, size_t msg_len )
\r
123 if( plugin != 0 && plugin->hPipe_ != INVALID_HANDLE_VALUE ) {
\r
127 while( ok && (msg_len > 0) ) {
\r
130 ok = WriteFile( plugin->hPipe_,
\r
137 if( cb > msg_len ) break; // Should *never* happen!
\r
145 if( zf >= 3 ) ok = FALSE;
\r
160 int wbpListInit( WbPluginList * list )
\r
162 list->item_count_ = 0;
\r
167 int wbpListAdd( WbPluginList * list, WbPlugin * plugin )
\r
171 if( plugin != 0 ) {
\r
172 if( list->item_count_ < MaxWbPlugins ) {
\r
173 list->item_[ list->item_count_ ] = plugin;
\r
174 list->item_count_++;
\r
183 WbPlugin * wbpListGet( WbPluginList * list, int index )
\r
185 WbPlugin * result = 0;
\r
187 if( index >= 0 && index < list->item_count_ ) {
\r
188 result = list->item_[ index ];
\r
194 int wbpListGetCount( WbPluginList * list )
\r
196 return list->item_count_;
\r
199 int wbpListDeleteAll( WbPluginList * list )
\r
203 for( i=0; i<list->item_count_; i++ ) {
\r
204 wbpDelete( list->item_[i] );
\r
207 return wbpListInit( list );
\r
210 int wbpListBroadcastMessage( WbPluginList * list, const char * msg, size_t msg_len )
\r
215 for( i=0; i<list->item_count_; i++ ) {
\r
216 if( wbpSendMessage( list->item_[i], msg, msg_len ) == 0 ) {
\r
220 // Error sending message to plugin...
\r