OS/2 programming Tips which inclined just for a moment

January June*/Beliefia Productions mailto:jjsuwa@sys3175.com



0. Cautions

  1. This paper is written for the direction which is well versed in programming by the C language, and has experience of OS/2 program creation. I recommend that how to twist interest to programming or the direction which is not received mentally refrains from perusal (smile).
  2. Development environment used by this writing
    • The IBM VisualAge C++ Version3 for OS/2 Japanese version (finishing [ CJC308 application ]) (GUI development environmental omission) (attached toolkit omission)
    • IBM Developer's Toolkit for OS/2 Warp Version4 (GA or CSD4)
    . Although operation is not checked in other development environments, since a description peculiar to development environment thinks that it avoided if possible, if even suitable header/library are prepared, probably it should end with the minimum correction.

1. Partial Collection of Delicate Techniques

It is having made it é┘é± just for a moment.


1.1. Investigate the full path of the execution formal file of a self-process.

Have not I wished to carry out that space to an INI file in the present directory or the same place [ be / then / nothing ] as execution form? éá and what is it? argv[0] Although it is likely to be audible in é└éßé± with sufficient î⌐éΦéß etc. and becomes empty argv[0] Changing with é╠ôαùeé┴é─ processing systems is actual (smile).

#define INCL_BASE#define INCL_ERRORS#define <os2.h> Function */APIRET DosQueryCurrentProcessModuleFullPath which acquires the full path name of the module of the /* present process It returns. : Return value of DosQueryModuleName() (the pointer */ ULONG ulBufferLen /* full path name to the storing place of PCHAR pcBuffer and a /* full path name) Size of a storing place (byte unit) */{ PPIB pxpib; (VOID) DosGetInfoBlocks (PTIB*) (NULL, &pxpib); return DosQueryModuleName (HMODULE) (pxpib->pib_hmte, ulBufferLen, pcBuffer);} 

although there are nothings in é▄éƒ etc. -- very much DosGetInfoBlocks() it does not happen not to think very (smile) Usually, since .exe and the extension are attached to execution form, an INI file and in using being alike, please change an extension into it separately.


1.2. Investigate the CPU number in the SMP environment.

WarpServer Advanced and WSeB -- although YAJI is likely to fly (smile), seemingly, a kernel will become an equivalent for WSeB beyond marine by FixPak13 application for it to be high and for him unable to buy it -- therefore it prepares for it -- é╞éóéñé▒é╞ .

#define INCL_BASE#define INCL_ERRORS#define <os2.h> Function */APIRET DosQueryNumCPUs(pointer */to variable which returns the PULONG pulNumCPUs /* CPU number) { APIRET rc = DosQuerySysInfo which acquires the /* CPU number (26 /* 26:CPU number */ (ULONG) 26) It returns. : Return value of DosQuerySysInfo() (ULONG) /*! ERROR_INVALID_PARAMETER returns in the SMP environment. */ pulNumCPUs, (PVOID) (ULONG) sizeof (ULONG); if (rc == ERROR_INVALID_PARAMETER) { *pulNumCPUs = 1 (ULONG); /*, of course, it is one piece then. */ rc = NO_ERROR; } return rc;} 

Becoming [ an equivalent for WSeB ]-truly kana. Carrying-out [ SMP ] kana. Let's set without expecting not much. It is the insurance of the heart (bitter smile). Although it is the talk which can carry out SMP or is said when the kernel of WSeB FixPak1 is overwritten in rumor at Warp4 which applied FixPak13 anything


1.3. Do not take out strike REJI-related error pop-up and carry out it.

If it does not take out with all processes from the beginning and carries out, it will be to CONFIG.SYS. AUTOFAIL=YES write -- yes, it is -- it is -- although -- it is made not to want to want to take out only a self-process in some cases

#define INCL_BASE#define INCL_ERRORS#define <os2.h> Macroscopic */#define DosEnableErrorPopup(bUsePopup) \ (VOID) DosError which sets up a /* error pop-up display / un-displaying (!= FALSE (BOOL).) Argument : bUsePopup <- it is TRUE when displaying error pop-up. (bUsePopup) It returns. : (VOID) Nothing FERR_ENABLEHARDERR : FERR_DISABLEHARDERR) 

Now, it says good-bye, returns from gloomy error pop-up of that, and comes judge the situation in code.


1.4. Pleasant Device IOCtl

The device IOCtl without an opportunity to use very much. Although it, the more, thinks that it uses and there is worth the more it knows (îâÄäî⌐), since there is also that it can use for the use which end éσéñ does not have in inside, either, let's introduce.

Before it, let's prepare the function for first of all opening a device.

#define INCL_BASE#define INCL_ERRORS#define <os2.h> Function which opens a /* device driver in IOCtl It returns. : Return value of DosOpen() */APIRET DosOpenDevice4IOCtl(pointer */to pointer */ PSZ pszDeviceName /* device file name to variable which returns PHFILE phfDevice and /* file handle) { ULONG ulDosOpenAct ion; return DosOpen(pszDeviceName, phfDevice, &ulDosOpenAction, (ULONG)0, (ULONG)0, OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS, OPEN_SHARE_DENYNONE | OPEN_ACCESS_REA DWRITE | OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NOINHERIT, (PEAOP2)NULL);} Function which opens a /* logic drive It returns. : Return value of DosOpen() */APIRET DosOpenDASD(pointer */ UCHAR ucLogicalDrive /* logic drive character */to variable which returns PHFILE phfDASD and /* file handle) { ULONG ulD osOpenAction; UCHAR-aucFileDASD[4];/* aucFileDASD[0] = ucLogicalDrive; aucFileDASD[1] = (UCHAR)':'; aucFileDASD[2] = (UCHAR)'\0'; aucFileDASD[3] = (UCHAR)'\0'; */ *((PULONG)&aucFileDASD[0]) = ((ULONG)ucLogicalDrive << OPEN_ACCESS_READWRITE 24); PHFDASD, ((ULONG)':' (ULONG)0, DOSOPEN((PSZ)&AUCFILEDASD[0], ((ULONG)'\0' OPEN_ACTION_FAIL_IF_NEW OPEN_ACTION_OPEN_IF_EXISTS, 8) 

Each time DosOpen() Well [ é≡î⌐é─Äv ], DosOpen() a é┴é─ parameter -- many -- elapsing (smile) --


1.4.1. Control of Keyboard Light Emitting Diode

It seems that three Light Emitting Diodes, NumLock, CapsLock, and ScrollLock, are attached to most keyboards. Then, it is éóé└é┴é─é▌é▄é╡éσéñ about this just for a moment.

The file name of a keyboard driver \DEV\KBD$ . It is the first priority. DosOpenDevice4IOCtl() Please come out, open and acquire the file handle.

#define INCL_BASE#define INCL_DOSDEVIOCTL#define INCL_ERRORS#define <os2.h> /* Light Emitting Diode state constant */#define KBDLED_SCROLLLOCK 1 /* Scroll Lock */#define KBDLED_NUMLOCK 2 /* Num Lock */#define KBDLED_CAPSLOCK 4 /* Caps Lock */ Function which sets up a /* keyboard Light Emitting Diode state It returns. : Do Return value */APIRET DosSetKeyboardLEDSt ate (HFILE hfKeyboard and a /* keyboard driver) of sDevIOCtl() [ file handle * / ] ULONG flLEDState A /* Light Emitting Diode state, value which OR(ed) required KBDLED_* */{#pragma pack (1) struct { USHORT usLEDState; } xParameter;#pragma pack() ULONG ulParameter Len = (ULONG)sizeof(xParameter); xParameter.usLEDState = (USHORT)flLEDState; return DosDevIOCtl(hfKeyboard, IOCTL_KEYBOARD, KBD_ALTERKBDLED, (PVOID)&xParameter, (ULONG) ulParameterLen (PULONG)&ulParameterLen, (PVOID)NULL, (ULONG)0, (PULONG)NULL);} 

It seems that it can change even from an ordinary program in fact although it has written that only PM session manager can do to what or the description.


1.4.2. Access Counter Acquisition of IDE Device

There is admiration to which IDE was fixed as a cheap storage device bus now completely. but just recently, as it is, speed comes out, CPU load is low, and é╗éΦéßéá obtains and is also severe a long time ago -- it rubbed and carried out

By the reason (what) for saying, let's grasp the access situation to an IDE storage device. The file name of an IDE driver \DEV\IBMS506$ . Opening first is the same as the point.

#define INCL_BASE#define INCL_DOSDEVIOCTL#define INCL_ERRORS#define <os2.h> Function */APIRET DosQueryIDEAccessCounters which acquires the access counter of a /* IDE driver It returns. : Return value of DosDevIOCtl() (file handle */ ULONG ulUnitNumber of HFILE hfIDE and a /* IDE driver, ) /* IDE equipment number 0 :P /M 1 :P /S 2:S/M 3:S/S ... */ PULONG pulSectorsRead /* The read number of sectors */ PULONG pulSectorsWritten /* The written-in number of sectors */{ APIRET rc;#pragma pack (1) struct { UCHAR ucUnitNumber; } xParameter; struct { USHORT usRevisionNumber; ULONG ulTotalReadOperations; The number of times of /* reading operation */ ULONG ulTotalWriteOperations; The number of times of /* write-in operation */ ULONG ulTotalWriteErrors; The number of times of a /* write-in error */ ULONG ulTotalReadErrors; The number of times of a /* reading error */ ULO NG ulTotalSeekErrors; The number of times of a /* seeking error */ ULONG ulTotalSectorsRead; The number of /* reading sectors */ ULONG ulTotalSectorsWritten; The number of /* write-in sectors */ ULONG ulTotalBMReadOperations; The number of times of /* bus master reading operation */ ULONG ulTotalBMWriteOperations; The number of times of /* bus master write-in operation */ U LONG ulByteMisalignedBuffers; The number of times transmitted by the /* byte boundary gap */ ULONG ulTransfersAcross64K; The number of times transmitted across /* 64K boundary */ ULONG ulReserved [4]; } xData;#pragma pack() ULONG ulParameterLen = sizeof (ULONG) (xParameter), ulDataLen = sizeof (ULONG) (xData); xParameter.ucUnitNumber = (UCHAR)ulUnitNumber; rc = DosDevIOCtl(hfIDE, (ULONG)0x90, (ULONG)0x40, (PVOID)&xParameter, ulParameterLen, &ulParameterLen, (PVOID&xData ul DataLen, &ulDataLen); if(rc == NO_ERROR) { *pulSectorsRead = xData.ulTotalSectorsRead; *pulSectorsWritten = xData.ulTotalSectorsWritten; } return rc;} 

Since information returns [ that it is various and ] to other fields of a data structure object, those interested need to try.


1.4.3. Reboot Suddenly (Ctrl+Alt+Delete Emulation).

Although it does not understand how much demand of rebooting from a program there are, an installer or when making, is it said that it is?

Please open a DOS driver (DOS.SYS) for the time being. File name \DEV\DOS$ .

#define INCL_BASE#define INCL_DOSDEVIOCTL#define INCL_ERRORS#define <os2.h> Function */APIRET DosRebootSystem(file handle */of HFILE hfDOS /* DOS driver) { return DosDevIOCtl which reboots a /* system It returns. : Return value of DosDevIOCtl() (hfDOS, (ULONG) 0xd5, ) (ULONG)0xab, (PVOID)NULL, (ULONG)0, (PULONG)NULL, (PVOID)NULL, (ULONG)0, (PULONG)NULL);} 

the direction which terminated other applications before trying -- saying -- it will be -- probably (smile) --


2. Undocumented OS/2 Programming Information

Although it is investigated [ that it is various and ], and will also become books and will be made [ it is sufficient and ] them if it is Windows, if it is then said whether there is nothing to OS/2, it is perfectly. It says or there are too (bitter smile) few books of the development information on OS/2.


2.1. ANROKKU [ a module in use ]

Although it is too famous for naming it é┐ and Undocumented and is NANI, it is it there.

#define INCL_BASE#define INCL_ERRORS#define <os2.h> API */extern APIRET APIENTRY DosReplaceModule which replaces a module during /* use It returns. : When it fails, it is except NO_ERROR. ( /* pointer */ PSZ pszNewModule to the module file name PSZ pszOldModule and for /* replacement, the module file name replaced newly) Pointer through which it passes */ PSZ pszBackupModule Pointer to the new file name of the module for /* replacement */; 

pszOldModule ANROKKU [ it comes out and / the shown module ] pszBackupModule It renames [ it is alike and ] and continues. pszNewModule The module come out of and shown pszOldModule It is alike and renames. pszNewModule It reaches. pszBackupModule being alike NULL It can é≡ÄwÆΦ. Both NULL Only ANROKKU will be performed, if it is alike and carries out.

The module [ ANROKKU / module ] is read in all the contents, and it remains behind at a memory until a use count is set to 0. Keep in mind that it replaces and a front module is referred to while having remained behind at the memory.

Since import of this API is contained in why or OS2386.LIB in the social position of Undocumented API, it is not necessary to write import declaration to a DEF file.


2.2. Make a window always become a forefront side.

It is é╦éÑ, although there will be nothing and anything will be independently exhibited from primitive ages also by Undocumented, if it is Windows. When it is OS/2, it is /periodically reluctantly. WM_VRNDISABLED When it comes, order raising [ of Z ] direct was carried out and the incorrect evil spirit is formed.

# define WS_TOPMOST 0x00200000L /* It is always the front. */ 

In short, it is a window style. WinCreate[Std]Window() a dialog template resource -- coming out HWND_DESKTOP This is only specified as é╠Äq at the time of frame window ì∞éΘ. WS_TOPMOST The owned window of a frame also comes to a forefront side perfectly.


2.3. Color Selection Control

It is that which comes out when obtaining and editing - color palette, a SUKIMU palette, and é┼ÉF. In fact, since the common definition is carried out, if even a name understands this control class, anyone can use it.

# define WC_COLORSELECT"(PSZ) ColorSelectClass" /* color selection control class name */#define CSLM_NOTIFYRGB 0x0601 The message notified to an owner window when a /* color is changed The RGB value is contained in mp1. */#define CSLM_SETRGB 0x0602 Message sent when setting up a /* color The color set as mp1 is put in with a RGB value. */#if WARP3OREARLIER Since the values of a message differ before [ /* Warp3 ], they are cautions. */#undef CSLM_NOTIFYRGB#define CSLM_NOTIFYRGB 0x130 c#undef CSLM_SETRGB#define CSLM_SETRGB 0x1384#endif 

It is WPCONFIG.DLL, before creating color selection control, since there is nothing in the place which has window procedure at the time of the abbreviation of color selection control when nothing has been carried out, although it wrote that anyone used (it comes out SYS3175). DosLoadModule() Please come out and read. Please release WPCONFIG.DLL after canceling all color selection control similarly.

Keep in mind that the value of a message is different before [ Warp3 ] Warp4 or subsequent ones.


2.4. API Currently Extended Unawares

It seems that some APIs are extended while not knowing whether having passed time very well has influenced, either, after OS/2 is formed into 32 bit.


2.4.1. Dos*EventSem()

Is it API which exchanges a signal between threads? Only the following operation was completed until now.

# define DCE_POSTONE 0x0800 / * single post flag */#define DCE_AUTORESET 0x1000 / * automatic reset flag */ 

It is as follows when this extension is used.

It seems that it can use Warp3 FixPak29 / henceforth [ Warp4 FixPak4 ] according to the data at hand.


2.4.2. Win[Query/Set]SysValue()

It seems that it is various and that the addition is made by PM system value. Is it intelligible if it is called the item in the "user interface" page of a Warp4 "system" object? It cannot use, unless it is after Warp4, of course.

# define SV_FULLWINDOWDRAG 99 /* full window drug * /#define SV_ALTTABSWITCHWIN 100 /* Alt-Tab switch window * /#define SV_VIOMOUSEACTIONS 101 /* VIO mouse action * /#define SV_ASYNCFOCUSCHANGE 102 /* asynchronous focus change */#define SV_FOCUSCHANGESENS 103 /* focus change sensitivity (milli second) */ 

Do I carry out a full window drug and make an asynchronous focus change that Warp3 FixPak17 or subsequent ones is used? Please try someone (smile).


2.4.3. WinDrawBorder()

Although this is API which mainly draws a frame, the contents which can be drawn for a while are added.

# define DB_RAISED 0x0400 /* 3D ô╩ÿg is drawn. */#define DB_DEPRESSED 0x0800 /* 3D ëÜÿg is drawn. */ 

Seemingly, it uses, when drawing it of push button control somehow.


2.5. Set up a window title / icon from a VIO window.

Although I carry out [ mind as someone had appealed for rehabilitation of VIO application ], let's introduce Undocumented API which also puts the meaning which responds to it and can be used from VIO.

#define INCL_BASE#define INCL_PM#define INCL_ERRORS#define <os2.h> API which sets up the window title of a /* VIO window It returns. : When it fails, it is except NO_ERROR. */extern APIRET16 APIENTRY16 WinSetTitle (PSZ pszTitle /* pointer */to the window title character sequence to set up); API which sets up the window title and icon of a /* VIO window It returns. : It is NO_ERR when it fails. Except OR */extern APIRET16 APIENTRY16 WinSetTitleAndIcon (pointer */to the icon file name to PSZ pszTitle and the window title character sequence to /* set up to pointer */ PSZ pszIconPath /* set up); IMPORTS WinSetTitle = PMSHAPI.93IMPORTS WinSetTitleAndIcon = PMSHAPI.97 

Although the title and icon of a PM VIO window can be arbitrarily changed by calling these from VIO application, it turns VIO and, naturally they are 16bit APIs why. Be fully careful of how to call.