I am searching since weeks for a solution for my problem but i can t find anything. So I thought this is probably the biggest C#-Forum... I may ask here. The Question is quite difficult to explain so I just copy a link to stackoverflow where i asked before:
http://stackoverflow.com/questions/11382341/translate-c-code-com-interface-to-c-sharp
Again It would be sooooooo nice if someone could help me. I am really such anoyed by that interface but i really want to get i working :)
Loading

VulpesRank #55 · 29.2K reputationPosted Jul 8, 2012, 12:03 PM EDT
florian21 reputationPosted Jul 8, 2012, 12:25 PM EDT
EDIT: I can play now the primarybuffer but I still get an InvalidCastException when I try to call SetVolume because QueryInterface is not supported on the COM-Component. (E_NOINTERFACE)
VulpesRank #55 · 29.2K reputationPosted Jul 8, 2012, 3:25 PM EDT
florian21 reputationPosted Jul 10, 2012, 12:28 PM EDT
EDIT: OK no its not same result. I get HRESULT 0x8878001E at primaryBuffer.Play... What means that CTRL is not supported but i don t have to control volume and so on on primarybuffer... really confusing.
VulpesRank #55 · 29.2K reputationPosted Jul 10, 2012, 2:32 PM EDT
https://www.google.co.uk/search?sugexp=chrome,mod=5&sourceid=chrome&ie=UTF-8&q=HRESULT+0x8878001E
My guess is that it's not a problem with your translation of the COM interface but a problem with something else such as the sound-card.
florian21 reputationPosted Jul 12, 2012, 9:17 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jul 12, 2012, 2:51 PM EDT
florian21 reputationPosted Jul 13, 2012, 8:18 AM EDT
EDIT
OK I just tried it on another Computer. Same Result. With the IUnknown Interface it works best. sound plays on volume change --> crash.
VulpesRank #55 · 29.2K reputationPosted Jul 13, 2012, 8:59 AM EDT
http://msdn.microsoft.com/en-us/library/windows/desktop/ee416963(v=vs.85).aspx
There are just three new ones : IDirectSound8, IDirectSoundBuffer8, and IDirectSoundCaptureBuffer8 and the rest have just been renamed.
I don't think that the new ones inherit, as such, from the corresponding IDirectSound interfaces, though they do have some members in common.
IUnknown is still there, of course :)
florian21 reputationPosted Jul 13, 2012, 9:01 AM EDT
So I am searching and searching and searching. But I can find anything.
Another question: The Interface itself seems to be right. I mean all that marshalling stuff and so on...
florian21 reputationPosted Jul 14, 2012, 1:54 PM EDT
It works on MTAThread config but not on STAThread. Does anyone know why?
VulpesRank #55 · 29.2K reputationPosted Jul 14, 2012, 3:11 PM EDT
florian21 reputationPosted Jul 15, 2012, 1:45 AM EDT
It doesn t seems like to be very common problem because nobody really knows a solution for this problem :(
VulpesRank #55 · 29.2K reputationPosted Jul 15, 2012, 5:15 AM EDT
If the apartment state is reported as 'Unknown', then that's effectively MTA.
Although you can change the apartment state of an existing thread in certain circumstances, that's probably not a good idea as you don't know what else the user may be doing on that thread.
florian21 reputationPosted Jul 15, 2012, 5:24 AM EDT
But creating a new thread every time I call SetVolume is not that good solution because for example if the user creates a scrollbar that sets the volume. I would have to create new Threads thaaat often.
VulpesRank #55 · 29.2K reputationPosted Jul 15, 2012, 5:36 AM EDT
Whilst starting a new thread may pose some problems of its own, I don't see what other option is open to you. However, you should be able to use the threadpool rather than creating your own thread manually if MTA is required, because that's what the threadpool uses and (to my knowledge) it can't be changed.
florian21 reputationPosted Jul 15, 2012, 5:42 AM EDT
And by the way whats about creating a background thread that works with something like a queue that contains Actions the thread has to call. And every time the thread gets a new action into to queue it gets pushed?
VulpesRank #55 · 29.2K reputationPosted Jul 15, 2012, 6:00 AM EDT
Unless those Actions themselves create threads, then you wouldn't be able to mix Actions which require STA or MTA as the background thread itself would have to be one or the other.
I suppose you could have two background threads - one for Actions requiring STA and the other for Actions requiring MTA.
florian21 reputationPosted Jul 15, 2012, 6:18 AM EDT
It is not that way I would like to have it but it works. I've created a MTABackgroundthread.
Thanks a lot for your help :)