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