gpt4 book ai didi

c++ - 通过 FireMonkey/C++ 在 OS X 中寻址 COM

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:46:33 30 4
gpt4 key购买 nike

基于 COM 的 Blackmagic DeckLink API 可用于 Windows 和 OS X。我希望在 OS X 中解决它,但在 C++ 中使用 FireMonkey (FMX)。问题是他们的示例代码* 是为 Cocoa 编写的,我不知道如何为 FireMonkey 重写它。有没有人有这方面的经验,甚至有可能。

或者,是否有一种通用方法可以在 FireMonkey/OS X 中寻址具有 COM 接口(interface)的库?

根据请求,这是 Cocoa 的部分代码。

void    InitDeckLinkAPI (void)
{
CFURLRef bundleURL;

bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR(kDeckLinkAPI_BundlePath), kCFURLPOSIXPathStyle, true);
if (bundleURL != NULL)
{
gDeckLinkAPIBundleRef = CFBundleCreate(kCFAllocatorDefault, bundleURL);
if (gDeckLinkAPIBundleRef != NULL)
{
gCreateIteratorFunc = (CreateIteratorFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateDeckLinkIteratorInstance_0002"));
gCreateAPIInformationFunc = (CreateAPIInformationFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateDeckLinkAPIInformationInstance_0001"));
gCreateOpenGLPreviewFunc = (CreateOpenGLScreenPreviewHelperFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateOpenGLScreenPreviewHelper_0001"));
gCreateCocoaPreviewFunc = (CreateCocoaScreenPreviewFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateCocoaScreenPreview_0001"));
gCreateVideoConversionFunc = (CreateVideoConversionInstanceFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateVideoConversionInstance_0001"));
}
CFRelease(bundleURL);
}
}

bool IsDeckLinkAPIPresent (void)
{
// If the DeckLink API bundle was successfully loaded, return this knowledge to the caller
if (gDeckLinkAPIBundleRef != NULL)
return true;

return false;
}

IDeckLinkIterator* CreateDeckLinkIteratorInstance (void)
{
pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);

if (gCreateIteratorFunc == NULL)
return NULL;

return gCreateIteratorFunc();
}

*此处太长,但您可以下载 here .

最佳答案

在没有本地 COM 支持的平台上(例如 OS X),应该提供一个 C 入口点来访问接口(interface),在 DeckLink API 中有这样的工厂方法:

IDeckLinkIterator *deckLinkIterator = CreateDeckLinkIteratorInstance();

因此您可以在 C++Builder 中简单地使用 DeckLink API。但是有一个问题,C++Builder在sysmac.h中定义了一些COM类型比如IUnknown(包含在System.hpp中)与CFPluginCOM.h中定义的相同类型冲突,如果你的项目包含System.hpp例如所有 firemonkey 项目编译器都会显示错误:

[bccosx Error] sysmac.h(287): E2238 Multiple declaration for 'IUnknown'

DeckLink API的samples目录下有一个名为DeckControl的sample,是一个console程序,可以用C++Builder编译:

  1. 创建控制台项目并指定 main.cpp 作为项目源。
  2. 选择“无”作为目标框架
  3. 添加“OSX”平台

项目编译成功

那么 Fmx 项目(使用 System.hpp)呢?
创建一个包装器单元(例如 bcb_deck),将所需的 API 放入其中。请注意,不要在单元头中包含“DeckLinkAPI.h”,这会导致与上述相同的问题,但将其放在 cpp (bcb_deck.cpp) 中,例如:

bcb_deck.cpp:

void* createDeckLinkIteratorInstance() // use camel case to prevent conflict
{
return (void*) CreateDeckLinkIteratorInstance();
}

bool deckLinkIteratorNext(void *hDeckLinkIterator, void *hDeckLink)
{
IDeckLinkIterator *deckLinkIterator = (IDeckLinkIterator*) hDeckLinkIterator;
IDeckLink *deckLink = (IDeckLink*) hDeckLink;

return deckLinkIterator->Next(&deckLink) == S_OK;
}

用法:

#include "bcb_deck.h"
void *hDeckLinkIterator, *hDeckLink;
hDeckLinkIterator = createDeckLinkIteratorInstance();
if (hDeckLinkIterator)
{
// Enumerate all cards in this system
while (deckLinkIteratorNext(hDeckLinkIterator, hDeckLink))
{
// ...
}
}

关于c++ - 通过 FireMonkey/C++ 在 OS X 中寻址 COM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21287972/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com