running Win32 c++ code in android

1,011 views
Skip to first unread message

Abhi

unread,
Aug 10, 2011, 11:16:14 AM8/10/11
to android-ndk
Hello,

I have a win32 application that I would like to run on the Android
platform. I am new to this side of android and was looking for some
help to get started. The c++ code has a main function as below

int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hInstP, LPSTR
lpCmdLine, int nCmdShow)

How do I create the JNI wrapper for this? Any ideas?

Thanks,

AB

TiZ

unread,
Aug 10, 2011, 11:21:26 AM8/10/11
to android-ndk
Hi,
basically you have 2 ways to do it: a mix of Java that calls your C++
code, or a completly native C++ application (with, of course, some
reference to the Android stuff).
To have some ideas, look at the samples contained in the NDK: you'll
find and see the difference of the two methods I proposed you.

Hope this helps
Regards
TiZ

mic _

unread,
Aug 10, 2011, 11:47:06 AM8/10/11
to andro...@googlegroups.com
Does the code contain any calls to Win32 API functions? Because those functions obviously don't exist on Android, and in that case porting your application could end up requiring a lot of work.
The application model also differs between Android and Windows. On Windows your application might be a single executable with native code, which in turn links dynamically against a number of libraries (DLLs). On Android an application is a collection of activities, services, providers and receivers that have been packaged together. The activities are typically written in Java, although it's possible to write them in C/C++ as well.

/Michael

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


Bob Holmboe

unread,
Aug 10, 2011, 12:03:34 PM8/10/11
to andro...@googlegroups.com
HINSTANCE is part of the Windows API and I think LPSTR is a Windows specific long pointer. Those two things are not going to be available on the Android framework. You will be able to paste most of your C++ code into a new project as long as it  just C++ code and does not use the Microsoft additions for Windows or MFC.  

Abhi

unread,
Aug 10, 2011, 12:50:54 PM8/10/11
to android-ndk
Thanks for the quick replies everyone. I looked deeper into the c++
code and looks like it uses windows API for creating the UI etc. It is
a .exe application that I want to try and replicate in Android. So
basically, I can get rid of the UI piece frm the original code and do
it in Android instead, and use the rest of the c++ code that contains
the real algorithm of the application?

Thanks.

AB

Colin Knapp

unread,
Aug 10, 2011, 1:08:19 PM8/10/11
to andro...@googlegroups.com

Not really. It's not just windows api stuff but a lot of stuff. A good starting point is that you should be able to fully compile your cpp program for a Linux machine. Once that works, then you can start looking into compiling the cpp code for an Android target.

Chris Stratton

unread,
Aug 10, 2011, 2:21:47 PM8/10/11
to andro...@googlegroups.com
On Wednesday, August 10, 2011 12:50:54 PM UTC-4, Abhi wrote:
Thanks for the quick replies everyone. I looked deeper into the c++
code and looks like it uses windows API for creating the UI etc. It is
a .exe application that I want to try and replicate in Android. So
basically, I can get rid of the UI piece frm the original code and do
it in Android instead, and use the rest of the c++ code that contains
the real algorithm of the application?

It is going to be a large project requiring that you build an understanding of what the current code is trying to do.

One (slight) hopeful point is that both programming models are largely event-driven, though windows lets you poll for events while android requires that you receive event-related calls.
Reply all
Reply to author
Forward
0 new messages