CFLite: Difference between revisions

From kJams Wiki
Jump to navigation Jump to search
No edit summary
 
(19 intermediate revisions by the same user not shown)
Line 1: Line 1:
What is it? CoreFoundation is a cross platform set of APIs that handle international text (unicode + any conversions + search & replace), primitive data types, plist & xml parsing & container classes, with i/o (memory,  file, network, virtual device), structured data management of said containers (can wrap with STL): dictionaries (maps), arrays (lists of any kind), sets, and all primitive data types plus calendars, dates, locales, etc.  This from the CFLite page:
==What is it?==
CoreFoundation is a cross platform set of APIs that handle international text (unicode + any conversions + search & replace), primitive data types, plist & xml parsing & container classes, with i/o (memory,  file, network, virtual device), structured data management of said containers (can wrap with STL): dictionaries (maps), arrays (lists of any kind), sets, and all primitive data types plus calendars, dates, locales, etc.  This from the CFLite page:
* CF provides the fundamental C data types (for example, String, Dictionary, Array, Data and Number) as well as the essential services (such as plug-ins, URL handling and networking) ... [it] provides convenient facilities for importing and exporting these types as part of a rich, flexible data structure known as a property list (a kind of XML).
* CF provides the fundamental C data types (for example, String, Dictionary, Array, Data and Number) as well as the essential services (such as plug-ins, URL handling and networking) ... [it] provides convenient facilities for importing and exporting these types as part of a rich, flexible data structure known as a property list (a kind of XML).
The thing is so blindingly useful for Unicode string management, managing preferences, internal API dynamic parameter lists, creating, storing, sending and receiving your in-memory data structures as files or via the web, it makes so many things so easy it's a wonder more people aren't using it.  Oh, I know why! Nobody's made an easy way to get it going on windows!  Sure they *say* it's open source "just compile it on windows"?  Well, it's not '''quite''' that easy, actually.  So I'm going to make it easy for you to use this on Windows.  Now you can really write cross platform code to manage your core data types and the ability to easily serialize huge data structures for streaming to / from a file, within memory, or over the web!  YAY!
The thing is so blindingly useful for Unicode string management, managing preferences, internal API dynamic parameter lists, creating, storing, sending and receiving your in-memory data structures as files or via the web, it makes so many things so easy it's a wonder more people aren't using it.  Oh, I know why! Nobody's made an easy way to get it going on windows!  Sure they *say* it's open source "just compile it on windows"?  Well, it's not '''quite''' that easy, actually.  So I'm going to make it easy for you to use this on Windows.  Now you can really write cross platform code to manage your core data types and the ability to easily serialize huge data structures for streaming to / from a file, within memory, or over the web!  YAY!


==The "Easy" Way==
==What's special about this implementation==
# Download my pre-built [http://kjams.com/cflite/downloads/CoreFoundation.zip Windows CFLite 476.13 Binary Installer].  It's not really an installer, you have to manually install it. 
* "just works" on windows
# Unzip it and drop the folder into your WINDOWS directory (typically on your C:\ drive)
* works in 32 and 64 bit, compiles with no warnings
# On your desktop, right click on "My Computer", click "properties", click "Advanced", click "Environment Variables", then under "System Variables", scroll down to "Path" and select it, click "Edit", then add "'''%SystemRoot%\CoreFoundation;'''" to the beginning of the line.  (note that if you produce an application for public consumption, you'll have to have your installer do these 2 steps programmatically)
* CFNetwork is also implemented (both client and server)
# In your Visual Studio (or whatever IDE):
* uses LibreSSL, with support for TLS 1.1 and 1.2
## In "C++ / General / Additional Include Directories", add these include paths: "'''C:\WINDOWS\CoreFoundation'''" and "'''C:\WINDOWS\CoreFoundation\GNUCompatability'''"
* projects for Qt are included
## In "C++ / Preprocessor / Preprocessor Defninitions", add "'''__WIN32__'''"
## In "Linker / General / Additional Library Directories", add "'''C:\WINDOWS\CoreFoundation'''"
## In "Linker / Input / Additional Dependencies", add "'''CoreFoundation.dll'''"
## In Release configuration only: In "Linker / Optimization / References", change it to "'''Keep Unreferenced Data'''"
## if you are also linking against QuickTime for winders, set the QT header search path to come AFTER the CF ones, and, in any source file that includes <Movies.h>, put this line in front of it:<br><pre>#define __CFUUID__</pre>
# You're done!  Enjoy the goodness!


I have added a single function to the Windows version of CF:
==How to use it==
void  CFSetLogFile(CFStringRef pathRef);
Just download my [[Code/CFLite/CFNetwork|CoreFoundation]] package.
Call this during your app initialization and it will direct the output CFShow() and CFLog() and friends to that file.  Otherwise these functions don't do anything.  See CFTest for an example in the CCFLog::operator() routine.


==The Hard Way==
==Cooperating with QuickTime==
Build the thing your self. Separate page for that, [[CFLite|go here]].
QuickTime for windows comes with it's own version of CoreFoundation.  If you make a call to a QT function that returns a CF object, you're going to need to release it with QT's version of CFRelease().
 
<pre>
void    QT_CFRelease(CFTypeRef cfType)
{
    typedef void    (*QT_CFReleaseProcType)(CFTypeRef cf);
    static QT_CFReleaseProcType        QT_CFReleaseProc = NULL;
 
    if (QT_CFReleaseProc == NULL) {
        HINSTANCE        hinstLib = GetModuleHandleA("QTCF");
 
        if (hinstLib == NULL) {
            MessageAlert("ERROR: unable to load QTCF");
            return;
        }
   
        // Get function pointer
        QT_CFReleaseProc = (QT_CFReleaseProcType)GetProcAddress(hinstLib, "QTCF_CFRelease");
        if (QT_CFReleaseProc == NULL) {
            MessageAlert("ERROR: unable to find CFRelease");
            return;
        }
    }
 
    if (QT_CFReleaseProc) {
        QT_CFReleaseProc(cfType);
    }
}
</pre>
 
==Debugging with QuickTime on Windows in Parallels Desktop on Mac==
If you do any debugging on Windows using Parallels (which is an app running on your mac), and your app uses QuickTime, then you'll run into the dreaded "Clipboard Chain Lockup".  When you're paused in the debugger, the moment you copy and/or paste between the Host and the Guest, your Parallels app will hang (as well as the other app on your host that was the source / destination of the clipboard transfer).
 
To get around that, [[Blog/Parallels/Solution|use this code]].
 
If you'd like to read the entire crazy saga of how I came to even understand this, [[Blog/Parallels|see this blog post]].
 
==Old Info==
Looking for the [[CFLite old|historic (out of date)]] page?

Latest revision as of 15:34, 9 August 2017

What is it?

CoreFoundation is a cross platform set of APIs that handle international text (unicode + any conversions + search & replace), primitive data types, plist & xml parsing & container classes, with i/o (memory, file, network, virtual device), structured data management of said containers (can wrap with STL): dictionaries (maps), arrays (lists of any kind), sets, and all primitive data types plus calendars, dates, locales, etc. This from the CFLite page:

  • CF provides the fundamental C data types (for example, String, Dictionary, Array, Data and Number) as well as the essential services (such as plug-ins, URL handling and networking) ... [it] provides convenient facilities for importing and exporting these types as part of a rich, flexible data structure known as a property list (a kind of XML).

The thing is so blindingly useful for Unicode string management, managing preferences, internal API dynamic parameter lists, creating, storing, sending and receiving your in-memory data structures as files or via the web, it makes so many things so easy it's a wonder more people aren't using it. Oh, I know why! Nobody's made an easy way to get it going on windows! Sure they *say* it's open source "just compile it on windows"? Well, it's not quite that easy, actually. So I'm going to make it easy for you to use this on Windows. Now you can really write cross platform code to manage your core data types and the ability to easily serialize huge data structures for streaming to / from a file, within memory, or over the web! YAY!

What's special about this implementation

  • "just works" on windows
  • works in 32 and 64 bit, compiles with no warnings
  • CFNetwork is also implemented (both client and server)
  • uses LibreSSL, with support for TLS 1.1 and 1.2
  • projects for Qt are included

How to use it

Just download my CoreFoundation package.

Cooperating with QuickTime

QuickTime for windows comes with it's own version of CoreFoundation. If you make a call to a QT function that returns a CF object, you're going to need to release it with QT's version of CFRelease().

void    QT_CFRelease(CFTypeRef cfType)
{
    typedef void    (*QT_CFReleaseProcType)(CFTypeRef cf);
    static QT_CFReleaseProcType        QT_CFReleaseProc = NULL;
   
    if (QT_CFReleaseProc == NULL) {
        HINSTANCE        hinstLib = GetModuleHandleA("QTCF");

        if (hinstLib == NULL) {
            MessageAlert("ERROR: unable to load QTCF");
            return;
        }
     
        // Get function pointer
        QT_CFReleaseProc = (QT_CFReleaseProcType)GetProcAddress(hinstLib, "QTCF_CFRelease");
        if (QT_CFReleaseProc == NULL) {
            MessageAlert("ERROR: unable to find CFRelease");
            return;
        }
    }
   
    if (QT_CFReleaseProc) {
        QT_CFReleaseProc(cfType);
    }
}

Debugging with QuickTime on Windows in Parallels Desktop on Mac

If you do any debugging on Windows using Parallels (which is an app running on your mac), and your app uses QuickTime, then you'll run into the dreaded "Clipboard Chain Lockup". When you're paused in the debugger, the moment you copy and/or paste between the Host and the Guest, your Parallels app will hang (as well as the other app on your host that was the source / destination of the clipboard transfer).

To get around that, use this code.

If you'd like to read the entire crazy saga of how I came to even understand this, see this blog post.

Old Info

Looking for the historic (out of date) page?