<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">&lt;<a href="mailto:djm1329@san.rr.com" target="_blank">djm1329@san.rr.com</a>&gt;</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 :(. &nbsp;The VM can write to stdout, but does so not using printf. &nbsp;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>&nbsp; &nbsp;&nbsp;DWORD mode;</div><div>...</div><div><div>&nbsp; &nbsp; files[0].sessionID = thisSession;</div><div>&nbsp; &nbsp; files[0].file = GetStdHandle(STD_INPUT_HANDLE); // &amp;&nbsp;STD_OUTPUT_HANDLE &amp; 1 &amp;&nbsp;STD_ERROR_HANDLE &amp; 2</div>
<div>&nbsp; &nbsp; files[0].fileSize = 0;</div><div>&nbsp; &nbsp; files[0].writable = false;</div><div>&nbsp; &nbsp; files[0].lastOp = 0; /* unused on win32 */</div><div>&nbsp; &nbsp; files[0].isStdioStream = GetConsoleMode(files[0].file, &amp;mode) != 0;</div>
<div><br></div><div>i.e. isStdioStream ==&nbsp;GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &amp;mode) != 0;</div><div><br></div><div>Then when it wants to write it does</div><div><br></div><div><div>&nbsp; if (f-&gt;isStdioStream)</div>
<div>&nbsp; &nbsp; WriteConsole(FILE_HANDLE(f), (LPVOID) (byteArrayIndex + startIndex), count, &amp;dwReallyWritten, NULL);</div><div>&nbsp; else</div><div>&nbsp; &nbsp; WriteFile(FILE_HANDLE(f), (LPVOID) (byteArrayIndex + startIndex), count, &amp;dwReallyWritten, NULL);</div>
</div><div><br></div><div>and to read it does</div><div><br></div><div><div>&nbsp; if (f-&gt;isStdioStream)</div><div>&nbsp; &nbsp; ReadConsole(FILE_HANDLE(f), (LPVOID) (byteArrayIndex+startIndex), count,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp;dwReallyRead, NULL);</div>
<div>&nbsp; else</div><div>&nbsp; &nbsp; ReadFile(FILE_HANDLE(f), (LPVOID) (byteArrayIndex+startIndex), count,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&amp;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. &nbsp;Hence adapted from&nbsp;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>&nbsp; int result;</div><div><br></div><div>&nbsp; va_start(al, fmt);</div><div>&nbsp; wvsprintf(consoleBuffer, fmt, al);</div>
<div><br></div><div>// and then adapt the above to write to the console:</div><div><div>&nbsp; if (f-&gt;isStdioStream)</div><div>&nbsp; &nbsp; WriteConsole(FILE_HANDLE(f), consoleBuffer, strlen(consoleBuffer), &amp;dwReallyWritten, NULL);</div>
<div>&nbsp; else</div><div><span class="Apple-style-span">&nbsp; &nbsp; WriteFile(FILE_HANDLE(f),&nbsp;</span>consoleBuffer, strlen(consoleBuffer)<span class="Apple-style-span">, &amp;dwReallyWritten, NULL);</span></div></div><div><span class="Apple-style-span"><br>
</span></div><div>&nbsp; result = vfprintf(stdout, fmt, al);</div><div>&nbsp; va_end(al);</div><div>&nbsp; return result;</div><div>}</div></div><div><br></div>-- <br>HTH,<div>Eliot</div><br>
</div>
<br></blockquote></div><br></body></html>