c - C Master Volume Windows 中的 __uuidof

标签 c windows com uuid

我想用C更改主音量,但__uuidof仅适用于C++;我可以用什么来代替它?

const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
hr = CoCreateInstance(
     CLSID_MMDeviceEnumerator, NULL,
     CLSCTX_ALL, IID_IMMDeviceEnumerator,
     (void**)&deviceEnumerator);

我只发现:Alternative to __uuidof in C

最佳答案

CLSID_MMDeviceEnumeratorIID_IMMDeviceEnumerator定义in your API's header file ,即<mmdeviceapi.h> .

您必须在 C 代码中使用这些定义,而不是 __uuidof ,因为这仅适用于 C++ 代码。

请注意,您需要包含 <initguid.h>之前<mmdeviceapi.h> :

#include <initguid.h>
#include <mmdeviceapi.h>

那么这段代码应该可以工作:

hr = CoCreateInstance(
    &CLSID_MMDeviceEnumerator, (*)
    NULL,
    CLSCTX_ALL, 
    &IID_IMMDeviceEnumerator,  (*)
    (void**)&deviceEnumerator
);

(*)请注意,我使用了 & (address-of),因为在 C++ 中你有引用,但在 C 代码中你需要显式地使用指针。

关于c - C Master Volume Windows 中的 __uuidof,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47012491/

相关文章:

检查某个索引处的数组是否在 C 中具有未初始化的值

c - Linux 中的 fork() 行为

windows - 在 Windows 上对带有 jq 的文件使用通配符

c++ - 如何使用 CAtlComModule 实现 COM 事件接收器?

c - 在 strncpy 或类似工具上使用 memcpy 是不好的做法吗?

c - malloc - 从 void* 到 double* 的无效转换

linux - 如何将文件从 Windows 传输到 Linux 服务器,使用 shell 脚本处理它,并将结果下载回来

windows - 如何在路径长度大于256的Windows中创建目录

powershell - 如何在PowerShell中查看可用COM对象的描述列表?

c++ - 如何跨多个线程在 COM 中使用 LoadLibrary?