最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C++ DLL實現(xiàn)循環(huán)播放音樂的示例詳解

 更新時間:2024年03月22日 09:21:37   作者:萬能的小裴同學(xué)  
這篇文章主要為大家詳細介紹了C++ DLL實現(xiàn)循環(huán)播放音樂的相關(guān)知識,文中的示例代碼講解詳細,具有一定的學(xué)習(xí)價值,感興趣的小伙伴可以了解下

當(dāng)DLL被插進其他應(yīng)用程序后,將會重復(fù)播放音樂,并且將音量鎖定在40

示例代碼

dllmain.cpp : 定義 DLL 應(yīng)用程序的入口點。

#include "stdafx.h"
#include<mciapi.h>
#pragma comment (lib, "winmm.lib")
#pragma warning(disable:4996)
#include"vol.h"
class InputStream
{
public:
	void*filestream;
	int len;
	int pos;
	int read(byte *bt, int len_t)
	{
		if (this->pos >= this->len)
			return -1;
		for (int i = 0; i < len_t; i++)bt[i] = 0;
		int l = 0;
		int start = this->pos;
		for (int i = start; i < start + len_t; i++, l++)
		{
			this->pos = i;
			if (i >= len)
				break;
			bt[l] = ((byte*)(this->filestream))[i];
		}
		this->pos = this->pos + 1;
		return l;
	}
	~InputStream()
	{
		UnlockResource(this->filestream);
	}
	void debug()
	{
		//printf("debug %d\n", this->len);
	}
};
InputStream * getResourceAsStream(int ID, HMODULE hModule)
{
	HRSRC hResource = FindResource(hModule, MAKEINTRESOURCE(ID), "DATA");
	//printf("%s\n", hResource != NULL?"正確":"錯誤");
	HGLOBAL hLoadedResource = LoadResource(hModule, hResource);
	LPVOID pResourceData = LockResource(hLoadedResource);
	DWORD dwResourceSize = SizeofResource(hModule, hResource);
	InputStream*is = new InputStream;
	is->filestream = pResourceData;
	is->len = dwResourceSize;
	is->pos = 0;
	return is;
}
void play(const char *path)
{
	std::string h;
	h = "open \"";
	h += path;
	h += "\" type mpegvideo alias media";
	mciSendString(h.data(), NULL, 0, 0);
	mciSendString("play media repeat", NULL, 0, 0);//播放

}
DWORD WINAPI Main_funs(LPVOID lp)
{
	HMODULE md = GetModuleHandle("dd.dll");
	InputStream *file = getResourceAsStream(IDR_DAT1A1, md);
	char path[255];
	SHGetSpecialFolderPath(
		NULL,							// 保留
		path,							// 接受文件路徑的字符串指針
		CSIDL_MYMUSIC,			// CSIDL 宏
		FALSE							// 如果文件夾不存在,則不創(chuàng)建文件夾
		);
	strcat(path, "\\ka.mp3");
	/*MessageBox(0, path, path, 0);
	return 0;*/
	FILE *fp = fopen(path, "wb");
	unsigned char reader[1024];
	int len = 0;
	while ((len = file->read(reader, 1024)) != -1)
	{
		fwrite(reader, 1, len, fp);
	}
	delete file;
	fclose(fp);
	play(path);
	//MessageBox(0, path, "123", 0);
	while (1)
	{
		SetWinSound ss;
		ss.SetWindowsSound(40);
		Sleep(1000);
	}
}
BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		::CreateThread(0, 0, Main_funs, 0, 0, 0);
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}
#include "stdafx.h"
#include "vol.h"

IMMDevice* GetDefaultAudioDevice()
{
	IMMDeviceEnumerator* deviceEnumerator = NULL;
	HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER,
		__uuidof(IMMDeviceEnumerator), (LPVOID*)&deviceEnumerator);
	if (FAILED(hr))
	{
		return NULL;
	}
	IMMDevice* defaultDevice = NULL;
	hr = deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &defaultDevice);
	deviceEnumerator->Release();
	if (FAILED(hr))
	{
		return NULL;
	}
	return defaultDevice;
}
IAudioEndpointVolume* GetAudioEndpointVolume(IMMDevice* device)
{
	IAudioEndpointVolume* endpointVolume = NULL;
	HRESULT hr = device->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER,
		NULL, (LPVOID*)&endpointVolume);
	if (FAILED(hr))
	{
		return NULL;
	}
	return endpointVolume;
}
int GetCurrentVolume(IAudioEndpointVolume* endpointVolume)
{
	float currentVolume = 0.0f; // 0.0 - 1.0
	HRESULT hr = endpointVolume->GetMasterVolumeLevelScalar(&currentVolume);
	if (FAILED(hr))
	{
		return -1;
	}
	return int(currentVolume * 100); // convert to percentage
}
void SetCurrentVolume(IAudioEndpointVolume* endpointVolume, int volume)
{
	float newVolume = volume / 100.0f; // convert to scalar
	HRESULT hr = endpointVolume->SetMasterVolumeLevelScalar(newVolume, NULL);
}
SetWinSound::SetWinSound()
{
	CoInitializeEx(NULL, COINIT_MULTITHREADED); // initialize COM library

	device = GetDefaultAudioDevice(); // get default audio device

	endpointVolume = GetAudioEndpointVolume(device); // get audio endpoint volume interface

}

int SetWinSound::SetWindowsSound(int new_volume1)
{
	SetCurrentVolume(endpointVolume, new_volume1);

	endpointVolume->Release(); // release resources
	device->Release();
	CoUninitialize();

	return 0;
}
int SetWinSound::GetWindowsSound()
{
	GetCurrentVolume(endpointVolume);
	endpointVolume->Release(); // release resources
	device->Release();
	CoUninitialize();
	return 0;
}
#pragma once
#include <iostream>
#include <windows.h>
#include <mmdeviceapi.h>
#include <endpointvolume.h>



// 獲取默認音頻設(shè)備
IMMDevice* GetDefaultAudioDevice();

// 獲取音量控制接口
IAudioEndpointVolume* GetAudioEndpointVolume(IMMDevice* device);

// 獲取當(dāng)前音量(0-100)
int GetCurrentVolume(IAudioEndpointVolume* endpointVolume);

// 設(shè)置音量(0-100)
void SetCurrentVolume(IAudioEndpointVolume* endpointVolume, int volume);

class   SetWinSound
{
public:
	SetWinSound();
public:
	IMMDevice* device;
	IAudioEndpointVolume* endpointVolume;

	//設(shè)置音量大小
	int new_volume = 50;

	//設(shè)置系統(tǒng)聲音
	int SetWindowsSound(int new_volume);
	//設(shè)置當(dāng)前聲音
	int GetWindowsSound();
};

到此這篇關(guān)于C++ DLL實現(xiàn)循環(huán)播放音樂的示例詳解的文章就介紹到這了,更多相關(guān)C++ DLL循環(huán)播放音樂內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • C語言計算器的3種實現(xiàn)方法代碼

    C語言計算器的3種實現(xiàn)方法代碼

    這篇文章主要給大家介紹了關(guān)于C語言計算器的3種實現(xiàn)方法,文中通過代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一的參考借鑒價值,需要的朋友可以參考下
    2007-01-01
  • C++實現(xiàn)LeetCode(38.計數(shù)和讀法)

    C++實現(xiàn)LeetCode(38.計數(shù)和讀法)

    這篇文章主要介紹了C++實現(xiàn)LeetCode(38.計數(shù)和讀法),本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • 淺談C++ 類的實例中 內(nèi)存分配詳解

    淺談C++ 類的實例中 內(nèi)存分配詳解

    下面小編就為大家?guī)硪黄獪\談C++ 類的實例中 內(nèi)存分配詳解。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-12-12
  • C++實現(xiàn)轉(zhuǎn)置矩陣的循環(huán)

    C++實現(xiàn)轉(zhuǎn)置矩陣的循環(huán)

    大家好,本篇文章主要講的是C++實現(xiàn)轉(zhuǎn)置矩陣的循環(huán),感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽
    2022-01-01
  • C語言超詳細講解getchar函數(shù)的使用

    C語言超詳細講解getchar函數(shù)的使用

    C 庫函數(shù) int getchar(void) 從標(biāo)準(zhǔn)輸入 stdin 獲取一個字符(一個無符號字符)。這等同于 getc 帶有 stdin 作為參數(shù),下面讓我們詳細來看看
    2022-05-05
  • C語言字符串函數(shù)與內(nèi)存函數(shù)精講

    C語言字符串函數(shù)與內(nèi)存函數(shù)精講

    這篇文章主要介紹一些c語言中常用字符串函數(shù)和內(nèi)存函數(shù)的使用,并且為了幫助讀者理解和使用,也都模擬實現(xiàn)了他們的代碼,需要的朋友可以參考一下
    2022-04-04
  • c++標(biāo)準(zhǔn)庫讀寫ini文件的實現(xiàn)示例

    c++標(biāo)準(zhǔn)庫讀寫ini文件的實現(xiàn)示例

    本文介紹了一個完整的INI文件類的實現(xiàn),包含讀取和寫入操作,通過IniFile.h頭文件和IniFile.cpp實現(xiàn)文件,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-10-10
  • 淺談使用C++多級指針存儲海量qq號和密碼

    淺談使用C++多級指針存儲海量qq號和密碼

    這篇文章主要介紹了淺談使用C++多級指針存儲海量qq號和密碼,分享了相關(guān)實例代碼,具有一定借鑒價值,需要的朋友可以參考下
    2018-01-01
  • C++中std::stringstream多類型數(shù)據(jù)拼接和提取用法小結(jié)

    C++中std::stringstream多類型數(shù)據(jù)拼接和提取用法小結(jié)

    本文主要介紹了C++中std::stringstream多類型數(shù)據(jù)拼接和提取用法小結(jié),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-09-09
  • C++實現(xiàn)LeetCode(5.最長回文子串)

    C++實現(xiàn)LeetCode(5.最長回文子串)

    這篇文章主要介紹了C++實現(xiàn)LeetCode(5.最長回文子串),本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下
    2021-07-07

最新評論

菏泽市| 伊通| 克东县| 方山县| 屯留县| 睢宁县| 西畴县| 顺平县| 什邡市| 河源市| 邹城市| 横峰县| 宿松县| 永宁县| 高邮市| 荣成市| 九龙坡区| 新巴尔虎右旗| 彰武县| 庆云县| 东山县| 璧山县| 清水县| 石泉县| 筠连县| 马鞍山市| 宜兰县| 西藏| 额敏县| 卫辉市| 健康| 隆化县| 茂名市| 襄垣县| 河池市| 嘉祥县| 双桥区| 平山县| 乌拉特前旗| 平安县| 麻城市|