[2] | 1 | /*
|
---|
[104] | 2 | * Copyright (c) Chris Wohlgemuth 2002
|
---|
[2] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * http://www.geocities.com/SiliconValley/Sector/5785/
|
---|
| 6 | * http://www.os2world.com/cdwriting
|
---|
| 7 | *
|
---|
| 8 | * Redistribution and use in source and binary forms, with or without
|
---|
| 9 | * modification, are permitted provided that the following conditions
|
---|
| 10 | * are met:
|
---|
| 11 | * 1. Redistributions of source code must retain the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer.
|
---|
| 13 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
| 14 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 15 | * documentation and/or other materials provided with the distribution.
|
---|
| 16 | * 3. The authors name may not be used to endorse or promote products
|
---|
| 17 | * derived from this software without specific prior written permission.
|
---|
| 18 | *
|
---|
| 19 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
|
---|
| 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
| 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
| 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
---|
| 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
| 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
| 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
| 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
| 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
| 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
| 29 | * SUCH DAMAGE.
|
---|
| 30 | *
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | /************************************************************************/
|
---|
| 34 | /* Put all #defines here */
|
---|
| 35 | /************************************************************************/
|
---|
| 36 |
|
---|
[104] | 37 | #define INCL_32 /* force 32 bit compile */
|
---|
[2] | 38 | #define INCL_GPIBITMAPS
|
---|
| 39 | #define INCL_DOSFILEMGR
|
---|
| 40 | #define INCL_DOSRESOURCES
|
---|
| 41 | #define INCL_DOSMODULEMGR
|
---|
| 42 | #define INCL_WIN
|
---|
| 43 | #define INCL_GPI
|
---|
[104] | 44 | #define INCL_PM
|
---|
[2] | 45 |
|
---|
| 46 | /************************************************************************/
|
---|
| 47 | /* Put all #includes here */
|
---|
| 48 | /************************************************************************/
|
---|
| 49 |
|
---|
| 50 | #include <limits.h>
|
---|
| 51 | #include <os2.h>
|
---|
| 52 | #include <string.h>
|
---|
| 53 | #include <stdlib.h>
|
---|
| 54 | #include <os2medef.h>
|
---|
| 55 | #include <mmioos2.h>
|
---|
| 56 | #include "jpgproc.h"
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | /*************************************************************************************
|
---|
| 61 | * Routine is called on each DLL instantiation and termination.
|
---|
| 62 | * Caller assures that no two instances execute this code
|
---|
| 63 | * at the same time.
|
---|
| 64 | *************************************************************************************/
|
---|
| 65 | /*************************************************************************************
|
---|
| 66 | * Variable holds DLL module handle. Gets set at initialization.
|
---|
| 67 | * Data area is separate for each using process, so this value
|
---|
| 68 | * could be different (or same) per process.
|
---|
| 69 | *************************************************************************************/
|
---|
| 70 | HMODULE hModuleHandle;
|
---|
| 71 |
|
---|
[104] | 72 |
|
---|
| 73 | ULONG APIENTRY _DLL_InitTerm(ULONG modhandle,ULONG flag);
|
---|
| 74 | int _CRT_init(void);
|
---|
| 75 | void _CRT_term(void);
|
---|
| 76 |
|
---|
| 77 | ULONG APIENTRY _DLL_InitTerm (ULONG hModHandle, ULONG fTerm)
|
---|
[2] | 78 | {
|
---|
| 79 | hModuleHandle = hModHandle; /* Remember for NLS lookup */
|
---|
| 80 | if (!fTerm) {
|
---|
| 81 | if (_CRT_init())
|
---|
| 82 | return (0L);
|
---|
| 83 | } /* endif */
|
---|
[104] | 84 | else {
|
---|
| 85 | _CRT_term();
|
---|
| 86 | }
|
---|
[2] | 87 |
|
---|
| 88 | return (1L); /* Success */
|
---|
| 89 | } /* DLL_InitTerm */
|
---|
| 90 |
|
---|
| 91 |
|
---|
| 92 | /**************************************************************************
|
---|
| 93 | * GetFormatString **
|
---|
| 94 | **************************************************************************
|
---|
| 95 | *
|
---|
| 96 | * ARGUMENTS:
|
---|
| 97 | *
|
---|
| 98 | * lSearchId - Table search key
|
---|
| 99 | * pszFormatString - Address where to return string.
|
---|
| 100 | * If null, then string is not returned.
|
---|
| 101 | * lBytes - Number of bytes to copy.
|
---|
| 102 | *
|
---|
| 103 | * RETURN:
|
---|
| 104 | *
|
---|
| 105 | * Returns 0 if string not found, or the number of characters (bytes)
|
---|
| 106 | * copied to the callers buffer.
|
---|
| 107 | * Note, returned string is not ASCII nul terminated
|
---|
| 108 | *
|
---|
| 109 | * DESCRIPTION:
|
---|
| 110 | *
|
---|
| 111 | * This function will retrieve the format string for the specified
|
---|
| 112 | * IOProc from the resource file that contains the strings.
|
---|
| 113 | *
|
---|
| 114 | ***************************************************************************/
|
---|
| 115 | LONG GetFormatString (LONG lSearchId,
|
---|
| 116 | PSZ pszFormatString, /* Null, or dest address */
|
---|
| 117 | LONG lBytes) /* Caller provided maximum */
|
---|
| 118 | {
|
---|
| 119 | PVOID pResourceData;
|
---|
| 120 | CHAR *pTemp;
|
---|
| 121 | LONG lStringLen; /* Length of format string */
|
---|
| 122 | LONG lRetVal = 0; /* Function return value */
|
---|
| 123 | LONG lSearchTemp;
|
---|
| 124 |
|
---|
| 125 | if (DosGetResource(hModuleHandle,
|
---|
| 126 | RT_RCDATA,
|
---|
| 127 | MMOTION_IOPROC_NAME_TABLE,
|
---|
| 128 | &pResourceData))
|
---|
| 129 | {
|
---|
| 130 | return (MMIO_ERROR);
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | /*
|
---|
| 134 | * The resource table is of the form : FOURCC String\0
|
---|
| 135 | * Loop until a match is found, then return the string.
|
---|
| 136 | * Copy up to the number of bytes specified.
|
---|
| 137 | */
|
---|
| 138 |
|
---|
| 139 | lStringLen = 0;
|
---|
| 140 | pTemp = (CHAR *)pResourceData;
|
---|
| 141 |
|
---|
| 142 | while (pTemp)
|
---|
| 143 | {
|
---|
| 144 | memmove(&lSearchTemp, pTemp, sizeof(LONG));
|
---|
| 145 |
|
---|
| 146 | if (lSearchTemp == 0L)
|
---|
| 147 | {
|
---|
| 148 | break; /* End of table, search item not found */
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | if (lSearchTemp == lSearchId) /* Search item found? */
|
---|
| 152 | {
|
---|
| 153 | pTemp += sizeof(LONG); /* Bypass numeric search id */
|
---|
| 154 | lStringLen = strlen(pTemp); /* Determine length of found string */
|
---|
| 155 | if (lStringLen >= lBytes) /* Truncate, if necessary */
|
---|
| 156 | {
|
---|
| 157 | if (lBytes > 0)
|
---|
| 158 | lStringLen = lBytes; /* Number of characters to return */
|
---|
| 159 | else
|
---|
| 160 | {
|
---|
| 161 | /* Callers buffer has zero size. Cannot return any data */
|
---|
| 162 | lRetVal = 0; /* Size of returned data */
|
---|
| 163 | break; /* Done searching */
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 | if (pszFormatString != NULL)
|
---|
| 167 | {
|
---|
| 168 | memcpy(pszFormatString, pTemp, lStringLen); /* Copy string to caller */
|
---|
| 169 | }
|
---|
| 170 | lRetVal = lStringLen; /* Function return value */
|
---|
| 171 | break; /* We're done searching */
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | pTemp += sizeof(FOURCC);
|
---|
| 175 | pTemp += (strlen(pTemp) + 1); /* Advance to next search key */
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | DosFreeResource( pResourceData );
|
---|
| 179 |
|
---|
| 180 | return (lRetVal); /* Zero or strlen */
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 |
|
---|
| 184 | /**************************************************************************
|
---|
| 185 | * GetFormatStringLength **
|
---|
| 186 | **************************************************************************
|
---|
| 187 | *
|
---|
| 188 | * ARGUMENTS:
|
---|
| 189 | *
|
---|
| 190 | * lSearchId - Table search key
|
---|
| 191 | * plNameLength - Address where to return string length.
|
---|
| 192 | *
|
---|
| 193 | * RETURN:
|
---|
| 194 | *
|
---|
| 195 | * Length of the format string not including the terminating '\0'.
|
---|
| 196 | * That is, the same value as would be returned from strlen().
|
---|
| 197 | *
|
---|
| 198 | * DESCRIPTION:
|
---|
| 199 | *
|
---|
| 200 | * This function will retrieve the length of the format string
|
---|
| 201 | * for the specified IOProc from the resource file that contains
|
---|
| 202 | * the strings.
|
---|
| 203 | *
|
---|
| 204 | ***************************************************************************/
|
---|
| 205 | LONG GetFormatStringLength (LONG lSearchId,
|
---|
| 206 | PLONG plNameLength)
|
---|
| 207 | {
|
---|
| 208 | LONG lStringSize;
|
---|
| 209 | LONG lRetVal;
|
---|
| 210 |
|
---|
| 211 | lStringSize = GetFormatString (lSearchId, NULL, LONG_MAX);
|
---|
| 212 | if (lStringSize > 0) /* String found? */
|
---|
| 213 | {
|
---|
| 214 | *plNameLength = lStringSize; /* yes, return strlen */
|
---|
| 215 | lRetVal = 0; /* and indicate success to caller */
|
---|
| 216 | }
|
---|
| 217 | else
|
---|
| 218 | {
|
---|
| 219 | *plNameLength = 0; /* no, error. Return zero for length */
|
---|
| 220 | lRetVal = lStringSize; /* and error code from called routine */
|
---|
| 221 | }
|
---|
| 222 | return (lRetVal);
|
---|
| 223 | }
|
---|
| 224 |
|
---|
| 225 |
|
---|
| 226 | /**************************************************************************
|
---|
| 227 | * GetNLSData **
|
---|
| 228 | **************************************************************************
|
---|
| 229 | *
|
---|
| 230 | * ARGUMENTS:
|
---|
| 231 | *
|
---|
| 232 | * pulCodePage - Address where to return the code page/country.
|
---|
| 233 | * pulLanguage - Address where to return the language/dialect.
|
---|
| 234 | *
|
---|
| 235 | * RETURN:
|
---|
| 236 | *
|
---|
| 237 | * Error code or 0.
|
---|
| 238 | *
|
---|
| 239 | * DESCRIPTION:
|
---|
| 240 | *
|
---|
| 241 | * This function will retrieve the NLS information for the IOProc
|
---|
| 242 | * strings contained in the resource file.
|
---|
| 243 | *
|
---|
| 244 | ***************************************************************************/
|
---|
| 245 |
|
---|
| 246 | ULONG APIENTRY GetNLSData( PULONG pulCodePage,
|
---|
| 247 | PULONG pulLanguage )
|
---|
| 248 | {
|
---|
| 249 | PVOID pResourceData;
|
---|
| 250 | CHAR *pTemp;
|
---|
| 251 |
|
---|
| 252 | if (DosGetResource( hModuleHandle,
|
---|
| 253 | RT_RCDATA,
|
---|
| 254 | MMOTION_NLS_CHARSET_INFO,
|
---|
| 255 | &pResourceData ))
|
---|
| 256 | {
|
---|
| 257 | return (MMIO_ERROR);
|
---|
| 258 | }
|
---|
| 259 |
|
---|
| 260 | /*
|
---|
| 261 | * The resource table is of the form :
|
---|
| 262 | * usCodePage Low
|
---|
| 263 | * usCountryCode High
|
---|
| 264 | * usLanguage Low
|
---|
| 265 | * usDialect High
|
---|
| 266 | */
|
---|
| 267 |
|
---|
| 268 | pTemp = (CHAR *)pResourceData;
|
---|
| 269 |
|
---|
| 270 | while (pTemp)
|
---|
| 271 | {
|
---|
| 272 | memmove( pulCodePage, pTemp, sizeof(ULONG) );
|
---|
| 273 | pTemp += sizeof(ULONG);
|
---|
| 274 |
|
---|
| 275 | if (pTemp == NULL)
|
---|
| 276 | {
|
---|
| 277 | break;
|
---|
| 278 | }
|
---|
| 279 |
|
---|
| 280 | memmove( pulLanguage, pTemp, sizeof(ULONG) );
|
---|
| 281 |
|
---|
| 282 | break;
|
---|
| 283 | }
|
---|
| 284 |
|
---|
| 285 | DosFreeResource( pResourceData );
|
---|
| 286 |
|
---|
| 287 | return (MMIO_SUCCESS);
|
---|
| 288 | }
|
---|