//--------------------------------------------------------------------------- #include #include #include #include "TPMemory.h" #include "TPDocObject.h" #pragma hdrstop //--------------------------------------------------------------------------- // Important note about DLL memory management when your DLL uses the // static version of the RunTime Library: // // If your DLL exports any functions that pass String objects (or structs/ // classes containing nested Strings) as parameter or function results, // you will need to add the library MEMMGR.LIB to both the DLL project and // any other projects that use the DLL. You will also need to use MEMMGR.LIB // if any other projects which use the DLL will be performing new or delete // operations on any non-TObject-derived classes which are exported from the // DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling // EXE's to use the BORLNDMM.DLL as their memory manager. In these cases, // the file BORLNDMM.DLL should be deployed along with your DLL. // // To avoid using BORLNDMM.DLL, pass string information using "char *" or // ShortString parameters. // // If your DLL uses the dynamic version of the RTL, you do not need to // explicitly add MEMMGR.LIB as this will be done implicitly for you //--------------------------------------------------------------------------- #pragma argsused int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved) { return 1; } //--------------------------------------------------------------------------- bool __fastcall TextLoadFromFile(HANDLE hFile, AnsiString &Text) { DWORD dwRead; int n; char *str = NULL; if (!ReadFile(hFile, &n, sizeof(int), &dwRead, NULL)) return false; if (n > 0) { if ((str = new char[n + 1]) == NULL) goto fail; str[n] = 0; if (!ReadFile(hFile, str, n, &dwRead, NULL)) goto fail; Text = str; delete [] str; } return true; fail: if (str) delete [] str; return false; } //--------------------------------------------------------------------------- bool __fastcall ImageLoadFromFile(HANDLE hFile, TTexpiaBitmap *&Image) { DWORD dwRead; int w, h; WORD ,bpp; RGBQUAD rgb[256]; if (!ReadFile(hFile, &bpp, sizeof(WORD), &dwRead, NULL)) return NULL; if (bpp) { if (!ReadFile(hFile, &w, sizeof(int), &dwRead, NULL)) return NULL; if (!ReadFile(hFile, &h, sizeof(int), &dwRead, NULL)) return NULL; if ((Image = new TTexpiaBitmap) == NULL) return NULL; if (bpp == 8) { if (!ReadFile(hFile, rgb, 256 * sizeof(RGBQUAD), &dwRead, NULL)) goto fail; if (!Image->Create(w, h, bpp, rgb)) goto fail; } else { if (!Image->Create(w, h, bpp)) goto fail; } if (!Image->LoadFromTexpiaFile(hFile, cmZLib)) goto fail; } return true; fail: if (Image) { delete Image; Image = NULL; } return false; } //--------------------------------------------------------------------------- TTexpiaBitmap * __fastcall LoadThumbnailImage(HANDLE hSheafFile) { DWORD dwRead; bool result; TTexpiaBitmap *tempImage = NULL; if (!ReadFile(hSheafFile, &result, sizeof(bool), &dwRead, NULL)) return NULL; if(result){ if (!ImageLoadFromFile(hSheafFile, tempImage)) return NULL; } return tempImage; } //--------------------------------------------------------------------------- extern "C" __declspec(dllexport) __stdcall HBITMAP GetImageBitmap(LPSTR Filename) { HBITMAP ThumbnailBitmap; HBITMAP hOldBmp; HANDLE hSheafFile = INVALID_HANDLE_VALUE; int version, n, i; int StepNumber; //for ¾ÆÀ̺ñ ¿ä±¸»çÇ×. int ThumbnailCnt; int PrimaryThumbnailNum; DWORD dwRead; HDC dcSrc = NULL, dcDst = NULL; TTexpiaBitmap *TPBitmap=NULL; AnsiString str; try{ if ((hSheafFile = CreateFile(Filename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { if ((hSheafFile = CreateFile(Filename, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL)) == INVALID_HANDLE_VALUE) goto fail; } if (!ReadFile(hSheafFile, &version, sizeof(int), &dwRead, NULL)) goto fail; if (!TextLoadFromFile(hSheafFile, str)) goto fail; if (version >= 8) { if (!TextLoadFromFile(hSheafFile, str)) goto fail; if (!TextLoadFromFile(hSheafFile, str)) goto fail; if (!TextLoadFromFile(hSheafFile, str)) goto fail; if (!TextLoadFromFile(hSheafFile, str)) goto fail; if(version >=12){ //for ¾ÆÀ̺ñ ¿ä±¸»çÇ×. if (!ReadFile(hSheafFile, &StepNumber, sizeof(int), &dwRead, NULL)) goto fail; //for ¾ÆÀ̺ñ ¿ä±¸»çÇ×. } } if (!ReadFile(hSheafFile, &n, sizeof(int), &dwRead, NULL)) goto fail; if(version >= 11){ //ThumbnailÀ̹ÌÁöÀÇ °¹¼ö¸¦ Àоî¿Â´Ù if (!ReadFile(hSheafFile, &ThumbnailCnt, sizeof(int), &dwRead, NULL)) goto fail; if(ThumbnailCnt>0){ // primary ÀÇ À§Ä¡(¾î´À sheetÀÇ ¾î´À object)¶ÇÇÑ Àоî¿Â´Ù. if (!ReadFile(hSheafFile, &PrimaryThumbnailNum, sizeof(int), &dwRead, NULL)) goto fail; //To Do : ThumbnailÀ̹ÌÁö bitmap À̹ÌÁö¸¦ ¾ÐÃàÇØ¼­ Àоî¿Â´Ù. TPBitmap=LoadThumbnailImage(hSheafFile); } } CloseHandle(hSheafFile); if ((dcSrc = TPBitmap->CreateDC())==NULL) goto fail; if ((dcDst = CreateCompatibleDC(dcSrc)) == NULL) goto fail; if ((ThumbnailBitmap=CreateCompatibleBitmap(dcSrc,TPBitmap->Width,TPBitmap->Height)) == NULL) goto fail; hOldBmp = (HBITMAP)SelectObject(dcDst,ThumbnailBitmap); BitBlt(dcDst, 0, 0, TPBitmap->Width, TPBitmap->Height, dcSrc, 0, 0, SRCCOPY); SelectObject(dcDst,hOldBmp); DeleteDC(dcDst); TPBitmap->DeleteDC(dcSrc); if (TPBitmap){delete TPBitmap; TPBitmap = NULL;} return ThumbnailBitmap; } catch(...) { if (TPBitmap){delete TPBitmap; TPBitmap = NULL;} if (hSheafFile!=INVALID_HANDLE_VALUE) CloseHandle(hSheafFile); return NULL; } fail: if (TPBitmap){delete TPBitmap; TPBitmap = NULL;} if (hSheafFile!=INVALID_HANDLE_VALUE) CloseHandle(hSheafFile); return NULL; } //---------------------------------------------------------------------------