Step 2: C++ Main Function
- Comment out the main function in "PrintOpenWindows.cpp".
/* Uncomment to compile and run PrintOpenWindows.exe
int main()
{
cout << "PRINT_OPEN_WINDOWS ENTRY START" << endl;
printOpenWindowsEntryPoint();
cout << "PRINT_OPEN_WINDOWS ENTRY FINISH" << endl;
}
*/ - In your working directory, add an empty file, named "CPPHelper.h"
#ifndef _CPP_HELPER_H
#define _CPP_HELPER_H
#ifdef __cplusplus
extern "C" {
#endif
void cppHelperEntryPoint();
#ifdef __cplusplus
}
#endif
#endif
- In your working directory, add the following code, in a file named "CPPHelper.cpp":
#include "CPPHelper.h"
#include "PrintOpenWindows.h" // Comment to ignore PrintOpenWindows
#include <iostream>
using namespace std;
void cppHelperExitPoint()
{
cout << "CPP_HELPER EXIT START" << endl;
printOpenWindowsEntryPoint(); // Comment to ignore PrintOpenWindows
cout << "CPP_HELPER EXIT FINISH" << endl;
}
int main()
{
cout << "CPP_HELPER MAIN START" << endl;
cppHelperExitPoint();
cout << "CPP_HELPER MAIN FINISH" << endl;
}
void cppHelperEntryPoint()
{
cout << "CPP_HELPER ENTRY START" << endl;
cppHelperExitPoint(); // Comment to ignore PrintOpenWindows
cout << "CPP_HELPER ENTRY FINISH" << endl;
} - Compile the code and run "CPPHelper.exe", using the following commands:
cd /D "C:\Users\Scott\workspace\myrepo\my-app\src\main\resources\dlls"
"C:\MinGW64\bin\g++.exe" -o CPPHelper.exe CPPHelper.cpp PrintOpenWindows.cpp
CPPHelper.exe
This post was reposted from http://scottizu.wordpress.com/2013/08/21/an-introduction-to-jni-using-a-bottom-up-approach-step-2/, originally written on August 21st, 2013.
No comments:
Post a Comment