[comp.windows.ms] Show-stopper in wstdio.c/3.0 SDK tty sample app

karl@sugar.hackercorp.com (Karl Lehenbauer) (09/21/90)

The wstdio.c module in the tty sample application has some code that
is a guaranteed GP ever time.

In the initialization routine, stdioInit, the code does a LocalAlloc
to get a handle to some memory to use for registering a class with
windows.  It then CASTS THE HANDLE TO A POINTER AND TRIES TO REFERENCE
FIELDS WITH IT!  Looks like it needs to do a LocalLock on the
handle and use the address returned by LocalLock as a pointer, eh?

I guess just having a WNDCLASS structure created on the stack is no
good unless you know you're going to be large model only since
DS != SS.

By the way, with respect to all the people who are down on large model,
how big are your applications, anyway?  64K of code space doesn't really
go very far for any "real" application, I don't think.


-- 
-- uunet!sugar!karl
-- Usenet access: (713) 438-5018

karl@sugar.hackercorp.com (Karl Lehenbauer) (09/22/90)

In article <6589@sugar.hackercorp.com> karl@sugar.hackercorp.com (Karl Lehenbauer) writes:
>The wstdio.c module in the tty sample application has some code that
>is a guaranteed GP ever time.

OK, mea culpa, mea maxima cupla.  Turns out the problem was that I hadn't
listed the wstdio module that windows calls back when the stdio window is
opened in the .def file.  This was causing a GP when the window opened.
(Yes, guys, large model...)

My new problem with wstdio is that not every line is displayed when output...
some problem involving scrolling.  If you cause the window to refresh by
resizing it slightly or somesuch, everything is in there after the refresh.

-- 
-- uunet!sugar!karl
-- Usenet access: (713) 438-5018

kensy@microsoft.UUCP (Ken SYKES) (09/23/90)

In article <6589@sugar.hackercorp.com> karl@sugar.hackercorp.com (Karl Lehenbauer) writes:
>The wstdio.c module in the tty sample application has some code that
>By the way, with respect to all the people who are down on large model,
>how big are your applications, anyway?  64K of code space doesn't really
>go very far for any "real" application, I don't think.

Using small model doesn't limit you to 64K of code.  The way to get around
the 64K limit is to break the code into segments and prototype all of your
functions that will be called from another segment as FAR.  The -NT switch
will allow you to specify what segment each C module goes into.  It may
sound like a pain but the advantage is everything defaults to near code,
near data, unless you specify otherwise.  I have code that is a few 
hundred K that uses this technique.

Ken Sykes
Disclaimer: The above opinions are solely my own.

poffen@sj.ate.slb.com (Russell Poffenberger) (09/25/90)

In article <6589@sugar.hackercorp.com> karl@sugar.hackercorp.com (Karl Lehenbauer) writes:
>The wstdio.c module in the tty sample application has some code that
>is a guaranteed GP ever time.
>
>In the initialization routine, stdioInit, the code does a LocalAlloc
>to get a handle to some memory to use for registering a class with
>windows.  It then CASTS THE HANDLE TO A POINTER AND TRIES TO REFERENCE
>FIELDS WITH IT!  Looks like it needs to do a LocalLock on the
>handle and use the address returned by LocalLock as a pointer, eh?

If I remember right, this is OK if the LocalAlloc specified LMEM_FIXED as a
flag. This means that the memory can't be moved or discarded by windows so
the handle returned is the same as the pointer to the actual memory allocated.
This is still not recommended however, especially for GlobalAlloc.

>
>I guess just having a WNDCLASS structure created on the stack is no
>good unless you know you're going to be large model only since
>DS != SS.
>
>By the way, with respect to all the people who are down on large model,
>how big are your applications, anyway?  64K of code space doesn't really
>go very far for any "real" application, I don't think.

Use the medium model, then you aren't limited to 64K, except for any single
module. If you split up your source into several modules, then you can get
multiple code segments. (Don't forget that routines are now FAR.


Russ Poffenberger               DOMAIN: poffen@sj.ate.slb.com
Schlumberger Technologies       UUCP:   {uunet,decwrl,amdahl}!sjsca4!poffen
1601 Technology Drive		CIS:	72401,276
San Jose, Ca. 95110             (408)437-5254

risto@tuura.UUCP (Risto Lankinen) (09/25/90)

poffen@sj.ate.slb.com (Russell Poffenberger) writes:

>In article <6589@sugar.hackercorp.com> karl@sugar.hackercorp.com (Karl Lehenbauer) writes:
>>The wstdio.c module in the tty sample application has some code that
>>is a guaranteed GP ever time.
>>
>>I guess just having a WNDCLASS structure created on the stack is no
>>good unless you know you're going to be large model only since
>>DS != SS.
>>

Hi!

It is possible to do a function, say, RegWinClassDirect(), which takes all
the members of WNDCLASS structure as parameters in the *opposite* order.
Make it in .ASM into a DLL and call the RegisterWindowClass() with the far
ptr parameter SS:BP+06 (which points to the 'structure' of WNDCLASS members
pushed to stack for RegWinClassDirect() ).  I've done it, and it hasn't
failed so far even without LockData() (*) .  And I think it even will not,
since RegisterWindowClass() is supposed not to call any functions such that
would trigger memory movement.  The only importance as far as I see is that
the correct (segment register of the) far pointer is passed.

Terveisin: Risto Lankinen

(*) footnote: For memory models, where DS==SS, I take for granted that the
LockData() also locks the value of SS , but how is the matter for DLL's for
example?
-- 
Risto Lankinen / product specialist ***************************************
Nokia Data Systems, Technology Dept *  2                              2   *
THIS SPACE INTENTIONALLY LEFT BLANK * 2 -1 is PRIME!  Now working on 2 +1 *
replies: risto@yj.data.nokia.fi     ***************************************