X-Recipient: archive-cygwin@delorie.com
X-Spam-Check-By: sourceware.org
Date: Thu, 24 Jul 2008 15:26:59 -0400
From: Christopher Faylor <cgf-use-the-mailinglist-please@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: GetProcAddress Problem
Message-ID: <20080724192659.GC7670@ednor.casa.cgf.cx>
Reply-To: cygwin@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
References: <18613133.post@talk.nabble.com> <001401c8ecd8$efd601d0$9601a8c0@CAM.ARTIMI.COM>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <001401c8ecd8$efd601d0$9601a8c0@CAM.ARTIMI.COM>
User-Agent: Mutt/1.5.16 (2007-06-09)
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
Precedence: bulk
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie.com@cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

On Wed, Jul 23, 2008 at 04:29:46PM +0100, Dave Korn wrote:
>Stefano Facchetti wrote on 23 July 2008 16:17:
>
>> How specify in FAQ 6.16 I try to compile this code:
>> 
>> ...
>>  HMODULE h = LoadLibrary("cygwin1.dll");
>>  void (*init)() = GetProcAddress(h, "cygwin_dll_init");
>>  init();
>> ...
>> 
>> The compiler give my the following error:
>> 
>> festivalDll.cc: In function `void festival_init()':
>> festivalDll.cc:18: error: invalid conversion from `int (*)()' to `void
>> (*)()'
>> 
>> How can I do..?
>
>  GetProcAddress returns all function pointers as if they were of type 'int
>(*)()', because it has to return a pointer to some kind of function, but it
>can't know what actual prototype the function has, so it uses the simplest.
>
>  In your program, where you /know/ the actual type of the function, you
>need to cast the result returned from GPA:
>
>  void (*init)() = (void (*)()) GetProcAddress(h, "cygwin_dll_init");

...and this really isn't a Cygwin problem.  It's a combination Windows
API/C comprehension problem.

cgf

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

