public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Calling cygwin32_conv_to_full_win32_path from a MSVC app
@ 2000-01-12 11:55 Gordon Watts (UW Seattle)
  2000-01-24 18:50 ` Mumit Khan
  0 siblings, 1 reply; 5+ messages in thread
From: Gordon Watts (UW Seattle) @ 2000-01-12 11:55 UTC (permalink / raw)
  To: Gnu-Win Cygnus Mailing List

Hi,
  I'm trying to convert from UNIX paths to NT paths inside an app that has
been built under MSVC. I was hoping to do this by pulling in the
cygwin19.dll and then calling the conversion function.
  I can see from the mailing list (I used egroups, which had the best
message interface that I saw, to do the search) that this has been discussed
quite a bit. After an hour of looking I wasn't able to fix the problem. Here
is what I'm doing now.

  Building a console application.

#include <iostream>

extern "C" {
  void dll_noncygin_dllcrt0 (void);
  void cygwin32_conv_to_full_win32_path (const char *cygwin, char *result);
};

int main (void)
{
  char result[1000];
  dll_noncygwin_dllcrt0 ();
  cygwin32_conv_to_full_win32_path ("/d0dist/dist/releases", result);
  std::cout << result << std::endl;
  return 0;
}

I link it against a .lib that I built for the cygwin dll by doing a dumpbin
/exports and then parsing that to make up a .def file. The stacksize in the
def file is 10K and the heapsize is 2k (hmm, let me make that lots bigger --
at 20K still makes the same error). I'm pretty inexperienced with DLLs, so
this could be the problem.

At any rate, when I do the call, it crashes with access violation in the dll
(inside the cygwin32_conv_to_full_win32_path function). Is there anything
obvious I'm doing wrong? Many thanks.

	Cheers,
		Gordon.






--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Calling cygwin32_conv_to_full_win32_path from a MSVC app
  2000-01-12 11:55 Calling cygwin32_conv_to_full_win32_path from a MSVC app Gordon Watts (UW Seattle)
@ 2000-01-24 18:50 ` Mumit Khan
  0 siblings, 0 replies; 5+ messages in thread
From: Mumit Khan @ 2000-01-24 18:50 UTC (permalink / raw)
  To: Gordon Watts (UW Seattle); +Cc: Gnu-Win Cygnus Mailing List

On Wed, 12 Jan 2000, Gordon Watts (UW Seattle) wrote:

> Hi,
>   I'm trying to convert from UNIX paths to NT paths inside an app that has
> been built under MSVC. I was hoping to do this by pulling in the
> cygwin19.dll and then calling the conversion function.
>   I can see from the mailing list (I used egroups, which had the best
> message interface that I saw, to do the search) that this has been discussed
> quite a bit. After an hour of looking I wasn't able to fix the problem. Here
> is what I'm doing now.

You can actually do what you need via a "shim" DLL that is dependent on 
Cygwin. However, you'll need a recent Cygwin DLL (circa 2000-01-06 or so),
otherwise may get seg faults.

The idea is the following:

1. Find the Cygwin calls you need, which in this case are just the path
   conversion routines.

2. Write a Cygwin DLL that exports a set of "WINAPI" functions, which in
   turn call the Cygwin counterparts. The WINAPI/STDCALL is needed to
   load and execute using LoadLibrary/GetProcessAddress duo in the next
   step.

3. From your Mingw/MSVC app, load this DLL using Loadlibrary, and then
   use GetProcAddress to call the exported functions (from step 2), and
   it should work, at least in theory.

This is of course all without doing any testing, so your mileage will
certainly vary.

Here's rough draft of what you may need to do:

Step 2: write the "shim" DLL.

  /* Declare the Cygwin functions that we need. */
  extern int cygwin_conv_to_win32_path (const char *, char *);
  
  /* This is the interface function that non-Cygwin clients call. */
  __declspec(dllexport) __stdcall int
  conv_to_win32_path (const char *cygwin_path, char *win32_path)
  {
    return cygwin_conv_to_win32_path (cygwin_path, win32_path);
  }


Build the DLL using Cygwin GCC:
  
  $ gcc -c shim.c
  $ dllwrap -o shim.dll --target=cygwin32 shim.o

  [ 
    for the next version, you can do the following:
    $ gcc -shared -o shim.dll shim.o
  ]

Now, in your *non-Cygwin* application, you should be able to do the 
following:

  #include <windows.h>
  #include <stdio.h>
  #include <sys/types.h>

  static int
  conv_to_win32_path (const char *cygwin_path, char *win32_path)
  {
    HINSTANCE handle;
    FARPROC func;
    typedef int (* functype) (const char *, char *);

    handle = LoadLibrary ("shim.dll");
    if (! handle)
      return 1;
    
    /* Note the @8. You can of course "alias" it to be without the <n>
       when building the DLL.  */
    func = (functype) GetProcAddress ("conv_to_win32_path@8");
    if (! func)
      return 2;

    return (* func) (cygwin_path, win32_path);
  }
    
  int
  main ()
  {
    const char *cygwin_path = "/usr/local";
    char buf[MAX_PATH];

    conv_to_win32_path (cygwin_path, buf);
    return 0;
  }


This is completely untested, so please blame me if this hoses your machine 
and reformats your hard drive ;-)

Regards,
Mumit



--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: Calling cygwin32_conv_to_full_win32_path from a MSVC app
@ 2000-01-13 21:09 Gordon Watts (UW Seattle)
  0 siblings, 0 replies; 5+ messages in thread
From: Gordon Watts (UW Seattle) @ 2000-01-13 21:09 UTC (permalink / raw)
  To: Gnu-Win Cygnus Mailing List

I've not seen any more traffic on this... does this mean it isn't possible
to call the cygwin dll from a MSVC program to do something like convert a
UNIX style path to an NT one? If there is a FAQ I'm missed, please point me
to it... Many thanks!

	Cheers,
		Gordon.

-----Original Message-----
From: Gordon Watts (UW Seattle) [ mailto:gwatts@fnal.gov ]
Sent: Wednesday, January 12, 2000 1:58 PM
To: earnie_boyd@yahoo.com; Gnu-Win Cygnus Mailing List
Subject: RE: Calling cygwin32_conv_to_full_win32_path from a MSVC app


Hi,
  Thanks. You are correct. I am actually using the b20p1 distribution, but
due to build issues had to rename the dll to 19. I forgot about this when I
wrote the document.

  I was using cygpath for a while. Basically, we have an ENV var that
contains the path, and the scripts have to modify it. Then, when we invoke
the program (often by hand), it is directly, not via a path -- up shot is we
have no place to put the cygpath utility in. And the program we are running
is enough out of my control that I can't change the way it is run. So... I
need to convert the path while I'm running. :(

	Cheers,
		Gordon.

> -----Original Message-----
> From: Earnie Boyd [ mailto:earnie_boyd@yahoo.com ]
> Sent: Wednesday, January 12, 2000 12:12 PM
> To: Gordon Watts (UW Seattle); Gnu-Win Cygnus Mailing List
> Subject: Re: Calling cygwin32_conv_to_full_win32_path from a MSVC app
>
>
> --- "Gordon Watts (UW Seattle)" <gwatts@fnal.gov> wrote:
> > Hi,
> >   I'm trying to convert from UNIX paths to NT paths inside an
> app that has
> > been built under MSVC. I was hoping to do this by pulling in the
> > cygwin19.dll and then calling the conversion function.
>
> Why cygwin B19?!! It's a couple of years old now.
>
> >   I can see from the mailing list (I used egroups, which had the best
> > message interface that I saw, to do the search) that this has
> been discussed
> > quite a bit. After an hour of looking I wasn't able to fix the
> problem. Here
> > is what I'm doing now.
> >
>
> There exists a utility program called cygpath that does this
> already.  I don't
> remember if it was distributed with B19 or not, but it did exist
> in that era
> and it is in the current source tree.
>
> =====
> Earnie Boyd < mailto:earnie_boyd@yahoo.com >
> Cygwin Newbies, please visit
> < http://www.freeyellow.com/members5/gw32/index.html >
> __________________________________________________
> Do You Yahoo!?
> Talk to your friends online with Yahoo! Messenger.
> http://im.yahoo.com
>
>


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: Calling cygwin32_conv_to_full_win32_path from a MSVC app
  2000-01-12 12:13 Earnie Boyd
@ 2000-01-12 14:04 ` Gordon Watts (UW Seattle)
  0 siblings, 0 replies; 5+ messages in thread
From: Gordon Watts (UW Seattle) @ 2000-01-12 14:04 UTC (permalink / raw)
  To: earnie_boyd, Gnu-Win Cygnus Mailing List

Hi,
  Thanks. You are correct. I am actually using the b20p1 distribution, but
due to build issues had to rename the dll to 19. I forgot about this when I
wrote the document.

  I was using cygpath for a while. Basically, we have an ENV var that
contains the path, and the scripts have to modify it. Then, when we invoke
the program (often by hand), it is directly, not via a path -- up shot is we
have no place to put the cygpath utility in. And the program we are running
is enough out of my control that I can't change the way it is run. So... I
need to convert the path while I'm running. :(

	Cheers,
		Gordon.

> -----Original Message-----
> From: Earnie Boyd [ mailto:earnie_boyd@yahoo.com ]
> Sent: Wednesday, January 12, 2000 12:12 PM
> To: Gordon Watts (UW Seattle); Gnu-Win Cygnus Mailing List
> Subject: Re: Calling cygwin32_conv_to_full_win32_path from a MSVC app
>
>
> --- "Gordon Watts (UW Seattle)" <gwatts@fnal.gov> wrote:
> > Hi,
> >   I'm trying to convert from UNIX paths to NT paths inside an
> app that has
> > been built under MSVC. I was hoping to do this by pulling in the
> > cygwin19.dll and then calling the conversion function.
>
> Why cygwin B19?!! It's a couple of years old now.
>
> >   I can see from the mailing list (I used egroups, which had the best
> > message interface that I saw, to do the search) that this has
> been discussed
> > quite a bit. After an hour of looking I wasn't able to fix the
> problem. Here
> > is what I'm doing now.
> >
>
> There exists a utility program called cygpath that does this
> already.  I don't
> remember if it was distributed with B19 or not, but it did exist
> in that era
> and it is in the current source tree.
>
> =====
> Earnie Boyd < mailto:earnie_boyd@yahoo.com >
> Cygwin Newbies, please visit
> < http://www.freeyellow.com/members5/gw32/index.html >
> __________________________________________________
> Do You Yahoo!?
> Talk to your friends online with Yahoo! Messenger.
> http://im.yahoo.com
>
>


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Calling cygwin32_conv_to_full_win32_path from a MSVC app
@ 2000-01-12 12:13 Earnie Boyd
  2000-01-12 14:04 ` Gordon Watts (UW Seattle)
  0 siblings, 1 reply; 5+ messages in thread
From: Earnie Boyd @ 2000-01-12 12:13 UTC (permalink / raw)
  To: Gordon Watts (UW Seattle), Gnu-Win Cygnus Mailing List

--- "Gordon Watts (UW Seattle)" <gwatts@fnal.gov> wrote:
> Hi,
>   I'm trying to convert from UNIX paths to NT paths inside an app that has
> been built under MSVC. I was hoping to do this by pulling in the
> cygwin19.dll and then calling the conversion function.

Why cygwin B19?!! It's a couple of years old now.

>   I can see from the mailing list (I used egroups, which had the best
> message interface that I saw, to do the search) that this has been discussed
> quite a bit. After an hour of looking I wasn't able to fix the problem. Here
> is what I'm doing now.
> 

There exists a utility program called cygpath that does this already.  I don't
remember if it was distributed with B19 or not, but it did exist in that era
and it is in the current source tree.

=====
Earnie Boyd < mailto:earnie_boyd@yahoo.com >
Cygwin Newbies, please visit
< http://www.freeyellow.com/members5/gw32/index.html >
__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2000-01-24 18:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-01-12 11:55 Calling cygwin32_conv_to_full_win32_path from a MSVC app Gordon Watts (UW Seattle)
2000-01-24 18:50 ` Mumit Khan
2000-01-12 12:13 Earnie Boyd
2000-01-12 14:04 ` Gordon Watts (UW Seattle)
2000-01-13 21:09 Gordon Watts (UW Seattle)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).