Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2005

Tip: Looking for answers? Try searching our database.

I need to call CoInitializeEx(IntPtr pvReserved, uint dwCoInit);  pvReservered = null, so what is the value of COINIT_APARTMENTTHREADED?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Uchiha Jax - 16 Sep 2005 13:52 GMT
I've been recently getting around a lot of issues with the
DirectX.AudioVideoPlayback.Audio class.
It's a difficult class to work with, bad enough to make someone write this
article:

www.codeproject.com/cs/media/DirectX9_media_playback.asp

I however don't want to use Media Player as the author of this article
recommends, so i'm plugging away at sorting out the last of the remaining
problems.

One of the last issues remaining is an odd one, very occasionally I get an
"Error in Application" exception when opening a file.
After checking out the DirectX exception I got the error string:
CO_E_NOTINITIALIZED

After checking this on Google it seems that a call to CoInitializeEx is
required to resolve this issue and i'm assuming I have this issue as I open
the object on a new thread (yet another work around to make the events work
properly). I've done a simple P/Invoke before so I have the necessary code
for the method import, the only thing I don't know is the value of
COINIT_APARTMENTTHREADED  or  COINIT_MULTITHREADED.
How do I find out what these values are?

So I can do this:

const uint COINIT_APARTMENTTHREADED  = ??;
const uint COINIT_MULTITHREADED = ??;

CoInitialize(null, COINIT_APARTMENTTHREADED);
-
OR
-
CoInitialize(null, COINIT_MULTITHREADED);

Also, is this a good idea and might it resolve my problem or open up a can
of worms? (as I have limited data about what this method does exactly)
Your thoughts please.

The code that i'm having problems with is:

private void InitAudio() /// this gets called the FIRST time a file is
played only
{
  ThreadStart ts = new ThreadStart(AudioThreadStart);
  audioThread = new Thread(ts);
  audioThread.Name = "CynoPlayerAudio.InitAudio() Thread";
  audioThread.Priority = ThreadPriority.Highest;
  audioThread.Start();
}

 private void AudioThreadStart()
 {
  try
  {
   audio = new Audio(threadArgument, false); /// this is where I sometimes
get "Error in Application" = CO_E_NOTINITIALIZED
  }
  catch(Exception ex)
  {
   Console.WriteLine(ex.Message);
   MessageBox.Show(ex.Message);
  }

  audio.Ending+=new EventHandler(audio_Ending);
  audio.Pausing+=new EventHandler(audio_Pausing);
  audio.Starting+=new EventHandler(audio_Starting);
  audio.Stopping+=new EventHandler(audio_Stopping);

  if(autoRun)
  {
   audio.Play();
  }

  Application.Run(); /// this line is required to make the events for the
audio object to work as it relies (undocumented of course) on the windows
message system
 }

Please help if you can. :)

Kind Regards

Jax
Robert Jordan - 16 Sep 2005 14:07 GMT
Hi,

> private void InitAudio() /// this gets called the FIRST time a file is
> played only
[quoted text clipped - 3 lines]
>    audioThread.Name = "CynoPlayerAudio.InitAudio() Thread";
>    audioThread.Priority = ThreadPriority.Highest;

You forgot to initialize the STA:

     audioThread.ApartmentState = ApartmentState.STA;

>    audioThread.Start();
> }

Rob
Uchiha Jax - 16 Sep 2005 15:00 GMT
Problem solved. Many thanks.

Jax

> Hi,
>
[quoted text clipped - 14 lines]
>
> Rob

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.