Combining 16 bit and 32 bit 
Author Message
 Combining 16 bit and 32 bit

This may be a stupid question, but can you combine 16 and 32 bit code in the
same program?  Or call 32 bit DLL's from a 16 bit program?  Let me explain
why I want to do this:

I want to create a program that can read a file, parse it, and set
environment variables based on the contents of the file.  OK under DOS, no
problem (well, slight problem, tracing PSP's, using undocumented calls,
etc.).  However, I want the same program to work under NT.  I can do this
for NT only via the win32 API, and this means I have to have two copies of
the utility around and do some test to decide which one to run.  (util.exe,
util32.exe)

To summarize, I would like to create a single, self contained exe program
that will modify the environment in DOS or NT.

Can this be done (i know it won't be easy, since every compiler I've seen
does only one or the other, and I might need some ASM or something to glue
the two pieces together)

Or more generally is it possible to create utils that "autodetect" DOS/NT
and utilize appropriate code, so that command line utilities that I create
will work regardless of MS OS being used....

I understand that programmatically setting the environment is very different
in NT than in DOS.



Fri, 15 Dec 2000 03:00:00 GMT  
 Combining 16 bit and 32 bit

The PB/DLL product from powerbasic (http://www.powerbasic.com/) allows you
to compile DLLs and EXEs that can be used in 16-bit and 32-bit
environments.
--
To reply to me via e-mail, remove all occurances of the word "dot" from my
reply address.



Quote:
> This may be a stupid question, but can you combine 16 and 32 bit code in
the
> same program?  Or call 32 bit DLL's from a 16 bit program?  Let me

explain
<snip>


Fri, 15 Dec 2000 03:00:00 GMT  
 Combining 16 bit and 32 bit



Quote:
> This may be a stupid question, but can you combine 16 and 32 bit code in
the
> same program?  Or call 32 bit DLL's from a 16 bit program? >

   There are DLLs available that allow you to Call 32 bit DLLs from a 16bit
program.

This is called THUNKing - I have no idea where that name came from!!!!

There is a FreeWare DLL to do this on my site (not written by me)

http:\\users.orac.net.au\~brosco

Go to the "Windows API Goodies" page.



Sat, 16 Dec 2000 03:00:00 GMT  
 Combining 16 bit and 32 bit

Quote:



>> This may be a stupid question, but can you combine 16 and 32 bit code in
>the
>> same program?  Or call 32 bit DLL's from a 16 bit program? >

>   There are DLLs available that allow you to Call 32 bit DLLs from a 16bit
>program.

>This is called THUNKing - I have no idea where that name came from!!!!

>There is a FreeWare DLL to do this on my site (not written by me)

>http:\\users.orac.net.au\~brosco

>Go to the "Windows API Goodies" page.

Thanks for the info, and I will get the .dll, but is it possible to use a
DLL from a DOS program?


Sat, 16 Dec 2000 03:00:00 GMT  
 Combining 16 bit and 32 bit


says...

Quote:
> Thanks for the info, and I will get the .dll, but is it possible to use a
> DLL from a DOS program?

No.  Not directly anyway.  The PowerBASIC Developer Kit for Windows allows DOS
programs to call 16-bit DLLs when they are running inside of Windows 3.1, 95
or 98 (doesn't work in Windows NT).

--Dave



Sat, 16 Dec 2000 03:00:00 GMT  
 Combining 16 bit and 32 bit

Quote:


>says...
>> Thanks for the info, and I will get the .dll, but is it possible to use a
>> DLL from a DOS program?

>No.  Not directly anyway.  The PowerBASIC Developer Kit for Windows allows
DOS
>programs to call 16-bit DLLs when they are running inside of Windows 3.1,
95
>or 98 (doesn't work in Windows NT).

>--Dave

I appreciate all the feedback I've been getting but I guess I didn't state
my question clearly enough.  This is what I would like to do:

Create one(1) standalone, commandline executable that will modify the
environment, regardless of the MS Operating system involved.  (DOS, 95/98,
NT)  In the case of 95/98 and NT it doesn't have to modify it permanently,
just within the current DOS box.  For NT I can modify it via calls to the
WIN32API (using PB/CC for excample).   In DOS I can find the MCB or trace
PSP's to modify the master environment.  In 95/98 I might be able to use
either method, not sure yet.  However, I want to use one (1) stand alone
utility to do this.

Why do I want to do this?  Theoretical curiousity mostly, but it would have
application at some of the clients that I work for that have mixed
environments.

Anyway, can this be done?  The app would have to be a DOS app, just to be
able to run in all environments.



Sat, 16 Dec 2000 03:00:00 GMT  
 Combining 16 bit and 32 bit


says...

Quote:

> Create one(1) standalone, commandline executable that will modify the
> environment, regardless of the MS Operating system involved.  (DOS, 95/98,
> NT)  In the case of 95/98 and NT it doesn't have to modify it permanently,
> just within the current DOS box.  For NT I can modify it via calls to the
> WIN32API (using PB/CC for excample).   In DOS I can find the MCB or trace
> PSP's to modify the master environment.  In 95/98 I might be able to use
> either method, not sure yet.  However, I want to use one (1) stand alone
> utility to do this.

> Why do I want to do this?  Theoretical curiousity mostly, but it would have
> application at some of the clients that I work for that have mixed
> environments.

> Anyway, can this be done?  The app would have to be a DOS app, just to be
> able to run in all environments.

16-bit Windows applications can have a "DOS stub" program embedded in them.  
For example, if you restart your computer in MS-DOS mode (no Windows) and you
try to run NOTEPAD.EXE you will get a message that tells you the program can
only be run inside of Windows.

How can a Windows program give you that message? It can't actually.  A 16-bit
Windows application actually consists of two parts.  The first part is a
normal DOS program with the normal DOS header.  The second part is the actual
Windows program.  When Windows launches a program it skips the DOS header and
looks for the Windows header information.  If it doesn't see it, it runs the
program as a DOS app.

Now, as I mentioned above, the normal DOS program at the beginning of every
Windows program is a simple "Hello, World!" kinda deal where it simply prints
a "You gotta have Windows" type of message.  But, you can replace this "DOS
stub" with your own program (as long as it isn't larger than 60k).  So, when
you program is executed in a DOS environment the DOS program runs, but when
it's executed in Windows, the Windows program runs.

32-bit Windows applications also have this DOS stub, but unlike 16-bit Windows
programs, you can't replace the stub.  The size of the DOS stub is crucial and
there are hundreds of pointers in the Win32 executable header which depend on
the exact size of the DOS stub so that data in the executable can be quickly
found (that's a whole 'nother story).

So, as long as you write your program as a 16-bit application only (no Win32
access except by thunking), you can create a dual mode executable.

--Dave



Sun, 17 Dec 2000 03:00:00 GMT  
 Combining 16 bit and 32 bit

Dave,  Thanks.  This is just the type of information I was looking for!

I really appreciate it.

Now, off to learn how to thunk.....

Mark

Quote:


>says...

>> Create one(1) standalone, commandline executable that will modify the
>> environment, regardless of the MS Operating system involved.  (DOS,
95/98,
>> NT)  In the case of 95/98 and NT it doesn't have to modify it
permanently,
>> just within the current DOS box.  For NT I can modify it via calls to the
>> WIN32API (using PB/CC for excample).   In DOS I can find the MCB or trace
>> PSP's to modify the master environment.  In 95/98 I might be able to use
>> either method, not sure yet.  However, I want to use one (1) stand alone
>> utility to do this.

>> Why do I want to do this?  Theoretical curiousity mostly, but it would
have
>> application at some of the clients that I work for that have mixed
>> environments.

>> Anyway, can this be done?  The app would have to be a DOS app, just to be
>> able to run in all environments.

>16-bit Windows applications can have a "DOS stub" program embedded in them.
>For example, if you restart your computer in MS-DOS mode (no Windows) and
you
>try to run NOTEPAD.EXE you will get a message that tells you the program
can
>only be run inside of Windows.

>How can a Windows program give you that message? It can't actually.  A
16-bit
>Windows application actually consists of two parts.  The first part is a
>normal DOS program with the normal DOS header.  The second part is the
actual
>Windows program.  When Windows launches a program it skips the DOS header
and
>looks for the Windows header information.  If it doesn't see it, it runs
the
>program as a DOS app.

>Now, as I mentioned above, the normal DOS program at the beginning of every
>Windows program is a simple "Hello, World!" kinda deal where it simply
prints
>a "You gotta have Windows" type of message.  But, you can replace this "DOS
>stub" with your own program (as long as it isn't larger than 60k).  So,
when
>you program is executed in a DOS environment the DOS program runs, but when
>it's executed in Windows, the Windows program runs.

>32-bit Windows applications also have this DOS stub, but unlike 16-bit
Windows
>programs, you can't replace the stub.  The size of the DOS stub is crucial
and
>there are hundreds of pointers in the Win32 executable header which depend
on
>the exact size of the DOS stub so that data in the executable can be
quickly
>found (that's a whole 'nother story).

>So, as long as you write your program as a 16-bit application only (no
Win32
>access except by thunking), you can create a dual mode executable.

>--Dave



Mon, 18 Dec 2000 03:00:00 GMT  
 Combining 16 bit and 32 bit

Dave, one more question, then I'll go away (for a short while, at least ;-)

PowerBasic's PBDK 2.5 gives DOS programs the capability to call 16 bit
Windows DLL's, right?

And there are DLL's to do thunking between 16 bit and 32 bit, right?

So........., theoretically if purchased PBDK (I have PB3.5) I could do what
you've described below, right?

Quote:


>says...

>16-bit Windows applications can have a "DOS stub" program embedded in them.
>For example, if you restart your computer in MS-DOS mode (no Windows) and
you
>try to run NOTEPAD.EXE you will get a message that tells you the program
can
>only be run inside of Windows.

>How can a Windows program give you that message? It can't actually.  A
16-bit
>Windows application actually consists of two parts.  The first part is a
>normal DOS program with the normal DOS header.  The second part is the
actual
>Windows program.  When Windows launches a program it skips the DOS header
and
>looks for the Windows header information.  If it doesn't see it, it runs
the
>program as a DOS app.

>Now, as I mentioned above, the normal DOS program at the beginning of every
>Windows program is a simple "Hello, World!" kinda deal where it simply
prints
>a "You gotta have Windows" type of message.  But, you can replace this "DOS
>stub" with your own program (as long as it isn't larger than 60k).  So,
when
>you program is executed in a DOS environment the DOS program runs, but when
>it's executed in Windows, the Windows program runs.

>32-bit Windows applications also have this DOS stub, but unlike 16-bit
Windows
>programs, you can't replace the stub.  The size of the DOS stub is crucial
and
>there are hundreds of pointers in the Win32 executable header which depend
on
>the exact size of the DOS stub so that data in the executable can be
quickly
>found (that's a whole 'nother story).

>So, as long as you write your program as a 16-bit application only (no
Win32
>access except by thunking), you can create a dual mode executable.

>--Dave



Mon, 18 Dec 2000 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. 8-bit, 16-bit & 32-bit Colour

2. VB 4.0 (16-Bit)/Crystal Reports 3.0.1.32 (16-Bit) Print Preview Maximize Window

3. corruption of 16 bit db when used by both 16 and 32 bit apps

4. API Conversion 16 bit to 32 bit

5. Help..-NT 4.0-ISA access with 16 Bit GFA and 32 Bit DLL

6. 32-Bit to 16-Bit

7. VB 4.0 16 bit or 32 bit Escape Key

8. Passthrough queries fail in 16-bit VB4, succeed in 32-bit

9. 16 bit/32 bit

10. 32-Bit to 16-Bit

11. VB 16 bit vs 32 bit on NT machine

 

 
Powered by phpBB® Forum Software