<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title>Форум QUIK [тема: Звук через mciSendString и MessageBeep]</title>
		<link>http://forum.quik.ru</link>
		<description>Новое в теме Звук через mciSendString и MessageBeep форума  на сайте Форум QUIK [forum.quik.ru]</description>
		<language>ru</language>
		<docs>http://backend.userland.com/rss2</docs>
		<pubDate>Thu, 23 Apr 2026 18:30:21 +0300</pubDate>
		<item>
			<title>Звук через mciSendString и MessageBeep</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum17/message75297/topic8542/">Звук через mciSendString и MessageBeep</a></b> в форуме <a href="http://forum.quik.ru/forum17/">Обмен опытом</a>. <br />
			<br />====quote====<br /><a class="blog-p-user-name" id="bp_3aS2OI8I" href="/user/15910/" bx-tooltip-user-id="15910">Serge123</a> написал:<br /> <br />====quote====<br /><noindex><a href="/user/16011/" target="_blank" rel="nofollow">paluke</a></noindex> написал:<br />Ну например, может оно как-то использует оконные сообщения.<br />=============<br /> Сомнительно: не видно логики для неработоспособности этой функции в консольных программах. И в документации на сайте МС нет такого предупреждения... Аналогично для более современной функции PlaySound.<br />Как тогда МС вообще планирует использование звука в консольных программах??<br />=============<br />Вроде все работает.<br />Попробуйте сделать такую функцию &nbsp;в dll &nbsp;и добавьте sF в таблицу luaL_Reg <br />В данном примере это luaL_Reg nks&#91;&#93;<br />
====code====
<pre>void WINAPI soundF(char*ps,long m){ PlaySound(ps,GetModuleHandle(NULL), SND_FILENAME|SND_ASYNC);if (m)SleepEx(m,TRUE); }
static int sF(lua_State*L){ soundF((char*)lua_tostring(L,1),lua_tointeger(L,2));return 0; }
</pre>
=============
в луа надо вызывать так:
====code====
<pre>local x="C:/Windows/Media/Alarm10.wav" -- звуковой файл
nks.sF(x,1000);
</pre>
============= <br />
			<i>19.04.2024 08:21:26, nikolz.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum17/message75297/topic8542/</link>
			<guid>http://forum.quik.ru/messages/forum17/message75297/topic8542/</guid>
			<pubDate>Fri, 19 Apr 2024 08:21:26 +0300</pubDate>
			<category>Обмен опытом</category>
		</item>
		<item>
			<title>Звук через mciSendString и MessageBeep</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum17/message75291/topic8542/">Звук через mciSendString и MessageBeep</a></b> в форуме <a href="http://forum.quik.ru/forum17/">Обмен опытом</a>. <br />
			<br />====quote====<br /><a class="blog-p-user-name" id="bp_USOOBr6S" href="/user/16011/" bx-tooltip-user-id="16011">paluke</a> написал:<br />Ну например, может оно как-то использует оконные сообщения.<br />=============<br />Сомнительно: не видно логики для неработоспособности этой функции в консольных программах. И в документации на сайте МС нет такого предупреждения... Аналогично для более современной функции PlaySound.<br />Как тогда МС вообще планирует использование звука в консольных программах?? <br />
			<i>18.04.2024 14:04:54, Serge123.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum17/message75291/topic8542/</link>
			<guid>http://forum.quik.ru/messages/forum17/message75291/topic8542/</guid>
			<pubDate>Thu, 18 Apr 2024 14:04:54 +0300</pubDate>
			<category>Обмен опытом</category>
		</item>
		<item>
			<title>Звук через mciSendString и MessageBeep</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum17/message75290/topic8542/">Звук через mciSendString и MessageBeep</a></b> в форуме <a href="http://forum.quik.ru/forum17/">Обмен опытом</a>. <br />
			<br />====quote====<br /><a class="blog-p-user-name" id="bp_LNz4S4iZ" href="/user/15910/" bx-tooltip-user-id="15910">Serge123</a> написал:<br />Вопрос, почему mciSendString в консольной программе не выдаёт звук, так и остался открытым...<br />=============<br />Ну например, может оно как-то использует оконные сообщения. <br />
			<i>18.04.2024 13:19:08, paluke.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum17/message75290/topic8542/</link>
			<guid>http://forum.quik.ru/messages/forum17/message75290/topic8542/</guid>
			<pubDate>Thu, 18 Apr 2024 13:19:08 +0300</pubDate>
			<category>Обмен опытом</category>
		</item>
		<item>
			<title>Звук через mciSendString и MessageBeep</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum17/message74933/topic8542/">Звук через mciSendString и MessageBeep</a></b> в форуме <a href="http://forum.quik.ru/forum17/">Обмен опытом</a>. <br />
			Вопрос, почему mciSendString в консольной программе не выдаёт звук, так и остался открытым... <br />
			<i>17.03.2024 22:09:37, Serge123.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum17/message74933/topic8542/</link>
			<guid>http://forum.quik.ru/messages/forum17/message74933/topic8542/</guid>
			<pubDate>Sun, 17 Mar 2024 22:09:37 +0300</pubDate>
			<category>Обмен опытом</category>
		</item>
		<item>
			<title>Звук через mciSendString и MessageBeep</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum17/message74780/topic8542/">Звук через mciSendString и MessageBeep</a></b> в форуме <a href="http://forum.quik.ru/forum17/">Обмен опытом</a>. <br />
			Оказывается, был уже похожий пример: <noindex><a href="https://forum.quik.ru/messages/forum10/message44608/topic5389/#message44608" target="_blank" rel="nofollow">https://forum.quik.ru/messages/forum10/message44608/topic5389/#message44608</a></noindex> <br />
			<i>06.03.2024 22:23:32, Serge123.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum17/message74780/topic8542/</link>
			<guid>http://forum.quik.ru/messages/forum17/message74780/topic8542/</guid>
			<pubDate>Wed, 06 Mar 2024 22:23:32 +0300</pubDate>
			<category>Обмен опытом</category>
		</item>
		<item>
			<title>Звук через mciSendString и MessageBeep</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum17/message74779/topic8542/">Звук через mciSendString и MessageBeep</a></b> в форуме <a href="http://forum.quik.ru/forum17/">Обмен опытом</a>. <br />
			Попробовал играть звук через PlaySound, почему-то не играет звук асинхронно и ошибку не возвращает, как было сказано на стр. <noindex><a href="https://learn.microsoft.com/en-us/previous-versions//dd743680(v=vs.85)" target="_blank" rel="nofollow">https://learn.microsoft.com/en-us/previous-versions//dd743680(v=vs.85)</a></noindex><br /><br />Вот пример программы:<br />
====code====
<pre>#include &#60;stdio.h&#62;
#include &#60;windows.h&#62;
#include &#60;Mmsystem.h&#62;

int main()
{ char *sname = "C:&#92;&#92;Windows&#92;&#92;Media&#92;&#92;chord.wav";

&nbsp;&nbsp;if (PlaySound(sname, NULL, SND_FILENAME | SND_ASYNC)) puts("Success&#92;n");
&nbsp;&nbsp;if (!PlaySound("SystemDefault", NULL, SND_ALIAS | SND_SYNC)) puts("Fail&#92;n");
&nbsp;&nbsp;return 0;
}
</pre>
=============
Вот компиляция:
====code====
<pre>gcc.exe playsnd.c -o playsnd.exe -O2 -s -lWinmm -m64 -std=c17
</pre>
=============
Кто что скажет, почему асинхронно не работает? Или это только у меня так? <br />
			<i>06.03.2024 22:04:35, Serge123.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum17/message74779/topic8542/</link>
			<guid>http://forum.quik.ru/messages/forum17/message74779/topic8542/</guid>
			<pubDate>Wed, 06 Mar 2024 22:04:35 +0300</pubDate>
			<category>Обмен опытом</category>
		</item>
		<item>
			<title>Звук через mciSendString и MessageBeep</title>
			<description><![CDATA[<b><a href="http://forum.quik.ru/messages/forum17/message74739/topic8542/">Звук через mciSendString и MessageBeep</a></b> в форуме <a href="http://forum.quik.ru/forum17/">Обмен опытом</a>. <br />
			Немного подправил пример, который видел на стр. <noindex><a href="https://quik2dde.ru/viewtopic.php?id=79" target="_blank" rel="nofollow">https://quik2dde.ru/viewtopic.php?id=79</a></noindex><br />dll файл получился меньше 20 Кб. Искал примеры, чтобы не выскакивало окно консоли, смотрел примеры через виндовс скрипт хост (расширение файла .vbs). Если запускать в Проводнике, то окнА консоли нет, а если в Квике, то есть, не понял, почему...<br /><br />Убрал проверку на ошибки. mci с MessageBeep микшируется, а mci с mci не смог смикшировать. И в том и моём примере mci устройство после завершения скрипта остаётся открытым. В OnStop или в OnClose надо бы закрыть, или ну его? Я пробовал вставить mciSendString(&quot;CLOSE QUIK_MP3&quot;, NULL, 0, NULL); в DllMain, когда приходит сообщение DLL_THREAD_DETACH, опять нарвался на зависание Квика...<br /><br />МС пишет, что в вин10 mci устарел:<br /><noindex><a href="https://learn.microsoft.com/ru-ru/windows/win32/multimedia/mci-commands" target="_blank" rel="nofollow">https://learn.microsoft.com/ru-ru/windows/win32/multimedia/mci-commands</a></noindex><br />Может, есть уже примеры с использованием MediaPlayer?<br /><br />Кто-то в dll использует
====code====
<pre>#define LUA_LIB
#define LUA_BUILD_AS_DLL
</pre>
=============
кто-то нет, я не увидел различий, по-всякому работает.<br /><br />Компилировать можно примеро так:
====code====
<pre>gcc.exe playsnddll.c -o playsnddll.dll -mdll -O2 -s -L. -llua54 -lWinmm -m64 -std=c17
</pre>
=============
Это playsnddll.dll.c:<table class="forum-spoiler"><thead onclick="if (this.nextSibling.style.display=='none') { this.nextSibling.style.display=''; BX.addClass(this, 'forum-spoiler-head-open'); } else { this.nextSibling.style.display='none'; BX.removeClass(this, 'forum-spoiler-head-open'); } BX.onCustomEvent('BX.Forum.Spoiler:toggle', [{node: this}]); event.stopPropagation();"><tr><th><div>Скрытый текст</div></th></tr></thead><tbody class="forum-spoiler" style="display:none;"><tr><td>
====code====
<pre>#include &#60;windows.h&#62;
#include &#60;mmsystem.h&#62;
/*
 // #include &#60;stdbool.h&#62;
 #define bool&nbsp;&nbsp;&nbsp;_Bool
 #define true&nbsp;&nbsp;&nbsp;1
 #define false&nbsp;&nbsp;&nbsp;0
*/
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"

/*
// Стандартная точка входа для DLL
bool APIENTRY DllMain(HANDLE hModule, DWORD&nbsp;&nbsp;ul_reason_for_call, LPVOID lpReserved)
{ return true;
}
*/

static int forLua_mciSendString(lua_State *L)
{ mciSendString("CLOSE QUIK_MP3", NULL, 0, NULL);
&nbsp;&nbsp;mciSendString(lua_tostring(L, 1), NULL, 0, NULL);
&nbsp;&nbsp;mciSendString("PLAY QUIK_MP3", NULL, 0, NULL);
&nbsp;&nbsp;return 0;
}

static int forLua_MessageBeep(lua_State *L)
{ MessageBeep(lua_tointeger(L, 1));
&nbsp;&nbsp;return 0;
}
&nbsp;&nbsp;&nbsp;
// список реализованных в dll пользовательских функций
static struct luaL_Reg ls_lib&#91;&#93; =
{ {"mciSendString", forLua_mciSendString},
&nbsp;&nbsp;{"MessageBeep", forLua_MessageBeep},
&nbsp;&nbsp;{NULL, NULL}
};

// Имя dll должно быть playsnddll, как написано ниже!
__declspec(dllexport) int luaopen_playsnddll(lua_State *L)
{ luaL_newlib(L, ls_lib);
&nbsp;&nbsp;return 1;
}
</pre>
=============
</td></tr></tbody></table><br />Это playsnd.lua:<table class="forum-spoiler"><thead onclick="if (this.nextSibling.style.display=='none') { this.nextSibling.style.display=''; BX.addClass(this, 'forum-spoiler-head-open'); } else { this.nextSibling.style.display='none'; BX.removeClass(this, 'forum-spoiler-head-open'); } BX.onCustomEvent('BX.Forum.Spoiler:toggle', [{node: this}]); event.stopPropagation();"><tr><th><div>Скрытый текст</div></th></tr></thead><tbody class="forum-spoiler" style="display:none;"><tr><td>
====code====
<pre>-- Предполагается, что эта dll лежит в подпапке "скрипты" папки Quik
package.cpath =&nbsp;&nbsp;package.cpath .. ';' .. getWorkingFolder() .. '&#92;&#92;скрипты' .. '&#92;&#92;playsnddll.dll'
local playsnddll = require('playsnddll')

-- Эту функцию можно удалить и вызывать напрямую playsnddll.mciSendString
local function PlaySoundFile(file_name)
 playsnddll.mciSendString('OPEN "' .. file_name .. '" TYPE MpegVideo ALIAS QUIK_MP3')
end

function main()
 playsnddll.MessageBeep(0x10)
-- playsnddll.MessageBeep(0)
 PlaySoundFile('C:&#92;&#92;Windows&#92;&#92;Media&#92;&#92;chord.wav')
 playsnddll.mciSendString('OPEN "' .. 'C:&#92;&#92;Windows&#92;&#92;Media&#92;&#92;ringout.wav' .. '" TYPE MpegVideo ALIAS QUIK_MP3')
-- PlaySoundFile('C:&#92;&#92;Windows&#92;&#92;Media&#92;&#92;Windows Hardware Fail.wav')
-- PlaySoundFile('C:&#92;&#92;Windows&#92;&#92;Media&#92;&#92;Windows Hardware Insert.wav')
-- PlaySoundFile('C:&#92;&#92;Windows&#92;&#92;Media&#92;&#92;Windows Error.wav')
-- PlaySoundFile('C:&#92;&#92;Windows&#92;&#92;Media&#92;&#92;Windows Message Nudge.wav')
end
</pre>
=============
</td></tr></tbody></table> <br />
			<i>04.03.2024 17:20:49, Serge123.</i>]]></description>
			<link>http://forum.quik.ru/messages/forum17/message74739/topic8542/</link>
			<guid>http://forum.quik.ru/messages/forum17/message74739/topic8542/</guid>
			<pubDate>Mon, 04 Mar 2024 17:20:49 +0300</pubDate>
			<category>Обмен опытом</category>
		</item>
	</channel>
</rss>
