How to initiate a main method in C++ from Java
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Monday, July 1, 2002 06:39 AM

I have a WinMain method in C++ which calls a main method from a class and create a UI. Is it possible to use JNI to call that WinMain method into a JFrame or somehow instantiate an instance of that object to put it on a JFrame? Below is my WinMain and int main() code: int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { // Call the standard main return main(__argc, __argv); } int main(int argc,char *argv[]) { A2GRadar_instance = new A2GRadar_class("A2GRadar",550,600); TrueTypeFontList::Instance(""); A2GRadar_ins   More>>

I have a WinMain method in C++ which calls a main method from a class and create a UI. Is it possible to use JNI to call that WinMain method into a JFrame or somehow instantiate an instance of that object to put it on a JFrame? Below is my WinMain and int main() code:



int WINAPI WinMain

			
(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
			
{
// Call the standard main
return main(__argc, __argv);
}

int main(int argc,char *argv[])
			
{
A2GRadar_instance = new A2GRadar_class("A2GRadar",550,600);
TrueTypeFontList::Instance("");

A2GRadar_instance->CreateObjects();

A2GRadar_instance->SetRedraw();

Timer frameTimer;
do
{
A2GRadar_instance->Calculate(frameTimer.ElapsedSecondsDouble());
}
while(A2GRadar_instance->FrameAnimate());
return 0;
}
   <<Less

Re: How to initiate a main method in C++ from Java

Posted By:   suryakanth_koppera  
Posted On:   Friday, August 2, 2002 07:34 AM

If I understand what u want is to invoke the main method of C++ from Java. I did this in my way if it works for u that will be good. What i did was I created a dll in in c++ and loaded in java. From java I am invoking the Native method called.See the code below.


JNIEXPORT void JNICALL Java_Native_Hello(JNIEnv *env, jobject obj)


{


int k = WinMain(hcur,hpre,cmdline,cmshow);


return;


}


int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)


{


MSG msg;


HACCEL hAccelTable;


sprintf(szWindowClass,"%s","SURYA");


sprintf(szTitle,"%s","SURYA");


MyRegisterClass(hInstance);


if(!InitInstance(hInstance,nCmdShow)){


return 1;


}


while (GetMessage(&msg, NULL, 0, 0))


{


TranslateMessage(&msg);


DispatchMessage(&msg);


}



return 0;


}


The parameters I passed to WinMain(hcur,hpre,cmdline,cmshow)
are declared globally in c++. This worked for me hope it will work for u too.


surya

Re: How to initiate a main method in C++ from Java

Posted By:   Alexander_Krapf  
Posted On:   Wednesday, July 24, 2002 05:56 AM

Iris,


I am not sure that I understand your question correctly. Are you currently calling a Java main() method from your WinMain and you want to put the GUI that the Java main() displays into a JFrame?


Regards,


Alex


P.S.: Feel free to reply to my corporate address (remove dashes from a-l-e-x@c-o-d-e-m-e-s-h.com) or to at least send a duplicate there. I don't think that tons of people will be interested in a very application-specific question.

About | Sitemap | Contact