0

I am trying to use a existing c code in Windows Phone. For that I have created a Windows phone runtime component (C++) which has the legacy c code and referring it in my managed WP8 application.

I am facing issues in building the solution.

Solution Explorer - Project Structure

I have disable Precompiled headers option for "sample.c"

sample.h

int getNumber();

sample.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;
}

Issue Error on building the solution

I couldnt find a proper walk through for integrating "C" (Not C++) lib/code in Windows Phone Runtime and using it in managed project.

Rajmohan Kathiresan
  • 338
  • 1
  • 3
  • 12
  • The problem is that you mix C and C++, it has likely nothing to do with the phone stuff. http://stackoverflow.com/questions/1041866/in-c-source-what-is-the-effect-of-extern-c – Lundin Apr 17 '14 at 06:33
  • @Lundin Thanks for the response . Added extern keywork while including C header in cpp file. – Rajmohan Kathiresan Apr 17 '14 at 06:53

0 Answers0