用C++写uefi程序

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操作。。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值