0

我正在尝试在 Windows Phone 中使用现有的 c 代码。为此,我创建了一个 Windows 手机运行时组件 (C++),它具有遗留的 c 代码并在我的托管 WP8 应用程序中引用它。

我在构建解决方案时遇到了问题。

解决方案资源管理器 - 项目结构

我禁用了“sample.c”的预编译头选项

样本.h

int getNumber();

样本.c

#include <stdio.h>
#include"sample.h"

int main()
{
    printf("This is a native C program.\n");
    return 0;
}

int getNumber()
{
    return 2014; // Sample value to return 
}

NativeComponentRoot.cpp

#include "pch.h"
#include "NativeComponentRoot.h"
#include "sample.h" 

using namespace NativeComponentRoot;
using namespace Platform;

WindowsPhoneRuntimeComponent::WindowsPhoneRuntimeComponent()
{
}

NumberGenerator::NumberGenerator()
{

}

int NumberGenerator::GetMeANumber()
{
    int number = getNumber(); // Trying to invoke the function in sample.c
    return number;
}

问题 构建解决方案时出错

我找不到在 Windows Phone Runtime 中集成“C”(非 C++)lib/code 并在托管项目中使用它的适当演练。

4

0 回答 0