C language > Tips & tricks

COM helper library

(1/3) > >>

John Z:
Here is a link to a helper library that with just two files opens up a lot of possibilities. 
Really useful - I was able to add two files and a few (to get started) lines of code and have added a working speech capability to my program.  8)

https://sourceforge.net/projects/disphelper/ 

From the developer:

--- Quote ---DispHelper is a COM helper library that can be used in C++ or even plain C. No MFC or ATL required! It allows you to call COM objects with a printf style syntax. Included with DispHelper are over 20 samples demonstrating using COM objects from ADO to WMI
--- End quote ---

The code needs few minor fixups to run the "plain C sources" under Pelles C version 10, mainly adding l to %s in a few places, as in "%ls".  So far I've only used the speech interface but there are many other examples.  Would have taken me a long time to figure out from scratch although I'd end up a bit more knowledgeable if I did.

John Z

bitcoin:
Good thing, thanks! COM is terrible.

MrBcx:
Another option ...

BCX makes using COM scripts written in VBA, VBScript and others pretty easy.  The
best part is being able to easily mix non-COM code with COM, in order to get real
work done.    ;)

BCX includes a number of time-saving wrappers.  The BCX code below generates
the attached C file that compiles with Pelles V11 just fine.   The attached zip
contains the C source code and a 38kb executable.  No other dependencies needed.

DIM oVoice AS OBJECT
oVoice = COM ("SAPI.SpVoice")
IF ISOBJECT(oVoice) THEN oVoice.Speak "Hello from BCX"
UNCOM (oVoice)

 

TimoVJL:
An old example from Tino
https://forum.pellesc.de/index.php?topic=1200.msg5436#msg5436

--- Code: ---#include <objbase.h> // Necessary for COM ( + ole32.lib see Project Properties)
#include <sapi.h> // Found in PellesC-Include-Folder
#include <stdio.h>

int main(){

printf("Sapi 5.1 - PellesC Demo - Turn on the speakers & Listen\r\n\r\n");

ISpVoice *pVoice = NULL;

if (FAILED(CoInitialize( 0 )) ) return FALSE;

HRESULT hr = CoCreateInstance(
&CLSID_SpVoice,
NULL,
CLSCTX_ALL,
&IID_ISpVoice,
(void **) &pVoice);

if( SUCCEEDED( hr ) ){
hr = pVoice->lpVtbl->Speak( pVoice, L"Hello world. Ehlo world.", 0, 0);
pVoice->lpVtbl->Release( pVoice );
pVoice = NULL;
};

CoUninitialize ();
return 0;
}

--- End code ---

bitcoin:
What is 'BCX' ?

Navigation

[0] Message Index

[#] Next page

Go to full version