Download Pelles C here: http://www.pellesc.se
int wmain(int argc, wchar_t *wargv[])
{
// 1. Define the command line in a mutable buffer
wchar_t application[] = L"\\\\?\\c:\\Program Files\\PellesC\\Bin\\cc.exe";
wchar_t commandLine[] = L"/help";
// 2. Initialize the structures
STARTUPINFOW si;
PROCESS_INFORMATION pi;
// Zero out the memory for both structures
SecureZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
SecureZeroMemory(&pi, sizeof(pi));
wprintf(L"Launching PellesC cc compiler driver using CreateProcessW...\n");
// 3. Call CreateProcessW
BOOL success = CreateProcessW
(
application, // Application name
commandLine, // Command line arguments (must be mutable)
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFOW structure
&pi // Pointer to PROCESS_INFORMATION structure
);
// 4. Check for success
if (!success)
{
wprintf(L"CreateProcessW failed. Error code: %lu\n", GetLastError());
return 1;
}
wprintf(L"Process started successfully!\n");
wprintf(L"Process ID (PID): %lu\n", pi.dwProcessId);
// 5. Clean up handles to avoid leaks
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return 0;
}
QuoteThe Unicode version of this function, CreateProcessW, can modify the contents of this string. Therefore, this parameter cannot be a pointer to read-only memory (such as a const variable or a literal string). If this parameter is a constant string, the function may cause an access violation.Maybe other compiler create a buffer automagically for CommandLine?
#include <stdio.h>
#include <stdarg.h>
int VaFunc(int, ...);
char f[] = "Sum = %u\n";
int __cdecl main(void)
{
printf(f, VaFunc(3,5,6,7));
return 0;
}
int VaFunc(int n, ...)
{
int sum = 0;
va_list args;
va_start(args, n);
for (int i = 0; i < n; i++)
sum += va_arg(args, int);
va_end(args);
return sum;
}
.386
.model flat,stdcall
option casemap:none
ExitProcess PROTO :DWORD
printf PROTO C :DWORD,:VARARG
VaFunc PROTO C :DWORD,:VARARG
.data
f db 'Sum = %u',0
.code
start:
invoke VaFunc,3,5,6,7
invoke printf,ADDR f,eax
invoke ExitProcess,0
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
VaFunc PROC C x:DWORD,y:VARARG
xor eax,eax
mov edx,DWORD PTR [esp+4]
@@:
add eax,DWORD PTR [esp+4*edx+4]
dec edx
jnz @b
retn
VaFunc ENDP
OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef
END start.386
.model flat,stdcall
option casemap:none
ExitProcess PROTO :DWORD
printf PROTO C :DWORD,:VARARG
VaFunc PROTO C :DWORD,:VARARG
.data
f db 'Sum = %u',0
.data?
retaddr dd ?
i dd ?
.code
start:
push 7
push 6
push 5
push 3
call VaFunc
invoke printf,ADDR f,eax
invoke ExitProcess,0
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
VaFunc PROC C x:DWORD,y:VARARG
pop retaddr
pop edx
xor eax,eax
@@:
pop ecx
add eax,ecx
inc i
cmp edx,i
jne @b
push retaddr
retn
VaFunc ENDP
OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef
END start
many of us end up there every once in a while....typedef struct { float m[16]; } Mat4;
Mat4 broken(void) {
Mat4 s;
memset(&s, 0, sizeof(s)); // set the block
s.m[0] = 1.0f; // explicit
return s;
}
// Caller:
Mat4 result;
memset(&result, 0xCC, sizeof(result)); // fill with known garbage
result = broken();
/* Expected per C standard: result.m[1] == 0.0f */
/* Observed: result.m[1] == -1.07374e+08 */
/* (the 0xCC garbage — the copy never wrote that slot) */Page created in 0.033 seconds with 15 queries.