Category : OS/2 Files
Archive   : RUNDLL.ZIP
Filename : PROC2.C

 
Output of file : PROC2.C contained in archive : RUNDLL.ZIP
/*
proc2.c

to make procaddr.dll:
cl -Alfu -c -Gs2 -Ox -W2 -DDLL proc2.c
link /nod/noi proc2,procaddr.dll,,llibcdll.lib os2,procaddr.def;
implib procaddr.lib procaddr.def
copy procaddr.dll \os2\dll
*/

#include

#ifdef DLL
int _acrtused = 0;
#endif

#define INCL_DOS
#include "os2.h"

#include "local.h"
#include "proc2.h"

typedef struct {
char *name;
USHORT (APIENTRY *f)();
} DOSCALLS;

/*
include table generated from BSEDOS.H with AWK script DOSCALLS.AWK
table looks like:
LOCAL DOSCALLS NEAR dos[] = {
"", 0,
...
"DosGetHugeShift", DosGetHugeShift,
"DosGetInfoSeg", DosGetInfoSeg,
...
} ;
DOSCALLS.C also contains #define NUM_DOSCALLS
*/
#include "doscalls.c"

LOCAL FN NEAR getdoscall(ASCIIZ name);
LOCAL USHORT NEAR doscalls = 0;

WORD pascal loadmodule(ASCIIZ name)
{
WORD h;
return DosLoadModule((void far *) 0, 0, name, (PHMODULE) &h) ? 0 : h;
}

/*
if name is actually a four-byte ordinal number, use it as is
otherwise if module is not DOSCALLS, use it as is
otherwise if module is DOSCALLS, get ordinal number and use it instead
*/
FN pascal getprocaddr(WORD module, ASCIIZ proc)
{
FN f;

if (! doscalls) doscalls = loadmodule("DOSCALLS");

if ((module == doscalls) && FP_SEG(proc))
return getdoscall(proc);
else
return DosGetProcAddr(module, proc, (PPFN) &f) ? 0 : f;
}

FN pascal procaddr(ASCIIZ module, ASCIIZ proc)
{
return getprocaddr(loadmodule(module), proc);
}

BOOL pascal freemodule(WORD h)
{
return (! DosFreeModule(h));
}

/*
do binary search of table, looking for name, returning function ptr
*/
LOCAL FN NEAR getdoscall(ASCIIZ name)
{
signed cmp, mid;
signed base = 1, top = NUM_DOSCALLS+1;

name = strupr(name);

for (;;)
{
mid = (base + top) / 2;
cmp = strcmp(name, strupr(dos[mid].name));

if (cmp == 0) return (FN) dos[mid].f;
else if (mid == base) return 0;
else if (cmp < 0) top = mid;
else if (cmp > 0) base = mid;
}
}


  3 Responses to “Category : OS/2 Files
Archive   : RUNDLL.ZIP
Filename : PROC2.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/