Skip to content

Instantly share code, notes, and snippets.

@vtjnash
Forked from ihnorton/testcp.cxx
Last active August 29, 2015 14:02
Show Gist options
  • Save vtjnash/bfbdfe55915557f0d691 to your computer and use it in GitHub Desktop.
Save vtjnash/bfbdfe55915557f0d691 to your computer and use it in GitHub Desktop.
// envtest.cpp : Defines the entry point for the console application.
//
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
int _tmain()
{
printf("openblas: 0x%016lx %d\n", LoadLibraryExW(L"libopenblas.dll", NULL, LOAD_WITH_ALTERED_SEARCH_PATH), GetLastError());
LPTSTR lpszVariable;
LPTCH lpvEnv;
// Get a pointer to the environment block.
lpvEnv = GetEnvironmentStrings();
// If the returned pointer is NULL, exit.
if (lpvEnv == NULL)
{
printf("GetEnvironmentStrings failed (%d)\n", GetLastError());
return 0;
}
// Variable strings are separated by NULL byte, and the block is
// terminated by a NULL byte.
lpszVariable = (LPTSTR) lpvEnv;
while (*lpszVariable)
{
_tprintf(TEXT("%s\n"), lpszVariable);
lpszVariable += lstrlen(lpszVariable) + 1;
}
FreeEnvironmentStrings(lpvEnv);
_tprintf(TEXT("\n\n\n"));
/////////////////////////////////////////////////
STARTUPINFOW si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
DWORD dwFlags = CREATE_UNICODE_ENVIRONMENT;
WCHAR cmd[] = L"ping www.github.com";
// Start the child process.
if( !CreateProcessW( NULL, // No module name (use command line)
cmd, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
dwFlags, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return 0;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment