We help IT Professionals succeed at work.

What am I allowed to do in "DllMain"?

AMZita
AMZita asked
on
Medium Priority
583 Views
Last Modified: 2012-06-27
Can anyone enlighten me about this code? Im trying to make a DLL who initializes some stuff in the DLLMain attaching process. I could of course just move the initializing code to start() or to a new function initialize() or something but I figured that the meaning of DllMain was just for cases like this? Or am I wrong? ... please Im goooing nuuuuts!

#include "stuff.h"

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{                          
      switch(fdwReason)
      {
      case DLL_PROCESS_ATTACH:
// ----- When moving this code segment to "start()", everything works good.. whats the difference?
            Randomize();
            SetSpeaker( 0, 90 );
            SetSpeaker( 1, 270 );
            audio = new RtAudio(&stream, 0, (int)CHANNELS, 0, 0, RtAudio::RTAUDIO_FLOAT64, SAMPLE_RATE, &buffersize, 4);
            audio->setStreamCallback(stream, &RainSynth, NULL);
// ------
            break;

      case DLL_PROCESS_DETACH:
            audio->closeStream(stream);
            break;
      }

      return TRUE;
}

extern "C" __declspec(dllexport) void Start()
{
// ----- When moving the above code segment to this place instead, everything works good.. why?
      audio->startStream(stream);
}

extern "C" __declspec(dllexport) void Stop()
{
      audio->stopStream(stream);
}
Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Sorry for beeing so lame but what is non-reentrant code/process wide?

What would you recommend me to do? (except learning more c++)

When does a new thread initialize?, as far as I new Im only using one DLL-thread so why sould anything block anything at all? Hmmm ... I _am_ going nuts ... Is the best/only way of doing this to implement a Create() and Clear() function to create/clear my "audio" object?

Is a new thread initialized every time I set something like this? ... :

[DllImport("mydll.dll")]
private static extern void SomeFunction();

... or when Im calling SomeFunction() ?
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.