Slight goof on that post.  The make file I posted didn't have everything set
(it was missing the -lole32 flag to the link).  Here is the correct
makefile:

-----------------
makefile
-----------------
.PHONY: clean all

istreamtest.exe : istreamtest.obj
        gcc -o istreamtest.exe -mwindows -mno-cygwin -lole32 istreamtest.obj

istreamtest.obj : IStreamTest.cpp
        gcc -c -o istreamtest.obj -g -fvtable-thunks -e _mainCRTStartup
istreamtest.cpp

clean :
        rm istreamtest.exe istreamtest.obj

all : istreamtest.exe


-----Original Message-----
From: Paul K Gleske [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 14, 2001 4:40 PM
To: [EMAIL PROTECTED]
Subject: RE: Issue calling Com function(s)


I've made a simple program that isolates the trouble I've been having
getting CreateStreamOnHGlobal to work.  I've included the source file
(IStreamTest.cpp) and the makefile.  As I don't know if this list allows
attachments the files are here in their entirety.

The problem I'm having now is a link issue.  It keeps complaining that
CoInitialize and CreateStreamOnHGlobal are not found.  I wanted to get a
very simple program working in VC and gcc and then I would tackle my big
program.  But, the simple program won't even link now.

BTW, this program works correctly when compiled and linked as a VC++
project.

Thanks for the link to the description of -fvtable-thunk.  However, I don't
think it helps me to understand how/when it should be used.  There is the
comment that all libs must be re-compiled including libgcc.a.  How do I do
that?  Is it really necessary?  How does this vtable-thunk help the call to
the IStream pointer?

tia,

-pkg

-----------------
IStreamTest.cpp
-----------------

// IStreamTest.cpp
//

#define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows
headers
#include <stdio.h>

#include <objbase.h>
#include <ole2.h>

int main(int argc, char* argv[])
{
        printf("Hello World!\n");

    // First init Com
    HRESULT hr = CoInitialize(NULL);

    char data[] = "This is the data for the IStream";

    DWORD  size   = sizeof(data);
    UINT   flags  = LMEM_MOVEABLE | LMEM_NODISCARD | LMEM_ZEROINIT;
    HLOCAL block = ::LocalAlloc(flags, size);

    if (block)  {

        // Load the allocated memory block with data.
        memcpy(LocalLock(block), data, size);
        LocalUnlock(block);

        // Create the stream from the HGlobal
        IStream *is;
        if( hr=CreateStreamOnHGlobal(block, FALSE, &is) == S_OK ) {
            // Now try to use the stream
            STATSTG stats;
            if (is->Stat(&stats, STATFLAG_NONAME) == S_OK )  {
                printf("We were able to get the stats\n");
            }

            // All done, release the stream
            is->Release();
        }
    }

    // Free up the memory block
    if (!block)
        ::LocalFree(block);

        return 0;
}

/// End of IStreamTest.cpp

-----------------
makefile
-----------------
.PHONY: clean all

istreamtest.exe : istreamtest.obj
        gcc -o istreamtest.exe -mwindows -mno-cygwin istreamtest.obj

istreamtest.obj : IStreamTest.cpp
        gcc -c -o istreamtest.obj -g -fvtable-thunks -e _mainCRTStartup
istreamtest.cpp

clean :
        rm istreamtest.exe istreamtest.obj

all : istreamtest.exe


--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple

Reply via email to