How do I use fileio without calling the allocConsole proc?

Started by gurangax, December 19, 2007, 09:48:52 AM

Previous topic - Next topic

gurangax

Help. I built a windows program using HLA and used the fileio. but it will fail if I do not call the allocConsole. Can someone tell me how to use fileio without using the console? or is there a way for me to integrate the console into my window or hide it. because it keeps poping out and thats not nice. Another thing is how do I convert windows unicode to HLA string? because I can not put the windows unicode string into HLA string.

Thanks for your help.

Evenbit

Use the WideCharToMultiByte() API function to convert from Unicode to a standard string, then convert this to an HLA string.

Nathan.

Evenbit

Quote from: gurangax on December 19, 2007, 09:48:52 AM
Help. I built a windows program using HLA and used the fileio. but it will fail if I do not call the allocConsole. Can someone tell me how to use fileio without using the console? or is there a way for me to integrate the console into my window or hide it. because it keeps poping out and thats not nice.

Nonsense!  "fileio" works just fine without any need to use the allocConsole API.  Just take a look at some of the downloadable example code available on Webster and at the 'aoaprogramming' Yahoo group.  You can use the "-w" switch while compliling to tell the linker to create a PE file that doesn't init a console at start-up.

QuoteAnother thing is how do I convert windows unicode to HLA string? because I can not put the windows unicode string into HLA string.

Here is a quick example of String -> Unicode -> String -> HLA String conversion:

program unicode;
#include("stdlib.hhf")
#include("w.hhf")

static
first :string := "Hello World!";

var
second :byte[128];
wide :byte[128];
slen :dword;
wlen :dword;
HLAbuf :byte[128];
HLAstr :string;

begin unicode;

// this first call is only to determine the lengths
w.MultiByteToWideChar( 0, 0, first, -1, null, 0 );

mov( eax, slen ); // ANSI length
shl( 1, eax );
mov( eax, wlen ); // Unicode length

// now we convert to Unicode
w.MultiByteToWideChar( 0, 0, first, -1, wide[0], wlen );

// now we convert back to ANSI
w.WideCharToMultiByte( 0, 0, wide[0], -1, second[0], slen, null, null );

// now convert to an HLA-style string
str.init( HLAbuf[0], 128 );
mov( eax, HLAstr );
mov( eax, edx );
lea( ebx, second[0] );
for ( mov( 0, ecx ); ecx < slen; add( 1, ecx ) ) do
mov( [ebx+ecx], al );
mov( al, [edx+ecx] );
endfor;
mov( slen, eax );
mov( HLAstr, esi );
mov( eax, (type str.strRec [esi]).length );

stdout.puts( HLAstr );

end unicode;


Nathan.

gurangax

Thanks for your help. My fault. It was a memory addressing problem which caused fileio.write to fail in windows without calling allocConsole. But if I called allocConsole there was no problem. Now I've fixed the problem (no more console). Thanks a lot.