<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Thanks, Eliot!</div><div><br></div><div><div>On Aug 17, 2012, at 15:21 , Eliot Miranda wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi DOug,<br><br><div class="gmail_quote">On Fri, Aug 17, 2012 at 1:57 PM, Douglas McPherson <span dir="ltr"><<a href="mailto:djm1329@san.rr.com" target="_blank">djm1329@san.rr.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'm using FFI to call an external C function which performs a printf. On the Mac such output conveniently displays in Console.app. Anyone know how I can see these printfs on Windows ? I tried starting the image with Cog's CroquetConsole.exe but nothing gets displayed in the console. Ideas?<br>
<br>
Thanks,<br>
Doug<br>
</blockquote></div><br>phhh... mingw :(. The VM can write to stdout, but does so not using printf. here's how it works, all code in platforms/win32/plugins/FilePlugin/sqWin32FilePrims.c.<div><br></div><div>When the CVM is asked for the stdin/out/err handles it does this for each handle:</div>
<div><br></div><div> DWORD mode;</div><div>...</div><div><div> files[0].sessionID = thisSession;</div><div> files[0].file = GetStdHandle(STD_INPUT_HANDLE); // & STD_OUTPUT_HANDLE & 1 & STD_ERROR_HANDLE & 2</div>
<div> files[0].fileSize = 0;</div><div> files[0].writable = false;</div><div> files[0].lastOp = 0; /* unused on win32 */</div><div> files[0].isStdioStream = GetConsoleMode(files[0].file, &mode) != 0;</div>
<div><br></div><div>i.e. isStdioStream == GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &mode) != 0;</div><div><br></div><div>Then when it wants to write it does</div><div><br></div><div><div> if (f->isStdioStream)</div>
<div> WriteConsole(FILE_HANDLE(f), (LPVOID) (byteArrayIndex + startIndex), count, &dwReallyWritten, NULL);</div><div> else</div><div> WriteFile(FILE_HANDLE(f), (LPVOID) (byteArrayIndex + startIndex), count, &dwReallyWritten, NULL);</div>
</div><div><br></div><div>and to read it does</div><div><br></div><div><div> if (f->isStdioStream)</div><div> ReadConsole(FILE_HANDLE(f), (LPVOID) (byteArrayIndex+startIndex), count,</div><div> &dwReallyRead, NULL);</div>
<div> else</div><div> ReadFile(FILE_HANDLE(f), (LPVOID) (byteArrayIndex+startIndex), count,</div><div> &dwReallyRead, NULL);</div></div><div><br></div><div>Now this doesn't really help you with printf, but if you can link your external C code you can redefine printf to invoke the above writing code. Hence adapted from platforms/win32/vm/sqWin32Intel.c, do something like:</div>
<div><br></div><div><div>int __cdecl</div><div>printf(const char *fmt, ...)</div><div>{ va_list al;</div><div> int result;</div><div><br></div><div> va_start(al, fmt);</div><div> wvsprintf(consoleBuffer, fmt, al);</div>
<div><br></div><div>// and then adapt the above to write to the console:</div><div><div> if (f->isStdioStream)</div><div> WriteConsole(FILE_HANDLE(f), consoleBuffer, strlen(consoleBuffer), &dwReallyWritten, NULL);</div>
<div> else</div><div><span class="Apple-style-span"> WriteFile(FILE_HANDLE(f), </span>consoleBuffer, strlen(consoleBuffer)<span class="Apple-style-span">, &dwReallyWritten, NULL);</span></div></div><div><span class="Apple-style-span"><br>
</span></div><div> result = vfprintf(stdout, fmt, al);</div><div> va_end(al);</div><div> return result;</div><div>}</div></div><div><br></div>-- <br>HTH,<div>Eliot</div><br>
</div>
<br></blockquote></div><br></body></html>