在不使用基础的情况下从 C++ 获取包路径
Get bundle path from c++ without using foundation
我目前正在开发 Chromium 嵌入式框架应用程序。
该项目由一个客户和一个助手组成。我需要知道来自帮助器的包路径,只需使用基础方法就很简单....好吧,我不能,因为我不能在帮助器中使用基础。
客户端是包裹在 objective-c++ cocoa 应用程序中的基于 C++ 的核心。
助手是纯 C++。
这两个应用程序共享基于进程类型的行为的自定义 class(请参阅下面的代码)。 "OnBeforeCommandLineProcessing"方法需要使用bundle路径! (只是将文件结尾更改为 .mm 并导入 foundation/cocoa 是行不通的,一旦我导入基础,事情就会变得丑陋并出现大量错误)。如何在没有基础的情况下从 C++ 获取包路径? 这不起作用:mainBundle = CFBundleGetMainBundle();
namespace client {
// Base class for customizing process-type-based behavior.
class ClientApp : public CefApp {
public:
ClientApp();
enum ProcessType {
BrowserProcess,
RendererProcess,
ZygoteProcess,
OtherProcess,
};
// Determine the process type based on command-line arguments.
static ProcessType GetProcessType(CefRefPtr<CefCommandLine> command_line);
protected:
// Schemes that will be registered with the global cookie manager.
std::vector<CefString> cookieable_schemes_;
private:
// Registers custom schemes. Implemented by cefclient in
// client_app_delegates_common.cc
static void RegisterCustomSchemes(CefRefPtr<CefSchemeRegistrar> registrar,
std::vector<CefString>& cookiable_schemes);
void OnBeforeCommandLineProcessing(const CefString& process_type,
CefRefPtr<CefCommandLine> command_line) OVERRIDE;
// CefApp methods.
void OnRegisterCustomSchemes(
CefRefPtr<CefSchemeRegistrar> registrar) OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(ClientApp);
};
} // namespace client
#endif // CEF_TESTS_CEFCLIENT_COMMON_CLIENT_APP_H_
重命名为 .mm 后尝试导入 cocoa/foundation:
当你的意思是 #include <CoreFoundation/CoreFoundation.h>
时,你正在导入 Foundation.h
。 Foundation 是一个 ObjC API(与 C++ 不兼容)。核心基础是CAPI。当您包含 CoreFoundation 时,CFBundleGetMainBundle()
应该没问题。请注意开头的 CF
表示它是 Core Foundation 的一部分,而 NS
表示 Foundation(或 AppKit)。
无需重命名 .mm
。只要用CoreFoundation,当个纯C++文件就好了。请记住,Core Foundation 有自己的内存管理。没有 ARC。您需要记住 CFRelease
您使用名称中带有 Create
或 Copy
的函数获得的任何内容(或者您调用 CFRetain
的函数。完整的详细信息在 Memory Management Programming Guide for Core Foundation.
我目前正在开发 Chromium 嵌入式框架应用程序。 该项目由一个客户和一个助手组成。我需要知道来自帮助器的包路径,只需使用基础方法就很简单....好吧,我不能,因为我不能在帮助器中使用基础。
客户端是包裹在 objective-c++ cocoa 应用程序中的基于 C++ 的核心。
助手是纯 C++。
这两个应用程序共享基于进程类型的行为的自定义 class(请参阅下面的代码)。 "OnBeforeCommandLineProcessing"方法需要使用bundle路径! (只是将文件结尾更改为 .mm 并导入 foundation/cocoa 是行不通的,一旦我导入基础,事情就会变得丑陋并出现大量错误)。如何在没有基础的情况下从 C++ 获取包路径? 这不起作用:mainBundle = CFBundleGetMainBundle();
namespace client {
// Base class for customizing process-type-based behavior.
class ClientApp : public CefApp {
public:
ClientApp();
enum ProcessType {
BrowserProcess,
RendererProcess,
ZygoteProcess,
OtherProcess,
};
// Determine the process type based on command-line arguments.
static ProcessType GetProcessType(CefRefPtr<CefCommandLine> command_line);
protected:
// Schemes that will be registered with the global cookie manager.
std::vector<CefString> cookieable_schemes_;
private:
// Registers custom schemes. Implemented by cefclient in
// client_app_delegates_common.cc
static void RegisterCustomSchemes(CefRefPtr<CefSchemeRegistrar> registrar,
std::vector<CefString>& cookiable_schemes);
void OnBeforeCommandLineProcessing(const CefString& process_type,
CefRefPtr<CefCommandLine> command_line) OVERRIDE;
// CefApp methods.
void OnRegisterCustomSchemes(
CefRefPtr<CefSchemeRegistrar> registrar) OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(ClientApp);
};
} // namespace client
#endif // CEF_TESTS_CEFCLIENT_COMMON_CLIENT_APP_H_
重命名为 .mm 后尝试导入 cocoa/foundation:
当你的意思是 #include <CoreFoundation/CoreFoundation.h>
时,你正在导入 Foundation.h
。 Foundation 是一个 ObjC API(与 C++ 不兼容)。核心基础是CAPI。当您包含 CoreFoundation 时,CFBundleGetMainBundle()
应该没问题。请注意开头的 CF
表示它是 Core Foundation 的一部分,而 NS
表示 Foundation(或 AppKit)。
无需重命名 .mm
。只要用CoreFoundation,当个纯C++文件就好了。请记住,Core Foundation 有自己的内存管理。没有 ARC。您需要记住 CFRelease
您使用名称中带有 Create
或 Copy
的函数获得的任何内容(或者您调用 CFRetain
的函数。完整的详细信息在 Memory Management Programming Guide for Core Foundation.