Skip to content

EntryPointNotFoundException with a simple example #161

@gpetrou

Description

@gpetrou

I am testing the usage of the library (CppSharp_VS2012_423_artifacts.zip) with a simple project in VS2012.
I have the following three projects based on some test projects you have in the repository:
Native.vcxproj with Native.h

#if defined(_MSC_VER)
#define DLL_API __declspec(dllexport)
#else
#define DLL_API
#endif

class DLL_API Foo
{
public:
     Foo();
     int A;
     float B;
const char* GetANSI();
};

and Native.cpp

#include "Native.h"  

const char* Foo::GetANSI()
{
 return "ANSI";
}

WrapperGenerator with Program.cs

using System;
using CppSharp;
using CppSharp.AST;
using CppSharp.Generators;

namespace WrapperGenerator
{
       class Program : ILibrary
      {
           static void Main(string[] args)
           {
                 ConsoleDriver.Run(new Program());
                 Console.ReadLine();
            }

           public void Setup(Driver driver)
           {            
        var options = driver.Options;
        options.Verbose = true;
        options.GeneratorKind = GeneratorKind.CSharp;          
        options.LibraryName = "Native";           
        options.Headers.Add(@"F:\Repositories\TestCppSharp\Source\Native\Native.h");
        options.OutputDir = @"F:\Repositories\TestCppSharp\Source\TestCppSharp\";            
        //options.TargetTriple = "i686-pc-win32";          
    }

    public void SetupPasses(Driver driver) { }
    public void Preprocess(Driver driver, ASTContext ctx)  { }
    public void Postprocess(Driver driver, ASTContext ctx) { }
   }

}

The Native.cs file is generated successfully and I have the following simple program in another project TestCppSharp

using System;
using Native;

 namespace TestCppSharp
 {
      class Program
     {
           static void Main(string[] args)
           {
                   Native.Foo d = new Foo();
                   Console.WriteLine(d.GetANSI());
           }
     }
  }

When I run this I get EntryPointNotFoundException inside Native.cs in

    public Foo()
    {
        __Instance = Marshal.AllocHGlobal(8);
        Internal.ctor_0(__Instance);
    }

Any ideas what might be wrong? Also, is the current Getting-Started documentation up-do-date? I could help with that if you want. In that guide the generated code does not include CppSharp.Runtime.ICppMarshal interface. Is it possible to do that in my example?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions