[Windows 10][C][GCC] Extract tags from CDR files

Sławomir Lach 0 Reputation points
2023-05-27T17:39:41.7033333+00:00

I am beginner programmer and I should extract tags from Corel Draw files (*.cdr).

I prefer extracting it in C language, because I known it already.

I install gcc compiler (I remember thanks to mingw project, but I am not sure if I install mingw, msys, cygwin or other).

I use Netbeans IDE and compile other programs on this compiler, so everything was configured.

I found some examples, but written in C++ or requires some other compiler (I prefer it to write it in some ISO C version), because uses some API forks (not yet follow via ISO standard).

It uses some shell functions and these examples were some complex.

I will tell the truth: people in my company was unable to use tags. I created tags and tags/search folders, but:

  1. It stop working after some windows 10 update
  2. Without looking at 1., people are nervous with tags - he/she prefers directories and I cannot group files by folders, because we group corel projects (some may contains people, some persons, some may contains rectangles, another circles or any of combinations, so I cannot group it into folders without duplicating files and duplicating files are stupid, because people will edit one version in some day and try to retry in another and could not found changes they were made).

So I decided to write my own system, based on apache and php. Everything working, but I was unable to extract tags. Ughhh... If somebody could give solution/example in php instead of c, it could be also great.

Summary: I need to extract metadata (in this case: tags) from cdr files. I known, that Windows do not have centralized database for tags, but some file format allow to store tags. There is also shell extensions, which allows to extend shell with some capabilities (in this case Corel allows Explorer to display tags). But I only found C++ examples, which requires compiler-dependent functionality. I need C or PHP simple examples, which only uses standardized language options.

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,632 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Paolo Lazzaroni 0 Reputation points
    2023-06-05T22:27:48.6466667+00:00

    If you're looking to extract tags from Corel Draw files (*.cdr) using C or PHP, I can provide you with some guidance.

    In C, you can use the Windows Shell API to access file properties, including tags. Here's an example of how you can extract tags from a CDR file using the Shell API in C:

    #include <Windows.h>
    #include <Shobjidl.h>
    #include <Propkey.h>
    
    void ExtractTagsFromCDR(const wchar_t* filePath) {
        IShellItem2* shellItem;
        if (SUCCEEDED(SHCreateItemFromParsingName(filePath, NULL, IID_PPV_ARGS(&shellItem)))) {
            PROPVARIANT propVariant;
            if (SUCCEEDED(shellItem->GetProperty(PKEY_Keywords, &propVariant))) {
                if (propVariant.vt == VT_VECTOR | VT_LPWSTR) {
                    for (ULONG i = 0; i < propVariant.calpwstr.cElems; i++) {
                        wprintf(L"Tag: %s\n", propVariant.calpwstr.pElems[i]);
                    }
                }
                PropVariantClear(&propVariant);
            }
            shellItem->Release();
        }
    }
    
    int main() {
        const wchar_t* filePath = L"path_to_your_cdr_file.cdr";
        CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
        ExtractTagsFromCDR(filePath);
        CoUninitialize();
        return 0;
    }
    

    This code uses the IShellItem2 interface from the Shell API to retrieve the PKEY_Keywords property, which represents the tags of a file. It then loops through the tag values and prints them to the console.

    For PHP, you can use the exif_read_data function to extract metadata from files. However, please note that this function is primarily intended for image files and may not work with Corel Draw files. Nevertheless, you can give it a try:

    $tags = exif_read_data('path_to_your_cdr_file.cdr', 'IFD0');
    if (isset($tags['Keywords'])) {
        foreach ($tags['Keywords'] as $tag) {
            echo "Tag: $tag\n";
        }
    }
    

    Keep in mind that the exif_read_data function relies on the availability of EXIF data within the file, and it may not support all file formats.

    Remember to replace 'path_to_your_cdr_file.cdr' with the actual path to your CDR file in both the C and PHP examples.

    I hope these examples help you extract tags from your Corel Draw files using standardized language options.

    0 comments No comments