c++ - Rtaudio in DLL makes program unresponsive -
i make dll in c++ streams sound speakers , can call visual basic program. creating dll , calling functions vb program worked. however, declare rtaudio object in dll, makes visual basic program unresponsive (and there no sound). if use exact same code in console application project instead of in dll works fine , hear sound. inexperienced in dll programming, have absolutely no idea cause such problem. give me hints might wrong?
this part of code. still produces same problem: dll:
//c , c++ libraries #define _use_math_defines #include <stdio.h> #include <iostream> #include <string> #include <vector> #include <valarray> #include <fstream> #include <stdlib.h> #include <map> #include <math.h> #include <stdint.h> #include <algorithm> #include <complex> #include <cmath> #include <iomanip> #include <limits> #include <time.h> #include <fcntl.h> #include <ctype.h> #include <windows.h> //boost thread library multi-threading #include <boost\thread.hpp> //include rtaudio #include <rtaudio.h> #ifdef audiodll1_exports #define audiodll1_api __declspec(dllexport) #else #define audiodll1_api __declspec(dllimport) #endif rtaudio dac; //if leave line out, works bool apientry dllmain(handle hmodule, dword ul_reason_for_call, lpvoid lpreserved) { switch (ul_reason_for_call) { case dll_process_attach: break; case dll_thread_attach: break; case dll_thread_detach: break; case dll_process_detach: break; } return true; } audiodll1_api int __stdcall getnumber() { return 5; }
this .def file:
library audiodll1 description 'audio dll test 1' exports getnumber
and vb example code:
public class form1 private declare function getnumber lib "audiodll1.dll" () integer dim mynum integer private sub form1_load(sender object, e eventargs) handles mybase.load label1.text = 10 end sub private sub button1_click(sender object, e eventargs) handles button1.click label1.text = 1 mynum = getnumber() label1.text = 2 label1.text = mynum end sub end class
as said, problem the
rtaudio dac;
i tried declaring locally, putting in thread etc. nothing works. however, if create win32 console application, include same headers, link same libraries, works well. these libs i'm linking to:
dsound.lib rtaudiolib.lib kernel32.lib user32.lib advapi32.lib ole32.lib
i not inherit parent or project defaults.
oh , i'm aware if work, not hear sound using code above. said, tried deleting portions of code find problem. , rtaudio dac; takes cause it.
edit: should add, rtaudiolib.lib static libary made rtaudio 4.0.12 code using
#define __windows_ds__ #define __windows_asio__
i immensely appreciate help.
best regards
the rtaudio constructor calling rtapids::getdevicecount() in turn calling directsoundenumerate() function of dsound.dll.
i tried declare rtaudio object during dll_process_attach (or in global space, seems cause same problem).
microsoft states 1 should not load other libraries during dll_process_attach.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682583.aspx
the entry-point function should perform simple initialization or termination tasks. must not call loadlibrary or loadlibraryex function (or function calls these functions), because may create dependency loops in dll load order. can result in dll being used before system has executed initialization code. similarly, entry-point function must not call freelibrary function (or function calls freelibrary) during process termination, because can result in dll being used after system has executed termination code.
so decided not in dll_process_attach , have separate custom init() function dll. solved issues.
Comments
Post a Comment