You could use two techniques.
1) Use BYOB instead of Scratch. BYOB is a branch of Scratch created at Berkeley, it is similar in its blocks interface, but is much more flexible - and in particular, it has file output and string handling capabilities.
2) Use the Scratch network communication, remote sensor connection. It's been used to connect Scratch to various outside tools, it could communicate to a C++ library. Basically, it communicates its variables and events, and listens to messages, through port 42001.
BYOB also supports the Scratch network, so you could use both. An alternative would be to customise Scratch into a version that support your tools using squeak. But a BYOB library would probably be easier to share.