Thursday, October 29, 2009

How Can Run an .exe file in java

Example:-
import java.io.*;
class test{
public static void main(String args[]){
try{
String str="C:/Program Files/Adobe/Reader 9.0/Reader/AcroRd32.exe";
Runtime.getRuntime().exec(str);
}
catch(Exception e){
}
}
}





Wednesday, October 28, 2009

How to Hide Console in C++

Example:-
#include 
#include
int main()
{
HWND hWnd
= GetConsoleWindow();
ShowWindow( hWnd, SW_HIDE );

return 0;
}

Tuesday, October 27, 2009

How to convert 'System::String' to 'char*'?

In VC++ 8:

Example:-


using namespace System::Runtime::InteropServices; // for class Marshal

void PrintMessage(System::String^ str)
{
const char* str2 = (char*)(void*)Marshal::StringToHGlobalAnsi(str);
printf(str2);
Marshal::FreeHGlobal((System::IntPtr)(void*)str2);
}

PrintMessage("Method 2");

You receive a System.Threading.ThreadStateException exception when you try to create an instance of a Windows form

Problem:- An unhandled exception of type 'System.Threading.ThreadStateException' occurred in System.Windows.Forms.dll

in microsoft visual c++

Solution:-

Just write '[STAThread]' above the main() function to resolve the problem. This code make your program single-threaded apartment (STA) instead of MTA.


Example:-

[STAThread]
int main(){

Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Application::Run(gcnew UserForm());
return 0;
}