NO

Author Topic: COM helper library  (Read 12047 times)

Offline John Z

  • Member
  • *
  • Posts: 860
COM helper library
« on: August 08, 2021, 05:15:16 PM »
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

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

Offline bitcoin

  • Member
  • *
  • Posts: 179
Re: COM helper library
« Reply #1 on: August 17, 2021, 10:58:38 PM »
Good thing, thanks! COM is terrible.

Offline MrBcx

  • Global Moderator
  • Member
  • *****
  • Posts: 189
    • Bcx Basic to C/C++ Translator
Re: COM helper library
« Reply #2 on: August 18, 2021, 01:00:09 AM »
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)

 
Bcx Basic to C/C++ Translator
https://www.BcxBasicCoders.com

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: COM helper library
« Reply #3 on: August 18, 2021, 08:02:02 AM »
An old example from Tino
https://forum.pellesc.de/index.php?topic=1200.msg5436#msg5436
Code: [Select]
#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;
}
May the source be with you

Offline bitcoin

  • Member
  • *
  • Posts: 179
Re: COM helper library
« Reply #4 on: August 18, 2021, 12:17:48 PM »
What is 'BCX' ?

Offline John Z

  • Member
  • *
  • Posts: 860
Re: COM helper library
« Reply #5 on: August 18, 2021, 01:05:20 PM »
Another option ...

BCX ...
The C output file is an amazing piece of work!  I've used all types of 'Basic' for a long time. Stopped upgrading M$ VB after version 5, but I wish I had gotten version 6. I think I tried BCX to convert a VB5 program of some complexity, too many issues as I recall.  Then I bought PowerBasic but in using it I realized I might as well switch to C for my windows programing (I have used C for non-windows systems Vax/Vms, HPux, etc for many years).

An old example from Tino ....
Wow based on this example I'm in overkill land with the COM helper Files since I'm only using simple speech output.  I'm going to test using this code as a basis instead.

Thank you both for these examples and inputs!

John Z

Offline John Z

  • Member
  • *
  • Posts: 860
Re: COM helper library
« Reply #6 on: August 18, 2021, 02:25:07 PM »
What is 'BCX' ?
Check out https://bcxbasiccoders.com/
"Basic to C Translator"

John Z

Offline Vortex

  • Member
  • *
  • Posts: 865
    • http://www.vortex.masmcode.com
Re: COM helper library
« Reply #7 on: August 18, 2021, 09:15:44 PM »
Hi TimoVJL and MrBcx,

Thanks for the examples.
Code it... That's all...

Offline MrBcx

  • Global Moderator
  • Member
  • *****
  • Posts: 189
    • Bcx Basic to C/C++ Translator
Re: COM helper library
« Reply #8 on: August 18, 2021, 10:04:30 PM »

Wow based on this example I'm in overkill land with the COM helper Files since I'm only using simple speech output.  I'm going to test using this code as a basis instead.

John Z

It's worth noting ... the COM code that BCX emits will generally compile with
MSVC++, Embarcadero C++(7.50), Clang, Pelles C, and Lcc-Win32.   Mingw32/64
is sometimes more difficult when working with COM but it can be done.

Bcx Basic to C/C++ Translator
https://www.BcxBasicCoders.com

Offline John Z

  • Member
  • *
  • Posts: 860
Re: COM helper library
« Reply #9 on: August 20, 2021, 02:54:38 PM »
An old example from Tino
https://forum.pellesc.de/index.php?topic=1200.msg5436#msg5436
Code: [Select]
#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;
}
So I found the above code, or something almost exactly like it in M$ tutorial on SAPI 5.4.  I've replaced the complex COM helper with this simpler code and it works well and reduced the exe by about 12K  :).  Thanks for the tip!


With this simple code I see that PellesC SAPI.H is throwing some warnings, yes I could suppress with pragma, but documenting here for future improvement consideration.
Code: [Select]
Building speech.obj.
C:\Program Files\PellesC_V10\Include\Win\sapi.h(3207): warning #2197: [ISO] 'SPEVENTENUM (aka enum SPEVENTENUM)' is not a standard bit-field type.
C:\Program Files\PellesC_V10\Include\Win\sapi.h(3208): warning #2197: [ISO] 'SPEVENTLPARAMTYPE (aka enum SPEVENTLPARAMTYPE)' is not a standard bit-field type.
C:\Program Files\PellesC_V10\Include\Win\sapi.h(3216): warning #2197: [ISO] 'SPEVENTENUM (aka enum SPEVENTENUM)' is not a standard bit-field type.
C:\Program Files\PellesC_V10\Include\Win\sapi.h(3217): warning #2197: [ISO] 'SPEVENTLPARAMTYPE (aka enum SPEVENTLPARAMTYPE)' is not a standard bit-field type.
C:\Program Files\PellesC_V10\Include\Win\sapi.h(3225): warning #2197: [ISO] 'SPEVENTENUM (aka enum SPEVENTENUM)' is not a standard bit-field type.
C:\Program Files\PellesC_V10\Include\Win\sapi.h(3226): warning #2197: [ISO] 'SPEVENTLPARAMTYPE (aka enum SPEVENTLPARAMTYPE)' is not a standard bit-field type.

All of the 'offending' lines are of the form
Code: [Select]
    SPEVENTENUM eEventId : 16;
    SPEVENTLPARAMTYPE elParamType : 16;

John Z


Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: COM helper library
« Reply #10 on: August 20, 2021, 06:12:00 PM »
With this simple code I see that PellesC SAPI.H is throwing some warnings, yes I could suppress with pragma, but documenting here for future improvement consideration.
Code: [Select]
Building speech.obj.
C:\Program Files\PellesC_V10\Include\Win\sapi.h(3207): warning #2197: [ISO] 'SPEVENTENUM (aka enum SPEVENTENUM)' is not a standard bit-field type.
C:\Program Files\PellesC_V10\Include\Win\sapi.h(3208): warning #2197: [ISO] 'SPEVENTLPARAMTYPE (aka enum SPEVENTLPARAMTYPE)' is not a standard bit-field type.
C:\Program Files\PellesC_V10\Include\Win\sapi.h(3216): warning #2197: [ISO] 'SPEVENTENUM (aka enum SPEVENTENUM)' is not a standard bit-field type.
C:\Program Files\PellesC_V10\Include\Win\sapi.h(3217): warning #2197: [ISO] 'SPEVENTLPARAMTYPE (aka enum SPEVENTLPARAMTYPE)' is not a standard bit-field type.
C:\Program Files\PellesC_V10\Include\Win\sapi.h(3225): warning #2197: [ISO] 'SPEVENTENUM (aka enum SPEVENTENUM)' is not a standard bit-field type.
C:\Program Files\PellesC_V10\Include\Win\sapi.h(3226): warning #2197: [ISO] 'SPEVENTLPARAMTYPE (aka enum SPEVENTLPARAMTYPE)' is not a standard bit-field type.

All of the 'offending' lines are of the form
Code: [Select]
    SPEVENTENUM eEventId : 16;
    SPEVENTLPARAMTYPE elParamType : 16;

John Z
You have to use pragmas to suppress those warnings, or set warning level 1.
The warning refers to the ISO standard "ยง6.7.2.1 Structure and union specifiers" in constraints, point 5, where says:
Quote
A bit-field shall have a type that is a qualified or unqualified version of _Bool, signed int, unsigned int, or some other implementation-defined type.
Microsoft apply bit-fielfs to almost all types available while strict ISO compliance allows only the integer types above.
The warning, on pedantic level 2, informs you that the bit-field is an implementation extension and therefore your code could be not portable.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Offline Vortex

  • Member
  • *
  • Posts: 865
    • http://www.vortex.masmcode.com
Re: COM helper library
« Reply #11 on: April 07, 2024, 01:05:45 PM »
ComView by Baron-von-Riedesel :

Quote
About

Win32 tool that allows to play with COM objects ( create objects of classes, call methods, set/get properties ). Can also create assembly include files from typelibs.

https://github.com/Baron-von-Riedesel/ComView
Code it... That's all...