Old 07-17-2010, 04:09 PM   #1
liteon
Human being with feelings
 
liteon's Avatar
 
Join Date: Apr 2008
Posts: 510
Default strange vst plugin process attach/detach

a question:

in reaper (also in energy xt for example) i have the following observation:

i load a vst plugin which allocates (attaches) a console to reaper and routes stdout to it.
then only for certain plugins (built with juce, synthmaker) i notice the following :
http://dl.dropbox.com/u/1627980/axon/axdebug3321121.gif
^ 400kb gif video

even if the plugin that allocated the console is offline, bringing the plugin in question online/offline is reported to the console...or is it actually the first plugin that is attached / detached while its offline (hope this makes sense) ?

and does any one know of any particular reason for this behavior ?

cheers



---
liteon is offline   Reply With Quote
Old 07-17-2010, 04:12 PM   #2
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 15,750
Default

Do the plugins share some common framework dll (and therefore maybe have a shared entry point)?
schwa is offline   Reply With Quote
Old 07-17-2010, 04:29 PM   #3
liteon
Human being with feelings
 
liteon's Avatar
 
Join Date: Apr 2008
Posts: 510
Default

the first plugin is using our framework, for the second ("test-against" plugin) looks like it happens with synthmaker, juce plugins. but yes different frameworks.

on our side the entry point is defined as:
Code:
__externc BOOL APIENTRY
DllMain(HINSTANCE hModule, DWORD reason, LPVOID lpReserved)
{
  trace("win32 DllMain");
  //g_Instance = hModule;
  switch(reason)
  {
    case DLL_PROCESS_ATTACH:
      trace("DllMain (reason: process attach)");
      gWinInstance = hModule;
      //printf("gWinInstance = %i\n",(int)gWinInstance);
      break;
    case DLL_PROCESS_DETACH:
      trace("DllMain (reason: process detach)");
      break;
    case DLL_THREAD_ATTACH:
      trace("DllMain (reason: thread attach)");
      break;
    case DLL_THREAD_DETACH:
      trace("DllMain (reason: thread detach)");
      break;
    default:
      trace("DllMain (reason: unknown)");
      break;
  }
  return TRUE;
}
DllMain is mostly needed here to get the HINSTANCE hModule and retrieve the real path of the module.


[edit]: aha its the 'extern "C"' definition of the entry point.
but this is needed for LADSPA plugins on WIN32. a solution i guess is to make it format (vst / ladpsa / etc) specific.

--

Last edited by liteon; 07-17-2010 at 04:41 PM.
liteon is offline   Reply With Quote
Old 07-17-2010, 04:32 PM   #4
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 15,750
Default

I might not be understanding the question, but the dll will be unloaded (by the Windows dll manager) only after FreeLibrary is called on the last instance that shares that entry point. Offlining the plugin is equivalent to deleting/freeing it (the only difference is that when offlining, Reaper will remember the plugin state/configuration).
schwa is offline   Reply With Quote
Old 07-17-2010, 04:47 PM   #5
liteon
Human being with feelings
 
liteon's Avatar
 
Join Date: Apr 2008
Posts: 510
Default

Quote:
Originally Posted by schwa View Post
I might not be understanding the question, but the dll will be unloaded (by the Windows dll manager) only after FreeLibrary is called on the last instance that shares that entry point. Offlining the plugin is equivalent to deleting/freeing it (the only difference is that when offlining, Reaper will remember the plugin state/configuration).
strange. it looks like if the entry point is declared without c++ naming schemes (extern "C"), different plugins will be recognized as instances of one another (or something in these lines), so perhaps thats why there is a thread attach / detach in the console.


--
liteon is offline   Reply With Quote
Old 07-18-2010, 12:26 AM   #6
cern.th.skei
Human being with feelings
 
cern.th.skei's Avatar
 
Join Date: Sep 2007
Location: trondheim, norway
Posts: 362
Default

DllMain, with reason: process attach/detach is called when the dll loads/unloads, isn't it? but when is it called with reason: thread attach/detach?
__________________
torhelgeskei.com
cern.th.skei is offline   Reply With Quote
Old 07-18-2010, 03:14 AM   #7
Mich
Human being with feelings
 
Join Date: May 2009
Posts: 1,265
Default

Quote:
Originally Posted by cern.th.skei View Post
DllMain, with reason: process attach/detach is called when the dll loads/unloads, isn't it? but when is it called with reason: thread attach/detach?
http://msdn.microsoft.com/en-us/libr...83(VS.85).aspx
Mich is offline   Reply With Quote
Old 07-18-2010, 12:28 PM   #8
liteon
Human being with feelings
 
liteon's Avatar
 
Join Date: Apr 2008
Posts: 510
Default

^
Quote:
The current process is creating a new thread. When this occurs, the system calls the entry-point function of all DLLs currently attached to the process
so obviously it should happen. the process (vst host) is calling the DllMain method of all plugins that are loaded. i guess this should be normal.

but what is the correct way to declare DllMain - with or without 'extern "C" '
?

[edit:] delete silly notes. apparently DllMain has to be declared as 'extern "C" ' after all at least for VST's from my tests.

--

Last edited by liteon; 07-18-2010 at 01:46 PM.
liteon is offline   Reply With Quote
Old 07-18-2010, 02:27 PM   #9
Mich
Human being with feelings
 
Join Date: May 2009
Posts: 1,265
Default

Quote:
Originally Posted by liteon View Post
but what is the correct way to declare DllMain - with or without 'extern "C" '
With. Altough MSVC++ might accept it without since you often see it without, but I think with is correct.
Mich is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 12:39 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.