用C++写uefi程序
2015-06-07 16:54
316 查看
uefi编程多半是以C语言进行开发,要想使用类和模板要在cpp文件中以如下方式包含头文件
#ifdef __cplusplus
extern "C"{
#endif
#include <uefi.h>
#include <library/uefilib.h>
#include <library/basememorylib.h>
#include <Library/MemoryAllocationLib.h>
#include <library/uefiapplicationentrypoint.h>
#include <Library/UefiBootServicesTableLib.h>
#include <library/baselib.h>
#include <library/printlib.h>
//#include <typeinfo>
#ifdef __cplusplus
}
#endif
并定义NULL
#undef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((VOID*)0)
#endif
然后为了消除bool类型的警告要在inf文件中的[BuildOptions] 模块中加上
MSFT:*_*_*_CC_FLAGS = /wd4804
然后就可以写如下代码
class TestClass
{
public:
TestClass(){Print((CHAR16*)L"hello world c plus plus \r\n");}
~TestClass(){Print((CHAR16*)L"bye bye !!!");}
};
//typeid操作符的返回结果是名为type_info的标准库类型的对象的引用
template<typename type1, typename type2>
void TestTemplate(type1 a, type2 b)
{
Print((CHAR16*)L"size of first arg is %d size of second arg is %d \r\n", sizeof(a), sizeof(b));
}
EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE *SystemTable)
{
CHAR16 Msg[100];
UnicodeSPrint(Msg, 100, (CHAR16*)L"hello world \r\n");
Print(Msg);
TestClass t;
UINT32 a = 1;
CHAR16 *b = NULL;
TestTemplate(a, b);
return EFI_SUCCESS;
}
这样个还不支持new和delete操作。。
#ifdef __cplusplus
extern "C"{
#endif
#include <uefi.h>
#include <library/uefilib.h>
#include <library/basememorylib.h>
#include <Library/MemoryAllocationLib.h>
#include <library/uefiapplicationentrypoint.h>
#include <Library/UefiBootServicesTableLib.h>
#include <library/baselib.h>
#include <library/printlib.h>
//#include <typeinfo>
#ifdef __cplusplus
}
#endif
并定义NULL
#undef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((VOID*)0)
#endif
然后为了消除bool类型的警告要在inf文件中的[BuildOptions] 模块中加上
MSFT:*_*_*_CC_FLAGS = /wd4804
然后就可以写如下代码
class TestClass
{
public:
TestClass(){Print((CHAR16*)L"hello world c plus plus \r\n");}
~TestClass(){Print((CHAR16*)L"bye bye !!!");}
};
//typeid操作符的返回结果是名为type_info的标准库类型的对象的引用
template<typename type1, typename type2>
void TestTemplate(type1 a, type2 b)
{
Print((CHAR16*)L"size of first arg is %d size of second arg is %d \r\n", sizeof(a), sizeof(b));
}
EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE *SystemTable)
{
CHAR16 Msg[100];
UnicodeSPrint(Msg, 100, (CHAR16*)L"hello world \r\n");
Print(Msg);
TestClass t;
UINT32 a = 1;
CHAR16 *b = NULL;
TestTemplate(a, b);
return EFI_SUCCESS;
}
这样个还不支持new和delete操作。。
相关文章推荐
- 一起talk C栗子吧(第十二回:C语言实例--单链表一)
- C++ 调用system()函数的多命令合并
- 关于C++函数思考2(C++函数返回引用和返回非引用的区别)
- C语言(1) HelloWord 与JAVA对比
- C++和JAVA的区别
- 面试考题之9.2:链表(C/C++版)
- 用C++实现多线程Mutex锁(Win32)
- C++11:override 与 final
- C/C++ 语言中的表达式求值
- C语言多线程下不同等级日志的实现
- c++ 访问者模式
- c++在string类源
- Microsoft Visual C++ Runtime Library Runtime Error解决的方式
- 在mfc中使用cef
- 设计模式之访问者模式,C++实现
- Effective C++ 条款45
- effective c++ 条款7
- C++开发者都应该使用的10个C++11特性
- C++函数的返回值问题(1)——返回引用类型&非引用类型
- 我所理解的设计模式(C++实现)——访问者模式(Visitor Pattern)