ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

acdbGetPreviewBitmapFromDwg locks the file even after the routine ends

2 REPLIES 2
Reply
Message 1 of 3
muaslam
273 Views, 2 Replies

acdbGetPreviewBitmapFromDwg locks the file even after the routine ends

Hi,

 

I have been using acdbGetPreviewBitmapFromDwg for extracting thumbnail image from DWG files and I am using this from a web job that is running continuously for all the requests. Whenever I make a call to the method acdbGetPreviewBitmapFromDwg, it locks the file and never releases for me to delete the file to clear the clutter from the server. Following is my source code,

 

            bool ReadThumbnail(std::wstring filename, std::wstring thumbnailPath, RDwgError^ error)
            {
                // acdbGetPreviewBitmapFromDwg depends on hostApp being initialized:
                RealDwg::RealDwgHostApp hostApp = RealDwg::RealDwgHostApp::Instance();
                if (!s_hostAppInitialized && Acad::eOk == acdbSetHostApplicationServices(&hostApp))
                    s_hostAppInitialized = true;
                if (!s_hostAppInitialized)
                {
                    error->Code = 2;
                    error->Description = "Host App Not Initialized.";
                    return false;
                }
                
                HBITMAP     hBitmap = NULL;
                HPALETTE    hPalette = NULL;

                char* filenameCharPointer = new char[1024];
                wcstombs(filenameCharPointer, filename.c_str(), 1024);
                if (!fopen(filenameCharPointer, "r"))
                {
                    error->Description = "Source file does not exist";
                    error->Code = 4;
                    return false;
                }

                delete filenameCharPointer;

                int bitmapresult = acdbGetPreviewBitmapFromDwg(filename.c_str(), &hBitmap, &hPalette);
                if (!bitmapresult)
                {
                    error->Description = "Could not get preview bitmap from dwg";
                    error->Code = 3;
                    return false;
                }

                std::cout << "Storing file now" << std::endl;

                CImage image;
                image.Attach(hBitmap);
                image.Save(thumbnailPath.c_str(), Gdiplus::ImageFormatBMP);
                

                std::cout << "File stored successfully" << std::endl;

                image.Destroy();
                DeleteObject(hBitmap);
                DeleteObject(hPalette);

                return true;
            }

 

 

Any help on how can I release the file for the next method to delete it after the thumbnail extraction. 

 

Regards,

Umar

2 REPLIES 2
Message 2 of 3
tbrammer
in reply to: muaslam

Saving the bitmap is done like this here:

#include <atlimage.h>
#include <Gdiplusimaging.h>
static void AsdkSavePreviewImage(LPCWSTR filename)
{
    HBITMAP hBitmap;
    HPALETTE hPal;
    acdbGetPreviewBitmapFromDwg(filename, &hBitmap, &hPal);
    CBitmap bitmap;
    bitmap.Attach(hBitmap);
    CImage image;
    image.Attach(bitmap);
    image.Save(_T("C:\\Temp\\myBitmap.bmp"), Gdiplus::ImageFormatBMP);
    DeleteObject(hBitmap);
    DeleteObject(hPal);
}

If this doesn't work:  Is the function called from the "main thread" or from a separate thread?


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

Message 3 of 3
daniel_cadext
in reply to: muaslam

Is the first code missing fclose?

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report