delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/12/31/10:12:34

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00,SPF_PASS
X-Spam-Check-By: sourceware.org
Message-ID: <4B3CC330.3090805@gmail.com>
Date: Thu, 31 Dec 2009 15:28:48 +0000
From: Dave Korn <dave DOT korn DOT cygwin AT googlemail DOT com>
User-Agent: Thunderbird 2.0.0.17 (Windows/20080914)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: Using cygwin headers/libraries in MS compiled programs
References: <001b01ca8a03$90bfe2f0$b23fa8d0$@calgacus.com>
In-Reply-To: <001b01ca8a03$90bfe2f0$b23fa8d0$@calgacus.com>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Neil DOT Mowbray AT calgacus wrote:
> Folks,
> 
> Apologies for the dumb question and  please re-direct if there is a better
> forum.

  Not a dumb question, but in fact a rather subtle and tricky one.

> How do I use cygwin *.h and *.dll in MS console programs?

  The simple answer: you don't.  You write a cygwin console program using gcc
instead.  All the standard windows APIs are available /as well/ as the POSIX
ones, but you avoid mixing the C runtimes and life is very very very much simpler.

  (Why exactly do you want it to be an "MS console program" in the first
place; is it actually necessary to use the VC runtime for some reason?)

> If I include <sys/cygwin.h> in a MS program I get many conflicts between
> the cygwin CRT and MS CRT stuff.  Is my only options to "port" the headers
> to MS and dynamically load the cygwin functions with LoadLibrary()?

  The longer answer: it is possible to dynamically load the cygwin1.dll, but
it is tricky because it requires the stack to be carefully prepared by
reserving some memory space at the top of it.  See "how-cygload.txt" in the
cygwin dll sources for more info.  Note also that this mechanism is little
used and doesn't get a lot of maintenance, so may sometimes suffer some bit-rot.

> What calling conventions do I need for cygwin functions in MS compiled
> code?

  Cygwin uses your bog-standard cdecl; nothing to worry about there.

> All I really want is cygwin_conv_path() so that my MS programs can accept
> cygwin paths.

  This is the sort of simple usage scenario that cygload ought to be able to
handle.  If you have trouble, an alternative option might be ripping the guts
out of the cygpath source and hacking it straight into your code.

  The real question is, what is it you /really/ want to do in the first place?

    cheers,
      DaveK



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

- Raw text -


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