mfc >> MFC ActiveX newb needs a little help (Crossposted from ms.public.vc.mfcole)

by the.tarquin » Tue, 21 Mar 2006 14:09:26 GMT

Hi everyone,

I was referred to this newsgroup after much searching elsewhere, so
I'm hoping this is the right kind of place for my questions. I've
never coded an activeX control before, nor worked extensively with MFC
(though I am quite proficient with C++, so I'm not finding MFC to be
much of a problem) and now I've found myself involved in a project
which requires me to code an activeX control to communicate between a
hosted HTML interface and a stand-alone .exe running in the background.
I'm starting to believe I may be in a touch over my head. Some
specific questions I have: (For reference, the application in question
is a distributed audio app designed for home automation.)

1.) If I have an activeX control which is going to compile down to
an .ocx, how would I go about establishing communication between it and
an .exe? The .ocx needs to be able to access functions in the .exe so
that it can, for example, send play, pause, and stop commands from the
html interface through to the stand-alone .exe.

2.) I've managed (after some struggle) to retrieve the clsid that
my activeX control is registering so that I can use it in an object
tag. Will this ever change? If I dump my control on another box, it
will always register the same clsid? How about if I make code changes
and recompile?

3.) While I'm starting to understand a little more about this whole
activeX thing, any good sources for beginners that you could send links
for would be most appreciated.

4.) The flighty, random question: Anyone have any advice for an
ActiveX newb working with control-to-exe communication or just activex
in general? Anything that you wish you'd known when you were just
trying to puzzle this whole thing out?

I've plowed through one small book on ActiveX in MFC, but it was
impressively unhelpful. Any help that the friendly members of the
intarweb can provide would be much appreciated.

Cheers,
Aaron Brown



mfc >> MFC ActiveX newb needs a little help (Crossposted from ms.public.vc.mfcole)

by Paul Barrett » Wed, 22 Mar 2006 02:09:29 GMT


1. At that point it's just like any other case of needing inter-process
communication. Is the EXE something that you have the source to and can
modify? If so I'd probably add a COM interface to the EXE (or maybe it
already has one), then call methods on that from your new OCX. If you don't
want to use COM, there's named-pipes, sockets, etc. but that's all more
work.
If the EXE is something that you can't modify, like media-player for
example, your OCX could find the EXE's window using FindWindow, then post it
messages to simulate keys or something.

2. No the CLSID won't change. It was generated once by the wizard and is
permanent unless you manually edit it in the .IDL file.

Maybe others have suggestions for 3 and 4.









Similar Threads

1. Lets create comp.microsoft.public.vc.mfc or alt.microsoft.public.vc.mfc

2. New to C++ and Need a little help with a public domain program

Hi,

I am new C++ and need a little help with a public domain program that
is suppose to perform a byte swap. I am receiving the following error
messages during the compile process with Microsoft C++ 2003.

Here are the error messages and source code:


(97) : error C2664: 'fgetpos' : cannot convert parameter 2 from 'void
*' to 'fpos_t *'

Conversion from 'void*' to pointer to non-'void' requires an explicit
cast

(99) : error C2440: '=' : cannot convert from 'void *' to 'unsigned
char *'

Conversion from 'void*' to pointer to non-'void' requires an explicit
cast


Here is the source:

/*
 * swap Version 0.0
 * Bart Trzynadlowski, October 27, 2000
 * Public domain
 *
 * June 11, 2001:
 *      - Updated contact information
 * 
 *
 * This program swaps the bytes, words, doublewords, or quadwords in
files.
 *
 * Usage:   swap <-b files, -w files, -d files, -q files>
 * Options: -?,-h   Show help
 *          -b      Byte swap (8-bit) [default]
 *          -w      Word swap (16-bit)
 *          -d      Doubleword swap (32-bit)
 *          -q      Quadword swap (64-bit)
 *
 * Contact Bart Trzynadlowski:
 *  Email:  XXXX@XXXXX.COM 
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int         swap_type = 0;  /* 0=byte, 1=word, 2=dword, 3=qword */
unsigned    mask[] = { 0, 1, 3, 7 };
unsigned    data_sz[] = { 1, 2, 4, 8 };
char        *type_l[] = { "byte", "word", "doubleword", "quadword" };
char        *type_u[] = { "Byte", "Word", "Doubleword", "Quadword" };


void Swap(unsigned char *buffer, unsigned size, char *file)
{
    unsigned        i, j;
    unsigned char   d[8];

    if (size & mask[swap_type])
    {
        fprintf(stderr, "swap: File cannot be %s-swapped: %s (%d
bytes)\n",
                type_l[swap_type], file, size);
        return;
    }

    printf("swap: %s-swapping file: %s (%d bytes)... ",
type_u[swap_type],
           file, size);
    for (i = 0; i < size; i += (data_sz[swap_type] * 2))
    {
        for (j = 0; j < data_sz[swap_type]; j++)
            d[j] = buffer[i + j];
        for (j = 0; j < data_sz[swap_type]; j++)
            buffer[i + j] = buffer[i + j + data_sz[swap_type]];
        for (j = 0; j < data_sz[swap_type]; j++)
            buffer[i + j + data_sz[swap_type]] = d[j];
    }
    printf("OK\n");
}

void ShowHelp()
{
    printf("swap Version 0.0 by Bart Trzynadlowski: Data-Swapping
Utility\n");
    printf("Usage:      swap <-b files, -w files, -d files, -q
files>\n");
    printf("Options:    -?,-h   Show this help text\n");
    printf("            -b      Swap bytes [default]\n");
    printf("            -w      Swap words\n");
    printf("            -d      Swap doublewords\n");
    printf("            -q      Swap quadwords\n");
    exit(0);
}

int main(int argc, char **argv)
{
    FILE            *fp;
    unsigned char   *buffer;
    unsigned        i, j;

    if (argc <= 1)
        ShowHelp();

    setvbuf(stdout, NULL, _IONBF, NULL); 

    for (i = 1; i < argc; i++)
    {
        if (!strcmp(argv[i], "-?") || !strcmp(argv[i], "-h"))  
ShowHelp();
           else if (!strcmp(argv[i], "-b"))    swap_type = 0;
           else if (!strcmp(argv[i], "-w"))    swap_type = 1;
           else if (!strcmp(argv[i], "-d"))    swap_type = 2;
           else if (!strcmp(argv[i], "-q"))    swap_type = 3;
        else
        {
            if ((fp = fopen(argv[i], "rb+")) == NULL)
                fprintf(stderr, "swap: Failed to open file: %s\n",
argv[i]);
                else
            {
                fseek(fp, 0, SEEK_END);
ERROR HERE->    fgetpos(fp, (void *) &j);
                rewind(fp);
ERROR HERE->    if ((buffer = calloc(j, sizeof(unsigned char))) ==
NULL)
                    fprintf(stderr, "swap: Failed to allocate %d bytes
of "
                                    "memory for file: %s\n", j,
argv[i]);
                else
                {
                    fread(buffer, sizeof(unsigned char), j, fp);
                    rewind(fp);
                    Swap(buffer, j, argv[i]);
                    fwrite(buffer, sizeof(unsigned char), j, fp);
                    free(buffer);
                }
                fclose(fp);
            }
        }
    }

    setvbuf(stdout, NULL, _IOLBF, NULL);

    return 0;
}

Any information would would be greatly appreciated.

Thanks,

3. Questions on ms dropTarget and vc debuger,need your help

4. Visual C++ 7.1 INTERNAL COMPILER ERROR -- crossposted clc++ and microsoft.public.vstudio.general

// As usual the error message directs one to the report the bug.
//
// And as usual there is absolutely no way to do so without paying for
// the privilege...
//
// Or using three or four hours to find the _current_ reporting page...
//
// Since I'm now using much time on reporting this compiler bug, please
// do also fix the __LINE__ macro.
//
// It does not work with some compiler options, which means e.g. Andrei
// Alexandrescu's ScopeGuard does not compile with this compiler.


#include    <vector>
#include    <iostream>

template< typename T, size_t N >
struct ArrayHolder
{
    T elem[N];
};

template< typename T >
class VectorImpl
{
private:
    std::vector<T> elem;
public:
    template< size_t N >
    VectorImpl( T const (&values)[N] ): elem( values, values+N ) {}

    T& operator[]( size_t i ){ return elem.at( i ); }
    T const& operator[]( size_t i ) const { return elem.at( i ); }
};

template< typename T >
class Vector: public VectorImpl< T >
{
public:
    template< size_t N >

    // This is a bug.  It causes a compiler crash.  That is, an ICE.
    VectorImpl( T const (&values)[N] ): VectorImpl( values ) {}
};

int main()
{
    typedef ArrayHolder<double, 6>  DoubleArray6;
    static DoubleArray6 const   x           = { 10, 20, 30, 40, 50, 60 };
    static DoubleArray6 const   xArray[]    = { x };

    Vector<DoubleArray6> v( xArray );
    for( size_t i = 0; i < 6; ++i )
    {
        std::cout << v[0].elem[i] << std::endl;
    }
}

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?