C api problem with add-in shutdown/detach code

in the code below during the dll_process_attach part i can log text to the server console without a problem, on the other hand if i do the same thing during the dll_process_detach the server will crash.

does anyone know of a way to log to the console during the shutdown/detach process without crashing the server?

i’m using the AddInLogMessageText() function to log text to the console.

also, does any one know a way to get the task name that the add-in has attached to? i’d like to replace the in the message with the actual task name?

thanks

raymond

BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved )

{

int x;

STATUS error = NOERROR;

switch( dwReason )

{

case DLL_PROCESS_ATTACH:

  InitializeCriticalSection( &gCriticalSection );

  gHandlerProc = ( EMHANDLER ) MakeProcInstance( ( FARPROC ) EMHandlerProc, hInstance );

  sprintf( gTextBuffer, "%s: Version %s Attached to <taskname> Task and Started\n", ProgramName, ProgramVersion );

  ConsoleLog( gTextBuffer );

  break;



case DLL_PROCESS_DETACH:

  CleanUp();

  FreeProcInstance( gHandlerProc ); 

  for ( x = 0; ExtensionHookTable[x].m_Name != NULL; x += 1 )

  {

    error = DeregisterEntry( x );

    if ( error )

      break;

  }

  DeleteCriticalSection( &gCriticalSection );

  printf( "%s: Version %s Detached from <taskname> Task and Ended\n", ProgramName, ProgramVersion );

  break;

}

return( TRUE );

UNREFERENCED_PARAMETER( lpReserved );

}

Subject: c api problem with add-in shutdown/detach code

Try the following changes to your code:

 CleanUp();

 for ( x = 0; ExtensionHookTable[x].m_Name != NULL; x += 1 )

 {

   error = DeregisterEntry( x );

   if ( error )

     break;

 }

 printf( "%s: Version %s Detached from <taskname> Task and Ended\n", ProgramName, ProgramVersion );

 FreeProcInstance( gHandlerProc ); 

 DeleteCriticalSection( &gCriticalSection );

Subject: RE: c api problem with add-in shutdown/detach code

sorry i should have been more specific, if i code it as below it will ALWAYS crash the server trying to print to the console

the printf() statement will work, so will the sprintf(), but logging the output ( gTextBuffer ) to the server console will not.

case DLL_PROCESS_DETACH:

  

  // printf( "%s: Version %s Detached from <taskname> Task and Ended\n", ProgramName, ProgramVersion );

  sprintf( gTextBuffer, "%s: Version %s Detached from <taskname> Task and Ended\n", ProgramName, ProgramVersion );

  ConsoleLog( gTextBuffer );



  CleanUp();

  

  for ( x = 0; ExtensionHookTable[x].m_Name != NULL; x += 1 )

  {

    error = DeregisterEntry( x );

    if ( error )

      break;

  }

  FreeProcInstance( gHandlerProc ); 

  DeleteCriticalSection( &gCriticalSection );

  

  break;

it generates this message when crashing

Thread=[0CB4:0002-0D2C]

Stack base=0x0012F58C, Stack size = 5700 bytes

PANIC: Invalid Signature - VPOOL structure corrupt