Неправильно инициализировали
https://msdn.microsoft.com/en-us/library/windows/d...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);
}