delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/06/14/17:09:25

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
From: "Paul K Gleske" <pkg AT gleske DOT org>
To: <cygwin AT cygwin DOT com>
Subject: RE: Issue calling Com function(s)
Date: Thu, 14 Jun 2001 16:58:53 -0400
Message-ID: <NCBBLNOKDKEGJLPOBEJDIEPJGHAA.pkg@gleske.org>
MIME-Version: 1.0
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0)
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
In-Reply-To: <NCBBLNOKDKEGJLPOBEJDKEPIGHAA.pkg@gleske.org>
Importance: Normal

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:pkg AT gleske DOT org]
Sent: Thursday, June 14, 2001 4:40 PM
To: cygwin AT cygwin DOT com
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019