Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
################################################################################
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
################################################################################

/.vs/*
#/docs/wwwroot/lib/*
#/docs/wwwroot/scripts/*
obj/
bin/
.git/
CMakeFiles/
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

7 changes: 3 additions & 4 deletions CoreCLRHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ int runFromEntryPoint(

std::string tpaList;
AddFilesFromDirectoryToTpaList( clrFilesAbsolutePath, tpaList );
std::cout<<"line 32"<<std::endl;
//std::cout<<"line 32"<<std::endl;
auto dl = dynamicLinker::dynamicLinker::make_new( coreClrDllPath );
auto coreclr_initialize = dl->getFunction<coreclrInitializeFunction>("coreclr_initialize");
auto coreclr_shutdown = dl->getFunction<coreclrShutdownFunction>("coreclr_shutdown");
auto coreclr_create_delegate = dl->getFunction<coreclrCreateDelegateFunction>("coreclr_create_delegate");
std::cout<<"line 37"<<std::endl;
//std::cout<<"line 37"<<std::endl;
try {
dl->open();
coreclr_initialize.init();
Expand Down Expand Up @@ -176,7 +176,6 @@ JNIEXPORT jint JNICALL Java_Sample1_intMethod
}
JNIEXPORT jint JNICALL Java_Sample1_coreClrHost(JNIEnv *env, jobject obj, jstring string)
{
std::cout<<"haha"<<std::endl;
const char *str = env->GetStringUTFChars(string,0);
char cap[128];
strcpy(cap,str);
Expand Down Expand Up @@ -216,7 +215,7 @@ JNIEXPORT jint JNICALL Java_Sample1_coreClrHost(JNIEnv *env, jobject obj, jstrin

int exitCode = runFromEntryPoint(
cwd, //+std::string("./tar.so"), // absolute path to this exe
std::string("/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.1/"), // absolute path to coreCLR DLLs
std::string("/usr/share/dotnet/shared/Microsoft.NETCore.App/2.1.30/"), // absolute path to coreCLR DLLs
assemblyDir, // absolute path to DLL to run
assemblyName,
std::string("Managed"),
Expand Down
222 changes: 222 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.16

# Default target executed when no arguments are given to make.
default_target: all

.PHONY : default_target

# Allow only one "make -f Makefile2" at a time, but pass parallelism.
.NOTPARALLEL:


#=============================================================================
# Special targets provided by cmake.

# Disable implicit rules so canonical targets will work.
.SUFFIXES:


# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =

.SUFFIXES: .hpux_make_needs_suffix_list


# Suppress display of executed commands.
$(VERBOSE).SILENT:


# A target that is always out of date.
cmake_force:

.PHONY : cmake_force

#=============================================================================
# Set environment variables for the build.

# The shell in which to execute make rules.
SHELL = /bin/sh

# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake

# The command to remove a file.
RM = /usr/bin/cmake -E remove -f

# Escaping for special characters.
EQUALS = =

# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /mnt/d/Projects/Nitin/Java2CSharp/Java2CSharp

# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /mnt/d/Projects/Nitin/Java2CSharp/Java2CSharp

#=============================================================================
# Targets provided globally by CMake.

# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
/usr/bin/cmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache

# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache

.PHONY : rebuild_cache/fast

# Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..."
/usr/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available.
.PHONY : edit_cache

# Special rule for the target edit_cache
edit_cache/fast: edit_cache

.PHONY : edit_cache/fast

# The main all target
all: cmake_check_build_system
$(CMAKE_COMMAND) -E cmake_progress_start /mnt/d/Projects/Nitin/Java2CSharp/Java2CSharp/CMakeFiles /mnt/d/Projects/Nitin/Java2CSharp/Java2CSharp/CMakeFiles/progress.marks
$(MAKE) -f CMakeFiles/Makefile2 all
$(CMAKE_COMMAND) -E cmake_progress_start /mnt/d/Projects/Nitin/Java2CSharp/Java2CSharp/CMakeFiles 0
.PHONY : all

# The main clean target
clean:
$(MAKE) -f CMakeFiles/Makefile2 clean
.PHONY : clean

# The main clean target
clean/fast: clean

.PHONY : clean/fast

# Prepare targets for installation.
preinstall: all
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall

# Prepare targets for installation.
preinstall/fast:
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast

# clear depends
depend:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend

#=============================================================================
# Target rules for targets named sample1

# Build rule for target.
sample1: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 sample1
.PHONY : sample1

# fast build rule for target.
sample1/fast:
$(MAKE) -f CMakeFiles/sample1.dir/build.make CMakeFiles/sample1.dir/build
.PHONY : sample1/fast

#=============================================================================
# Target rules for targets named tar

# Build rule for target.
tar: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 tar
.PHONY : tar

# fast build rule for target.
tar/fast:
$(MAKE) -f CMakeFiles/tar.dir/build.make CMakeFiles/tar.dir/build
.PHONY : tar/fast

CoreCLRHost.o: CoreCLRHost.cpp.o

.PHONY : CoreCLRHost.o

# target to build an object file
CoreCLRHost.cpp.o:
$(MAKE) -f CMakeFiles/tar.dir/build.make CMakeFiles/tar.dir/CoreCLRHost.cpp.o
.PHONY : CoreCLRHost.cpp.o

CoreCLRHost.i: CoreCLRHost.cpp.i

.PHONY : CoreCLRHost.i

# target to preprocess a source file
CoreCLRHost.cpp.i:
$(MAKE) -f CMakeFiles/tar.dir/build.make CMakeFiles/tar.dir/CoreCLRHost.cpp.i
.PHONY : CoreCLRHost.cpp.i

CoreCLRHost.s: CoreCLRHost.cpp.s

.PHONY : CoreCLRHost.s

# target to generate assembly for a file
CoreCLRHost.cpp.s:
$(MAKE) -f CMakeFiles/tar.dir/build.make CMakeFiles/tar.dir/CoreCLRHost.cpp.s
.PHONY : CoreCLRHost.cpp.s

dynamicLinker/dynamicLinker.o: dynamicLinker/dynamicLinker.cpp.o

.PHONY : dynamicLinker/dynamicLinker.o

# target to build an object file
dynamicLinker/dynamicLinker.cpp.o:
$(MAKE) -f CMakeFiles/tar.dir/build.make CMakeFiles/tar.dir/dynamicLinker/dynamicLinker.cpp.o
.PHONY : dynamicLinker/dynamicLinker.cpp.o

dynamicLinker/dynamicLinker.i: dynamicLinker/dynamicLinker.cpp.i

.PHONY : dynamicLinker/dynamicLinker.i

# target to preprocess a source file
dynamicLinker/dynamicLinker.cpp.i:
$(MAKE) -f CMakeFiles/tar.dir/build.make CMakeFiles/tar.dir/dynamicLinker/dynamicLinker.cpp.i
.PHONY : dynamicLinker/dynamicLinker.cpp.i

dynamicLinker/dynamicLinker.s: dynamicLinker/dynamicLinker.cpp.s

.PHONY : dynamicLinker/dynamicLinker.s

# target to generate assembly for a file
dynamicLinker/dynamicLinker.cpp.s:
$(MAKE) -f CMakeFiles/tar.dir/build.make CMakeFiles/tar.dir/dynamicLinker/dynamicLinker.cpp.s
.PHONY : dynamicLinker/dynamicLinker.cpp.s

# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... clean"
@echo "... depend"
@echo "... rebuild_cache"
@echo "... edit_cache"
@echo "... sample1"
@echo "... tar"
@echo "... CoreCLRHost.o"
@echo "... CoreCLRHost.i"
@echo "... CoreCLRHost.s"
@echo "... dynamicLinker/dynamicLinker.o"
@echo "... dynamicLinker/dynamicLinker.i"
@echo "... dynamicLinker/dynamicLinker.s"
.PHONY : help



#=============================================================================
# Special targets to cleanup operation of make.

# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system

23 changes: 15 additions & 8 deletions Managed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@
using System;
using System.Runtime.InteropServices;

public class Managed {
public class Managed
{

[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
unsafe delegate void myDelegate( IntPtr thisptr );
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
unsafe delegate void myDelegate(IntPtr thisptr);

public static unsafe void runIt( IntPtr thisptr, IntPtr mem_fun ) {
Console.WriteLine("Here's C# code:");
public static unsafe void runIt(IntPtr thisptr, IntPtr mem_fun)
{
Console.WriteLine(ProcessStatement());

myDelegate fun = (myDelegate) Marshal.GetDelegateForFunctionPointer( mem_fun, typeof(myDelegate) );
//myDelegate fun = (myDelegate) Marshal.GetDelegateForFunctionPointer( mem_fun, typeof(myDelegate) );

fun(thisptr); // first argument of member functions in C++ is "this", but it's hidden from us :-)
}
//fun(thisptr); // first argument of member functions in C++ is "this", but it's hidden from us :-)
}
public static string ProcessStatement()
{
return "In ProcessStatement";
}
}

2 changes: 1 addition & 1 deletion Managed.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>library</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
</Project>
25 changes: 25 additions & 0 deletions Managed.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.35027.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Managed", "Managed.csproj", "{66E3787C-26B9-4FDC-9329-C6BE4F9288DD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{66E3787C-26B9-4FDC-9329-C6BE4F9288DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{66E3787C-26B9-4FDC-9329-C6BE4F9288DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{66E3787C-26B9-4FDC-9329-C6BE4F9288DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{66E3787C-26B9-4FDC-9329-C6BE4F9288DD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {21D43ED0-F3C3-4708-9E53-E577E5B5826F}
EndGlobalSection
EndGlobal
Loading