#include "stdafx.h"
#include <Windows.h>
#include <conio.h>
extern "C" __declspec(dllexport) int CallNewProccess() {
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
if (!CreateProcess(NULL, const_cast<WCHAR*>(L"cmd"), NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) {
return 0;
}
else
return 1;
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
class WinApiClass
{
[DllImport("DLL4.dll")]
public static extern int CallNewProccess();
}
namespace ConsoleApp50
{
class Program
{
static void Main(string[] args)
{
try
{
int flag = WinApiClass.CallNewProccess();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey(true);
}
}
}
extern "C" __declspec(dllexport) int* CallNewProccess()
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
if(!CreateProcess(NULL, const_cast<WCHAR*>(L"cmd"), NULL, NULL,
FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi))
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return 0;
}
return pi.hProcess;
}
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
class WinApiClass
{
[DllImport("DLL4.dll")]
[DllImport("kernel32.dll", SetLastError=true)]
static extern bool CloseHandle(IntPtr hObject);
public static extern IntPtr CallNewProccess();
}
static void Main(string[] args)
{
IntPtr hndl = 0;
try
{
hndl = WinApiClass.CallNewProccess();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
if( hndl != 0 )
{
CloseHandle(hndl);
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey(true);
}
STARTUPINFO