Discussion:
[Libusb-devel] libsub 1.0 for Windows / MSVC
Pete Batard
2010-01-11 23:15:06 UTC
Permalink
(Starting a new thread for this one)

Thanks to Michael's good pointers, I now have a libusb-winusb that
compiles in MSVC9 (Visual Studio 2008), using pthread-win32, and the
executables produced look A-OK.

Some much cleanup is needed before I commit the MSVC patches to the tree
(later today or tomorrow), but I thought I'd just let you know that an
MSVC compatible version is coming your way.

Now, the upcoming version still requires variadic macro support, so I
don't think it'll work with MSVC6, but if people want tackle MSVC6
compatibility and submit a patch, I'd be happy to integrate it in
libusb-winusb (provided it doesn't require too many changes in the core
files).

I'll post an update when the MSVC changes have been committed.

Regards,

/Pete
Pete Batard
2010-01-12 01:44:34 UTC
Permalink
Alright, MSVC9 compatible version now in my tree
(http://code.google.com/p/libusb-winusb-wip/source/detail?r=52).

For compilation information, have a look at the README_MSVC.txt

Please test and report issues.

Regards,

/Pete
Xiaofan Chen
2010-01-12 12:35:56 UTC
Permalink
Post by Pete Batard
Alright, MSVC9 compatible version now in my tree
(http://code.google.com/p/libusb-winusb-wip/source/detail?r=52).
For compilation information, have a look at the README_MSVC.txt
Please test and report issues.
I am using the free Visual Studio Express 2008 version and the
WDK 7600.16385.0. I could not build the solution somehow.

What could be the problem?

1>------ Rebuild All started: Project: libusb-1.0, Configuration:
Release Win32 ------
1>Deleting intermediate and output files for project 'libusb-1.0',
configuration 'Release|Win32'
1>Compiling...
1>core.c
1>windows_usb.c
1>C:\WinDDK\7600.16385.0\inc\api/usbiodef.h(209) : error C2085:
'USB_IDLE_CALLBACK' : not in formal parameter list
1>C:\WinDDK\7600.16385.0\inc\api/usbiodef.h(212) : error C2016: C
requires that a struct or union has at least one member
1>C:\WinDDK\7600.16385.0\inc\api/usbiodef.h(212) : error C2061: syntax
error : identifier 'USB_IDLE_CALLBACK'
1>C:\WinDDK\7600.16385.0\inc\api/usbiodef.h(214) : error C2059: syntax
error : '}'
1>C:\WinDDK\7600.16385.0\inc\api/cfgmgr32.h(925) : warning C4005:
'CM_GETIDLIST_FILTER_BITS' : macro redefinition
1> C:\WinDDK\7600.16385.0\inc\api/cfgmgr32.h(919) : see
previous definition of 'CM_GETIDLIST_FILTER_BITS'
1>windows_compat.c
1>sync.c
1>io.c
1>descriptor.c
1>Build log was saved at
"file://c:\cygwin\home\mcuee\mcu\libusb1win32\libusb-winusb-wip-read-only\Release\BuildLog.htm"
1>libusb-1.0 - 4 error(s), 1 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
--
Xiaofan http://mcuee.blogspot.com
Pete Batard
2010-01-12 14:08:21 UTC
Permalink
Post by Xiaofan Chen
'CM_GETIDLIST_FILTER_BITS' : macro redefinition
1> C:\WinDDK\7600.16385.0\inc\api/cfgmgr32.h(919) : see
previous definition of 'CM_GETIDLIST_FILTER_BITS'
The problem (which I had on my end too), is that for some on Windows 7
(WINVER = 0x600 apparently), both (WINVER >= _WIN32_WINNT_WIN7) and
(WINVER <= _WIN32_WINNT_LONGHORN) conditions appear to be valid at the
same time.

The quick fix I used was to modify cfgmgr32.h to have:

#if (WINVER >= _WIN32_WINNT_WIN7)
#define CM_GETIDLIST_FILTER_TRANSPORTRELATIONS (0x00000080)
#define CM_GETIDLIST_FILTER_PRESENT (0x00000100)
#define CM_GETIDLIST_FILTER_CLASS (0x00000200)
#define CM_GETIDLIST_FILTER_BITS (0x100003FF)
#else if (WINVER <= _WIN32_WINNT_LONGHORN)
#define CM_GETIDLIST_FILTER_BITS (0x1000007F)
#endif

I'm still trying to figure out a fix that does not require modifying
cfgmgr32.h...

Regards,

/Pete
Xiaofan Chen
2010-01-13 11:35:29 UTC
Permalink
Post by Xiaofan Chen
Post by Pete Batard
Alright, MSVC9 compatible version now in my tree
(http://code.google.com/p/libusb-winusb-wip/source/detail?r=52).
For compilation information, have a look at the README_MSVC.txt
Please test and report issues.
I am using the free Visual Studio Express 2008 version and the
WDK 7600.16385.0. I could not build the solution somehow.
It seems that the project is not compatible with Visual C++
2008 Express. I am still having the errors. The warning may have
a fix. But I could not get past the 4 errors.

1>------ Build started: Project: libusb-1.0, Configuration: Debug Win32 ------
1>Compiling...
1>descriptor.c
1>io.c
1>sync.c
1>windows_compat.c
1>windows_usb.c
1>c:\winddk\7600.16385.0\inc\api\usbiodef.h(209) : error C2085:
'USB_IDLE_CALLBACK' : not in formal parameter list
1>c:\winddk\7600.16385.0\inc\api\usbiodef.h(212) : error C2016: C
requires that a struct or union has at least one member
1>c:\winddk\7600.16385.0\inc\api\usbiodef.h(212) : error C2061: syntax
error : identifier 'USB_IDLE_CALLBACK'
1>c:\winddk\7600.16385.0\inc\api\usbiodef.h(214) : error C2059: syntax
error : '}'
1>c:\winddk\7600.16385.0\inc\api\cfgmgr32.h(925) : warning C4005:
'CM_GETIDLIST_FILTER_BITS' : macro redefinition
1> c:\winddk\7600.16385.0\inc\api\cfgmgr32.h(919) : see
previous definition of 'CM_GETIDLIST_FILTER_BITS'
1>core.c
1>Generating Code...
1>Build log was saved at
"file://c:\cygwin\home\mcuee\mcu\libusb1win32\libusb-winusb-wip-read-only\Debug\BuildLog.htm"
1>libusb-1.0 - 4 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


One suggestion is since we need WDK anyway to build libusb-winusb
with Visual C++, we can just create an option to build with WDK C compiler.
This is the approach the libusb-win32 use. You can use either MinGW
or WDK to build libusb-win32.
--
Xiaofan http://mcuee.blogspot.com
Xiaofan Chen
2010-01-13 12:00:19 UTC
Permalink
Post by Pete Batard
Alright, MSVC9 compatible version now in my tree
(http://code.google.com/p/libusb-winusb-wip/source/detail?r=52).
For compilation information, have a look at the README_MSVC.txt
Please test and report issues.
By the way, while I am able to use MinGW to build libusb-winusb, but
there are quite some warnings similar to this one complaining the
unrecognized option `-pthread'.

gcc -DHAVE_CONFIG_H -I. -I.. -std=gnu99 -Wall -Wundef -Wunused -Wstrict-prototy
pes -Werror-implicit-function-declaration -Wshadow -pthread -g -O2 -MT libusb_1_
0_la-descriptor.lo -MD -MP -MF .deps/libusb_1_0_la-descriptor.Tpo -c descriptor.
c -DDLL_EXPORT -DPIC -o .libs/libusb_1_0_la-descriptor.o
gcc.exe: unrecognized option `-pthread'
--
Xiaofan http://mcuee.blogspot.com
Pete Batard
2010-01-13 12:16:06 UTC
Permalink
Post by Xiaofan Chen
By the way, while I am able to use MinGW to build libusb-winusb, but
there are quite some warnings similar to this one complaining the
unrecognized option `-pthread'.
Yes, these are normal, because the -pthread gcc flag (which is different
than -lpthread for the linker) is not implemented in MinGW.
Doesn't hurt the buidling process.

And I'll get back to you on the DDK warning errors, which I had too on
my platform, but simply edited the DDK files to make them go away.

Remember that libusb 1.0 for Windows is still beta software...

Regards,

/Pete
Pete Batard
2010-01-13 13:14:45 UTC
Permalink
Should be fixed in r68.

Please let me know if you see other errors.

Regards,

/Pete
Xiaofan Chen
2010-01-13 14:05:40 UTC
Permalink
Post by Pete Batard
Should be fixed in r68.
Please let me know if you see other errors.
Thanks, now I have no problems building libusb-winusb
and the two examples under Visual C++ 2008 Express Edition.
--
Xiaofan http://mcuee.blogspot.com
Xiaofan Chen
2010-01-14 11:39:08 UTC
Permalink
Post by Pete Batard
Post by Xiaofan Chen
By the way, while I am able to use MinGW to build libusb-winusb, but
there are quite some warnings similar to this one complaining the
unrecognized option `-pthread'.
Yes, these are normal, because the -pthread gcc flag (which is different
than -lpthread for the linker) is not implemented in MinGW.
Doesn't hurt the buidling process.
FYI, I just checked, -pthread is not valid for Cygwin GCC either.

***@AcerPC ~/mcu/libusb1win32/git
$ uname
CYGWIN_NT-6.0

***@AcerPC ~/mcu/libusb1win32/git
$ gcc -pthread
gcc: unrecognized option `-pthread'
gcc: no input files
--
Xiaofan http://mcuee.blogspot.com
Pete Batard
2010-01-14 14:12:52 UTC
Permalink
Post by Xiaofan Chen
FYI, I just checked, -pthread is not valid for Cygwin GCC either.
The -pthread warnings should be removed on MinGW now (git r73).

Regards,

/Pete
Xiaofan Chen
2010-01-14 14:26:24 UTC
Permalink
Post by Pete Batard
Post by Xiaofan Chen
FYI, I just checked, -pthread is not valid for Cygwin GCC either.
The -pthread warnings should be removed on MinGW now (git r73).
Yes there are no more -pthread gcc warnings any more. Thanks.
--
Xiaofan http://mcuee.blogspot.com
Michael Plante
2010-01-12 02:40:42 UTC
Permalink
Is config_msvc.h supposed to be checked in?

Michael



-----Original Message-----
From: Pete Batard [mailto:***@gmail.com]
Sent: Monday, January 11, 2010 7:45 PM
To: libusb-***@lists.sourceforge.net
Subject: Re: [Libusb-devel] libsub 1.0 for Windows / MSVC


Alright, MSVC9 compatible version now in my tree
(http://code.google.com/p/libusb-winusb-wip/source/detail?r=52).

For compilation information, have a look at the README_MSVC.txt

Please test and report issues.

Regards,

/Pete

----------------------------------------------------------------------------
--
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
Pete Batard
2010-01-12 09:40:19 UTC
Permalink
Post by Michael Plante
Is config_msvc.h supposed to be checked in?
Ah shoot! I knew I had to forgot one. Fixed now.
Because of all the new changes, I was planning to do clean compilation
tests on Windows and Linux today anyway. Just wanted to make sure you
guys had something to keep you busy...

Regards,

/Pete
Michael Plante
2010-01-12 04:05:13 UTC
Permalink
Post by Pete Batard
Alright, MSVC9 compatible version now in my tree
(http://code.google.com/p/libusb-winusb-wip/source/detail?r=52).
For compilation information, have a look at the README_MSVC.txt
Please test and report issues.
I've attached a change that allows printb() to be used in v6. It is the
double-parenthesis workaround. This is one of two ways I can think of. I'm
still looking into the usbi_log, etc., stuff, as well as LOOP_CONTINUE.
Looking back at the tracker, apparently Josh Perry had a way around this, so
I wish he had posted his code...



BTW, someone named "Joshua Perry" (with email shown) posted something
related to libusb here:

http://article.gmane.org/gmane.comp.hardware.avr.gcc/4913

Maybe this is the same person?

Thanks,
Michael
Michael Plante
2010-01-12 04:10:37 UTC
Permalink
Post by Michael Plante
Post by Pete Batard
Alright, MSVC9 compatible version now in my tree
(http://code.google.com/p/libusb-winusb-wip/source/detail?r=52).
For compilation information, have a look at the README_MSVC.txt
Please test and report issues.
I've attached a change that allows printb() to be used in v6. It is the
double-parenthesis workaround. This is one of two ways I can think of.

And the other option is attached to THIS email. Any reason to prefer one or
the other?

Michael
Graeme Gill
2010-01-12 04:21:12 UTC
Permalink
Post by Michael Plante
And the other option is attached to THIS email. Any reason to prefer one or
the other?
Using __VA_ARGS__ is neat, but is likely to be less portable. It
may not work with some/all of Microsofts DDK compilers for instance.

Graeme Gill.
Peter Stuge
2010-01-12 07:12:05 UTC
Permalink
Post by Michael Plante
And the other option is attached to THIS email. Any reason to
prefer one or the other?
+++ windows_compat.c (working copy)
-#define printb(...) printf(__VA_ARGS__)
+#define printb printf
I think this is very clean.


//Peter
Pete Batard
2010-01-12 10:16:11 UTC
Permalink
Post by Peter Stuge
Post by Michael Plante
+++ windows_compat.c (working copy)
-#define printb(...) printf(__VA_ARGS__)
+#define printb printf
I think this is very clean.
Simpler is always better - I'm gonna go with that one.

Regards,

/Pete
Michael Plante
2010-01-12 04:35:18 UTC
Permalink
Post by Graeme Gill
Post by Michael Plante
And the other option is attached to THIS email. Any reason to prefer
one or
Post by Graeme Gill
Post by Michael Plante
the other?
Using __VA_ARGS__ is neat, but is likely to be less portable. It
may not work with some/all of Microsofts DDK compilers for instance.
Yes. That patch removes it, just like the other patch. I *think* the
difference between the two patches is whether side effects (like
GetLastError()) still execute. In exchange for them not executing in the
first patch, more lines need to be changed, which takes longer to review.

Michael
Michael Plante
2010-01-12 05:36:56 UTC
Permalink
Post by Pete Batard
Alright, MSVC9 compatible version now in my tree
(http://code.google.com/p/libusb-winusb-wip/source/detail?r=52).
For compilation information, have a look at the README_MSVC.txt
Please test and report issues.
Dunno about Darwin, but I checked out r53, and it doesn't compile in Linux.
This makes it compile:

Index: libusb/os/linux_usbfs.c
===================================================================
--- libusb/os/linux_usbfs.c (revision 53)
+++ libusb/os/linux_usbfs.c (working copy)
@@ -2097,7 +2097,7 @@
continue;

num_ready--;
- list_for_each_entry(handle, &ctx->open_devs, list) {
+ list_for_each_entry(handle, &ctx->open_devs, list, struct
libusb_device_handle) {
hpriv = __device_handle_priv(handle);
if (hpriv->fd == pollfd->fd)
break;
Index: libusb/io.c
===================================================================
--- libusb/io.c (revision 53)
+++ libusb/io.c (working copy)
@@ -1321,7 +1321,7 @@
{
struct usbi_transfer *transfer;

- list_for_each_entry(transfer, &ctx->flying_transfers, list) {
+ list_for_each_entry(transfer, &ctx->flying_transfers, list, struct
usbi_transfer) {
struct timeval *cur_tv = &transfer->timeout;

/* if we've reached transfers of infinite timeout, then we
have no
Pete Batard
2010-01-12 09:59:26 UTC
Permalink
Post by Michael Plante
Dunno about Darwin, but I checked out r53, and it doesn't compile in Linux.
Now fixed in r55 for both Darwin and Linux (and tested with Linux).

Regards
Michael Plante
2010-01-12 06:44:08 UTC
Permalink
I'm still looking into the usbi_log, etc., stuff, as well as
LOOP_CONTINUE.

So it is fixable, and the only changes that need to be made to most of the
source files are to add double-parens. core.c and libusbi.h are the two
that had additional changes, so I am attaching their patches. I have made
patches for all Linux/Win files, and checked (via diff <(old 2>&1) <(new
2>&1)) that lsusb in Linux gives the same results (basically, 25 lines of
debug messages, and 2 lines of output). Summary of changes:

* added a va_list version of usbi_log, and made usbi_log work through
that.
* conditioned some of the changes on the VC version. I used 1200, but I'm
fine with it being a higher number, depending on how 02, 03, 05, and 08
work.
* had to add an additional level of dummy #defines for usbi_info, etc. to
remove the extra parentheses I'm adding when I call them.
* made all calls to these macros have an additional pair of parentheses.

All other changes are Windows only. VC6 does not support __FUNCTION__, so
that was conditionally dropped. Also, why does darwin_usb.c call directly
into _usbi_log()? Anyway...

I have a very similar patch for LOOP_CONTINUE, but it is dependent on this
patch, so I'll send it out later, if this is acceptable. I know Peter
expressed concern about changes to the core; this looks like a lot of stuff,
but most changed lines are just adding parentheses. After applying these
patches, only core.c will compile, but it compiles on both Windows and
Linux. I have patches that fix the rest, too, but I don't want to clutter
this email.

Michael
Nathan Hjelm
2010-01-12 07:04:43 UTC
Permalink
Post by Michael Plante
I'm still looking into the usbi_log, etc., stuff, as well as
LOOP_CONTINUE.
So it is fixable, and the only changes that need to be made to most of the
source files are to add double-parens. core.c and libusbi.h are the two
that had additional changes, so I am attaching their patches. I have made
patches for all Linux/Win files, and checked (via diff <(old 2>&1) <(new
2>&1)) that lsusb in Linux gives the same results (basically, 25 lines of
* added a va_list version of usbi_log, and made usbi_log work through
that.
* conditioned some of the changes on the VC version. I used 1200, but I'm
fine with it being a higher number, depending on how 02, 03, 05, and 08
work.
* had to add an additional level of dummy #defines for usbi_info, etc. to
remove the extra parentheses I'm adding when I call them.
* made all calls to these macros have an additional pair of parentheses.
All other changes are Windows only. VC6 does not support __FUNCTION__, so
that was conditionally dropped. Also, why does darwin_usb.c call directly
into _usbi_log()? Anyway...
I really can't recall why I use _usbi_log. I can't see the reason why I chose not to use the usbi_info, usbi_warn, and usbi_err macros.

Anyway, I am a little confused (I tend to delete any email with the word Windows in the subject though recently I have been enjoying this back and forth). Does Visual C not support ISO C99 (which defines variadic macros)? Why is there a need to move away from using variadic macros? Is this just another of many reasons why anything made by MS sucks?

-Nathan
Peter Stuge
2010-01-12 07:13:41 UTC
Permalink
VC6 does not support __FUNCTION__, so that was conditionally
dropped.
What about __func__ ?


//Peter
Pete Batard
2010-01-12 10:30:10 UTC
Permalink
Post by Michael Plante
I'm still looking into the usbi_log, etc., stuff, as well as
LOOP_CONTINUE.
I have a very similar patch for LOOP_CONTINUE (...)
Guys, if LOOP_CONTINUE is proving too troublesome to address for MSVC6,
I'm willing to ditch the macro altogether.
As long as logging is working, reverting to usbi_warn() + continue,
instead of a single macro call, is OK with me.

My only fear is that, if we get full MSVC6 support, we might get a lot
more requests to get libusb 1.0 for Windows working on older platforms
like Win2k, or even 98... ;)

Regards,

/Pete
Graeme Gill
2010-01-12 11:02:44 UTC
Permalink
Post by Pete Batard
My only fear is that, if we get full MSVC6 support, we might get a lot
more requests to get libusb 1.0 for Windows working on older platforms
like Win2k, or even 98... ;)
Win2K is doable (with the libusb-win32 kernel driver), but I
wouldn't imagine 98 is a prospect, given that it's based
on Win3.1 rather than WinNT, although it does support
the WinNT driver model (yes, I know you were kind of joking" :-)

Graeme Gill.
Xiaofan Chen
2010-01-12 11:58:31 UTC
Permalink
Post by Graeme Gill
Post by Pete Batard
My only fear is that, if we get full MSVC6 support, we might get a lot
more requests to get libusb 1.0 for Windows working on older platforms
like Win2k, or even 98... ;)
Win2K is doable (with the libusb-win32 kernel driver), but I
wouldn't imagine 98 is a prospect, given that it's based
on Win3.1 rather than WinNT, although it does support
the WinNT driver model (yes, I know you were kind of joking" :-)
Yeah, WinUSB does not work for Windows 98SE, ME and
Windows 2000. I believe libusb-win32 works under Windows
98SE and ME. But I have not used them since 2004.
--
Xiaofan http://mcuee.blogspot.com
Graeme Gill
2010-01-12 13:06:21 UTC
Permalink
Post by Xiaofan Chen
Yeah, WinUSB does not work for Windows 98SE, ME and
Windows 2000. I believe libusb-win32 works under Windows
98SE and ME. But I have not used them since 2004.
libusb-win32 works for 2000, 2003, XP, Vista and Win7.

Graeme Gil.
Xiaofan Chen
2010-01-12 13:48:42 UTC
Permalink
Post by Graeme Gill
Post by Xiaofan Chen
Yeah, WinUSB does not work for Windows 98SE, ME and
Windows 2000. I believe libusb-win32 works under Windows
98SE and ME. But I have not used them since 2004.
libusb-win32 works for 2000, 2003, XP, Vista and Win7.
I believe it also works under 98SE and ME. libusb-win32
device driver works under Vista 32 and Win7 32bit. But
for 64bit Vista and Windows 7, you have to have the
digital signature check disabled to use libusb-win32
device driver.

libusb-win32 filter driver is known to cause many problems
under Vista and Windows 7, and even in XP sometimes.
--
Xiaofan http://mcuee.blogspot.com
Graeme Gill
2010-01-12 22:58:27 UTC
Permalink
Post by Xiaofan Chen
for 64bit Vista and Windows 7, you have to have the
digital signature check disabled to use libusb-win32
device driver.
Self Signing is a more practical workaround, since
it has less impact on the normal security measures,
and you don't have to remember to hit F8 on every boot.

Graeme Gill.
Tim Roberts
2010-01-12 23:46:21 UTC
Permalink
Post by Graeme Gill
Post by Xiaofan Chen
for 64bit Vista and Windows 7, you have to have the
digital signature check disabled to use libusb-win32
device driver.
Self Signing is a more practical workaround, since
it has less impact on the normal security measures,
and you don't have to remember to hit F8 on every boot.
Self-signing can suppress the "this driver is unsigned warning" at
install time, but I don't believe it helps at all with the 64-bit KMCS
requirement. Those are two very different processes.
--
Tim Roberts, ***@probo.com
Providenza & Boekelheide, Inc.
Graeme Gill
2010-01-13 00:40:00 UTC
Permalink
Post by Tim Roberts
Self-signing can suppress the "this driver is unsigned warning" at
install time, but I don't believe it helps at all with the 64-bit KMCS
requirement. Those are two very different processes.
It doesn't suppress warnings, it makes it installable.

I've followed this
<http://nil-techno.blogspot.com/2008/08/installing-unsigned-drivers-on-vista-64.html>
as a guide, and it worked fine (on Vista 64, haven't tried Win7 64 yet).

Graeme Gill.
Peter Stuge
2010-01-13 00:37:24 UTC
Permalink
Post by Xiaofan Chen
Post by Graeme Gill
libusb-win32 works for 2000, 2003, XP, Vista and Win7.
I believe it also works under 98SE and ME. libusb-win32
device driver works under Vista 32 and Win7 32bit. But
for 64bit Vista and Windows 7, you have to have the
digital signature check disabled to use libusb-win32
device driver.
libusb-win32 filter driver is known to cause many problems
under Vista and Windows 7, and even in XP sometimes.
I think the WinUSB backend should have fairly high priority over
using the libusb-win32 device drivers. I consider the filter driver a
very special case that we at least should not encourage. With WinUSB
and libusb-win32 device driver backends I think we will have come
very far!


//Peter
Xiaofan Chen
2010-01-13 01:36:17 UTC
Permalink
Post by Peter Stuge
Post by Xiaofan Chen
Post by Graeme Gill
libusb-win32 works for 2000, 2003, XP, Vista and Win7.
I believe it also works under 98SE and ME. libusb-win32
device driver works under Vista 32 and Win7 32bit. But
for 64bit Vista and Windows 7, you have to have the
digital signature check disabled to use libusb-win32
device driver.
libusb-win32 filter driver is known to cause many problems
under Vista and Windows 7, and even in XP sometimes.
I think the WinUSB backend should have fairly high priority over
using the libusb-win32 device drivers. I consider the filter driver a
very special case that we at least should not encourage. With WinUSB
and libusb-win32 device driver backends I think we will have come
very far!
Agreed. WinUSB should be the first priority. Another backend
to consider is the HID backend due to the fact there are many
pseudo-HID device out there and they tend to be driven under
Linux by libusb/libhid based programs. If there is an HID backend
for Windows (and maybe Mac OS X), then we do not need to
deal with the driver installation issues (to "upgrade" the native
HID driver to libusb/winusb under Windows or use the codeless
kext under Mac OS X). This would benefit libhid project as well.

As for the filter driver, it is kind of "not recommended" any more
or "deprecated" as per past mailing list posts in the libusb-win32
mailing list.
--
Xiaofan http://mcuee.blogspot.com
Peter Stuge
2010-01-13 01:07:25 UTC
Permalink
Post by Pete Batard
My only fear is that, if we get full MSVC6 support, we might get a
lot more requests to get libusb 1.0 for Windows working on older
platforms like Win2k, or even 98... ;)
Maybe someone would also be interested in helping to add it. I think
it will already be a fantastic accomplishment to have the WinUSB
support finished, and I believe that it will be enough for many.
Not saying 2k is unimportant, just that WinUSB is the best first
step. I think support for the older systems will come eventually.


//Peter
Pete Batard
2010-01-12 12:59:25 UTC
Permalink
Isn't there something else that could be achieved for MSVC6 through the
use of <stdarg.h>
Just to clarify what I meant above (since the logging functions already
use make use of stdarg), can't stdarg be used all the way to remove the
need for double parenthesis in MSVC6, by redefining some of the macros
as inlines or something?
Pete Batard
2010-01-12 12:30:39 UTC
Permalink
Post by Michael Plante
this looks like a lot of stuff,
but most changed lines are just adding parentheses.
OK, I've been pondering about these patches for the last couple hours,
and I would rather like to avoid this double parenthesis business in
every log call, unless there is absolutely no other way.

Personally, I find this workaround to be a bit too obvious to be
comfortable with it, and I'm not aware of any other open source project
displaying something that screams "compiler limitation" as much as this
(but I suppose most other open source projects don't bother that much
about MSVC6 compatibility). If we go with this, everybody who's new to
the libusb source won't help but wonder about this counter-intuitive
need for double parenthesis in all the log function calls...

Isn't there something else that could be achieved for MSVC6 through the
use of <stdarg.h>
(http://msdn.microsoft.com/en-us/library/aa273077%28VS.60%29.aspx)?
Surely there must be more than one way to tackle the variadic macros
issue in MSVC6...

Regards,

/Pete
Graeme Gill
2010-01-12 23:59:49 UTC
Permalink
Post by Pete Batard
OK, I've been pondering about these patches for the last couple hours,
and I would rather like to avoid this double parenthesis business in
every log call, unless there is absolutely no other way.
Personally, I find this workaround to be a bit too obvious to be
comfortable with it, and I'm not aware of any other open source project
displaying something that screams "compiler limitation" as much as this
(but I suppose most other open source projects don't bother that much
about MSVC6 compatibility). If we go with this, everybody who's new to
As I mentioned before, wxWidgets supports VC6 and they are a highly C++
based open source project.

Personally I use the double parenthesis, as I don't see it as a big
deal (a small price paid for portability). A workaround with some
disadvantages is:

#ifdef DEBUG
#define eprintf printf
#else
#define eprintf //
#endif

int main() {

eprintf ("This is a test %d.\n",56);


The disadvantages being that // is not portable (some C compilers
may not support it), and that the eprintf has to be on one line.

Graeme Gill.
Michael Plante
2010-01-12 07:18:03 UTC
Permalink
Post by Nathan Hjelm
Anyway, I am a little confused (I tend to delete any email with the word
Windows in the subject

:-)
Post by Nathan Hjelm
Does Visual C not support ISO C99 (which defines variadic macros)? Why is
there a need to move away from using variadic macros?

The first release of VC6 predates C99 by a year, so they have an excuse
there. AFAIK, 2002 and 2003 also don't support it, but 2008 (what Pete is
using) does. I don't know about 2005. To answer your second question,
there's only a need if we want to support pre-2008 (pre-2005?) versions of
MSVC.
Post by Nathan Hjelm
Is this just
another of many reasons why anything made by MS sucks?
They have a *few* nice features I'd like to see emulated elsewhere.

Michael
Michael Plante
2010-01-12 07:20:45 UTC
Permalink
Post by Peter Stuge
VC6 does not support __FUNCTION__, so that was conditionally
dropped.
What about __func__ ?
I tried that too. Unfortunately, my fix couldn't use it even if it was
supported, due to the way the macro arguments are handled. E.g., while VC6
supports __FILE__ and __LINE__, I can't use them with the fix for the
variadic macros, as the macros basically aren't allowed to add anything that
wasn't in the "c" file. This drop in functionality should only affect VC6
builds, the way I've #ifdefed it.

Michael
Michael Plante
2010-01-12 16:27:02 UTC
Permalink
Post by Xiaofan Chen
Yeah, WinUSB does not work for Windows 98SE, ME and
Windows 2000. I believe libusb-win32 works under Windows
98SE and ME. But I have not used them since 2004.
Eh, well, the point of having multiple Windows backends was to support
things like the libusb-win32 driver, rather than WinUSB, right? That said,
I only see a point in supporting NT-based systems, and I can only test 2k+.

Michael
Michael Plante
2010-01-12 16:27:04 UTC
Permalink
Post by Pete Batard
Post by Michael Plante
this looks like a lot of stuff,
but most changed lines are just adding parentheses.
OK, I've been pondering about these patches for the last couple hours,
and I would rather like to avoid this double parenthesis business in
every log call, unless there is absolutely no other way.
If anyone has suggestions. I should point out that suggestions can be
tested in other compilers: just change the #ifdef temporarily and make sure
your suggestion doesn't use __VA_ARGS__.
Post by Pete Batard
Personally, I find this workaround to be a bit too obvious to be
obvious? Do you mean not obvious enough, based on the rest of the
paragraph?
Post by Pete Batard
displaying something that screams "compiler limitation" as much as this
Well, the patch does, and libusbi.h does, but I think most people will gloss
over the changes to the source files.
Post by Pete Batard
(but I suppose most other open source projects don't bother that much
about MSVC6 compatibility).
Other projects may have bothered from the start. One example that avoids it
that I see occasionally is to produce, in analogy, usbi_info0, usbi_info1,
usbi_info2, etc., depending on the number of varargs. Gcc has an extension
that checks printf-style formatting (which we should have been using anyway,
though #ifdefed on whether gcc is available...maybe I'll submit a patch at
some point), so that will catch most errors in the usage, provided the
compile is tested on gcc.
Post by Pete Batard
If we go with this, everybody who's new to
the libusb source won't help but wonder about this counter-intuitive
need for double parenthesis in all the log function calls...
I think there are far more interesting/complicated interactions than
logging, and the functions/macros still do what they say they do.
Post by Pete Batard
Isn't there something else that could be achieved for MSVC6 through the
use of <stdarg.h>
(http://msdn.microsoft.com/en-us/library/aa273077%28VS.60%29.aspx)?
Surely there must be more than one way to tackle the variadic macros
issue in MSVC6...
Assuming you mean getting rid of macros entirely (as seems implied by your
later email) : let me look into it. It was late at night, and I may have
missed a cleaner option. There might be a way that defines usbi_log
multiple ways, but removes the need to change all the macro references. It
would still disallow use of __FUNCTION__/etc. (nothing I can do), but I
could #ifdef it again. No promises, though.

BTW, can someone confirm what _MSC_VER is on 2002, 2003, 2005, 2008? I did
it by guessing bounds, and then manually binary searching with the #error
preprocessor directive.

Michael
Pete Batard
2010-01-12 17:21:06 UTC
Permalink
Hi Michael,
Post by Michael Plante
Post by Pete Batard
Personally, I find this workaround to be a bit too obvious to be
obvious? Do you mean not obvious enough, based on the rest of the
paragraph?
Was a poor choice of word on my end. I had written "in-your-face"
initially but then I tried to tone it down a bit... "bit of an eyesore"
would have been more appropriate.
This was by no means a criticism of your code, just my view that
multiple parentheses do not result in elegant code. But I must admit
that I keep a grudge against parentheses ever since I took Lisp...
Post by Michael Plante
Other projects may have bothered from the start. One example that avoids it
that I see occasionally is to produce, in analogy, usbi_info0, usbi_info1,
usbi_info2, etc., depending on the number of varargs.
Yes, I've seen that one too, and personally, I think I would be more
happy with numbered versions and single parentheses, but I want to hear
what other think
Post by Michael Plante
I think there are far more interesting/complicated interactions than
logging, and the functions/macros still do what they say they do.
I agree with that, and if there's no other way, I'll go with it in my
branch (no idea if the main branch will go with it though). Still, I
don't want to commit something that's impacting a lot of lines of codes
without making sure first that there's no other way.
Post by Michael Plante
Assuming you mean getting rid of macros entirely (as seems implied by your
later email) : let me look into it. It was late at night, and I may have
missed a cleaner option. There might be a way that defines usbi_log
multiple ways, but removes the need to change all the macro references. It
would still disallow use of __FUNCTION__/etc. (nothing I can do), but I
could #ifdef it again. No promises, though.
OK. I'll have a look at it on my end too.
Post by Michael Plante
BTW, can someone confirm what _MSC_VER is on 2002, 2003, 2005, 2008?
1500 (decimal) for 2008.

Regards,

/Pete
Michael Plante
2010-01-12 16:51:06 UTC
Permalink
Post by Pete Batard
Guys, if LOOP_CONTINUE is proving too troublesome to address for MSVC6,
I'm willing to ditch the macro altogether.
As long as logging is working, reverting to usbi_warn() + continue,
instead of a single macro call, is OK with me.
Well, I did have a way to keep LOOP_CONTINUE, actually, but it involves
(line 71-ish):

-#define LOOP_CONTINUE(...) { usbi_warn(ctx, __VA_ARGS__); continue; }
+#define LOOP_CONTINUE(x) { usbi_warn(x); continue; }

which requires things like this (line 387-ish):

-LOOP_CONTINUE("program assertion failed - found more than %d buses,
skipping the rest.", LIBUSB_BUS_MAX);
+LOOP_CONTINUE((ctx, "program assertion failed - found more than %d buses,
skipping the rest.", LIBUSB_BUS_MAX));

This works, but it may still be too ugly, based on your other email. Note
that ctx had to be added. I don't know that LOOP_CONTINUE is any easier to
read than the suggestion you just gave, so food for thought.

Michael
Michael Plante
2010-01-12 17:32:21 UTC
Permalink
Post by Pete Batard
Post by Michael Plante
Assuming you mean getting rid of macros entirely (as seems implied by
your
Post by Pete Batard
Post by Michael Plante
later email) : let me look into it. It was late at night, and I may
have
Post by Pete Batard
Post by Michael Plante
missed a cleaner option. There might be a way that defines usbi_log
multiple ways, but removes the need to change all the macro references.
It
Post by Pete Batard
Post by Michael Plante
would still disallow use of __FUNCTION__/etc. (nothing I can do), but I
could #ifdef it again. No promises, though.
OK. I'll have a look at it on my end too.
It looks like it'll work (cleaning up my last file, windows_usb.c, but all
the others compile in MSVC6 now w/o double-parentheses). All c files may
now need to include stdarg.h; not sure yet. I'll test on Linux and then
send it over.

Thanks,
Michael
Michael Plante
2010-01-12 17:52:57 UTC
Permalink
Post by Michael Plante
Post by Pete Batard
Post by Michael Plante
Assuming you mean getting rid of macros entirely (as seems implied
by your
Post by Michael Plante
Post by Pete Batard
Post by Michael Plante
later email) : let me look into it. It was late at night, and I
may have
Post by Michael Plante
Post by Pete Batard
Post by Michael Plante
missed a cleaner option. There might be a way that defines usbi_log
multiple ways, but removes the need to change all the macro
references. It
Post by Michael Plante
Post by Pete Batard
Post by Michael Plante
would still disallow use of __FUNCTION__/etc. (nothing I can do),
but I
Post by Michael Plante
Post by Pete Batard
Post by Michael Plante
could #ifdef it again. No promises, though.
OK. I'll have a look at it on my end too.
It looks like it'll work (cleaning up my last file, windows_usb.c, but
all the others compile in MSVC6 now w/o double-parentheses). All c files
may
Post by Michael Plante
now need to include stdarg.h; not sure yet. I'll test on Linux and then
send it over.

These patches should replace the previous two. Note that I have not yet
sent a fix for LOOP_CONTINUE...still looking for feedback on your preference
there. I can send a patch for it, if you want, but if you plan to get rid
of the macro, I won't. It turns out that MSCV6 does not complain if
stdarg.h is missing, so I did not add it to the other source files. If
later versions need it, you might have to add it.

Michael
Pete Batard
2010-01-12 18:56:38 UTC
Permalink
Post by Michael Plante
These patches should replace the previous two.
Excellent work. Now committed to r59.
Post by Michael Plante
Note that I have not yet
sent a fix for LOOP_CONTINUE...still looking for feedback on your preference
there.
What does the LOOP_CONTINUE patch look like? I guess I'll decide if I
want to remove LOOP_CONTINUE depending on the complexity of this patch,
or if I get the vibe that the code would be better off without
LOOP_CONTINUE.

Replacing all the LOOP_CONTINUE's is a 1 minute operation anyway, so no
big deal.

Regards,

/Pete
Michael Plante
2010-01-12 19:11:33 UTC
Permalink
Post by Pete Batard
Post by Michael Plante
Note that I have not yet
sent a fix for LOOP_CONTINUE...still looking for feedback on your
preference
Post by Pete Batard
Post by Michael Plante
there.
What does the LOOP_CONTINUE patch look like? I guess I'll decide if I
want to remove LOOP_CONTINUE depending on the complexity of this patch,
or if I get the vibe that the code would be better off without
LOOP_CONTINUE.
Replacing all the LOOP_CONTINUE's is a 1 minute operation anyway, so no
big deal.
Attached. Whatever you prefer.

Thanks,
Michael
Pete Batard
2010-01-12 20:27:48 UTC
Permalink
Post by Michael Plante
Post by Michael Plante
LOOP_CONTINUE.
Attached. Whatever you prefer.
You could just have said it used double parentheses, and that would have
settled it ;) Search and replace it is!

I'll apply your xusb.c fix though...
Pete Batard
2010-01-12 20:42:03 UTC
Permalink
r62. Any more changes needed for MSVC6?
Peter Stuge
2010-01-12 21:13:39 UTC
Permalink
+++ windows_usb.c (working copy)
@@ -68,7 +68,7 @@
// The 3 macros below are used in conjunction with safe loops.
#define LOOP_CHECK(fcall) { r=fcall; if (r != LIBUSB_SUCCESS) continue; }
-#define LOOP_CONTINUE(...) { usbi_warn(ctx, __VA_ARGS__); continue; }
+#define LOOP_CONTINUE(x) { usbi_warn x; continue; }
Doesn't this call to usbi_warn need () or even (()) around x?
@@ -377,7 +377,7 @@
// Will need to change storage and size of libusb_bus_t if this ever occurs
if (bus == LIBUSB_BUS_MAX) {
- LOOP_CONTINUE("program assertion failed - found more than %d buses, skipping the rest.", LIBUSB_BUS_MAX);
+ LOOP_CONTINUE((ctx, "program assertion failed - found more than %d buses, skipping the rest.", LIBUSB_BUS_MAX));
}
I for one don't like this. Hiding a bunch of formatting goo in a
macro is one thing, but I think statements which affect the code
flow, such as continue, should not be in a macro.

I don't know how widely used LOOP_CONTINUE() is so this might just be
a very minor problem, but that's how I feel anyway. It goes for
LOOP_CHECK as well.

Also, I like to make macros according to:

#define MACRO(stuff) do { otherstuff("this", (stuff), "that"); } while(0)

So that the macro can always be used like a function call. Also
remember to add () around macro parameters in order to avoid
unintentional effects.

Since this uses do..while it's also not possible to have continue
inside. I see that as a feature. :)


//Peter
Michael Plante
2010-01-12 20:17:52 UTC
Permalink
Hi Pete,

Also, here is the logging patch for xusb.c . It can be shortened if you
don't care about fprintf's return value.

Michael
Michael Plante
2010-01-12 20:58:36 UTC
Permalink
Post by Pete Batard
r62. Any more changes needed for MSVC6?
Merged. Minor things:

* there are 14 compiler warnings I might want to clean up (signed/unsigned,
as well as integer size mismatch)

* my ddk includes are still different from yours, and I had to change your
#ifdef to get USB_HUB_CAPABILITIES_EX, though these are both likely a
consequence of DDK version, rather than Visual Studio version. I didn't
consider it a high priority right now...

* someone still needs to test with 02/03/05 and see if my 1200 needs
adjustment upwards.


Major things:

* It lacks a project file for MSVC6 (*.dsp, *.dsw; replaces your *.vcproj,
*.sln, respectively, function-wise). If you do a "dir/s" in the root of
your working copy from a command window AFTER BUILDING all configurations in
2008, and email me the output off-list, I'll make sure my project outputs go
into the same directory. It would also be helpful if you'd tell me exactly
which compiler/linker switches get used so I can match those more closely,
as your project file doesn't seem to show this (apparently vcproj only shows
differences from defaults, rather than a full list of switches).

* I am building a DLL, but I could build a static library instead. To build
the DLL, either changes need to be made to the source to export the
functions, or else a .DEF file must be added. I am attaching the .DEF file,
as that would require no changes to the source.

Michael
Peter Stuge
2010-01-12 21:17:20 UTC
Permalink
Post by Michael Plante
* I am building a DLL, but I could build a static library instead.
Could both be built in one go?
Post by Michael Plante
To build the DLL, either changes need to be made to the source to
export the functions, or else a .DEF file must be added. I am
attaching the .DEF file, as that would require no changes to the
source.
Hm. Could it be generated at release time? Same for dsp, dsw, vcproj,
sln?


//Peter
Peter Stuge
2010-01-13 01:36:29 UTC
Permalink
Post by Michael Plante
Post by Pete Batard
r62. Any more changes needed for MSVC6?
Merged.
Since more developers are getting into the winusb code I'm happy
to add some personal git repos on git.libusb.org if you think it
could help, e.g. you might more easily be able to share code. (And
you would push directly, no reviews needed unless you ask for them.)
(I should've done this for Pete already way back when.) Takers simply
email me your public SSH2 key and prefered username.


//Peter
Pete Batard
2010-01-13 11:14:33 UTC
Permalink
Post by Peter Stuge
Since more developers are getting into the winusb code I'm happy
to add some personal git repos on git.libusb.org
I think it makes sense to have everything hosted on git.libusb.org (and
hopefully it'll help with merging changes to the main tree).

Before we create these private repositories, I wouldn't mind pushing the
current version I have on SVN to the git libusb-winusb repo, so that it
can then be cloned for everyone. How do you think we should do that? Or
would it be easier to have the svn code a private repo first and then
merge with libusb-winusb?

Also, the windows_usb.c is pretty big as it contains the generic code as
well as the WinUSB API calls, and if we add other APIs like HID, etc,
it'll become more difficult to maintain.
I'd like to break it down in 3 files to separate the generic calls from
the WinUSB API (if we're consistant, we need a 3rd file for the "dummy"
API). But this means a multiplication of windows related files in the
os/ directory...

Finally, as it's likely that we're at least going to try to add HID to
the Windows backend, I'm not sure "libusb-winusb" is still fitting for
the main windows branch. But then again, since the plan is to have the
development windows branch merged with main eventually, it doesn't
matter that much.

Regards,

/Pete
Michael Plante
2010-01-12 21:21:35 UTC
Permalink
Post by Peter Stuge
+++ windows_usb.c (working copy)
@@ -68,7 +68,7 @@
// The 3 macros below are used in conjunction with safe loops.
#define LOOP_CHECK(fcall) { r=fcall; if (r != LIBUSB_SUCCESS)
continue; }
Post by Peter Stuge
-#define LOOP_CONTINUE(...) { usbi_warn(ctx, __VA_ARGS__); continue; }
+#define LOOP_CONTINUE(x) { usbi_warn x; continue; }
Doesn't this call to usbi_warn need () or even (()) around x?
The patch is correct in this regard. It DID need one set of parens when
usbi_warn was defined to always use (()). It needs none when usbi_warn is
defined closer to how it is in the main git tree, since the extra set of
parens go in the usage of the LOOP_CONTINUE macro. In any case, the patch
wasn't applied: Pete removed the macro in r63.

Michael
Michael Plante
2010-01-12 21:31:06 UTC
Permalink
Post by Peter Stuge
Post by Michael Plante
* I am building a DLL, but I could build a static library instead.
Could both be built in one go?
Yes. We do need to discuss what they're named, because they can't have the
same name if they're built to the same output directory. The trouble is
that the .LIB extension has two very different meanings, one as a support
file for DLLs, and one as the actual static library itself, and they're not
even remotely interchangable.
Post by Peter Stuge
Post by Michael Plante
To build the DLL, either changes need to be made to the source to
export the functions, or else a .DEF file must be added. I am
attaching the .DEF file, as that would require no changes to the
source.
Hm. Could it be generated at release time? Same for dsp, dsw, vcproj,
sln?
dsp, dsw, vcproj, and sln can be generated by programs like "premake".
However, premake appears to have dropped support for vc6 in version 4, so
release 3.7 would be needed:

http://premake.sourceforge.net/

I've used premake scripts before (for the Open Dynamics Engine project), but
never written one.

But I don't think it's likely that the .DEF file could be generated. The
trouble is that DLLs only export symbols you tell the compiler/linker to
export. There are two ways to do that:

1) add an attribute to the function definition AND prototype

2) write a .DEF file

2 has the advantage of no changes to core files. 1 has the advantage that a
new function that should be exported is less likely to be overlooked by
non-Windows devs. You have to add _declspec(dllexport) to both the
prototype and definition when building the library, and _declspec(dllimport)
to the prototype when building something that uses the library. This is
almost always done with a #define so that the same header (libusb.h) can be
used for both apps and internal use. And the #define has to be nothing for
the static lib and for all Linux uses. This is uglier than
double-parentheses, in my opinion, but your call...

I don't think any of this .DEF stuff is a v6 issue. It's either an MSVC
issue in general, or a Windows issue in general. It's been this way even in
win3.x days, and possibly before.

Michael
Peter Stuge
2010-01-12 23:21:20 UTC
Permalink
Post by Michael Plante
Post by Peter Stuge
Post by Michael Plante
* I am building a DLL, but I could build a static library instead.
Could both be built in one go?
Yes. We do need to discuss what they're named, because they can't
have the same name if they're built to the same output directory.
Right, I know the lib vs dll vs lib situation. A subdirectory for
each type would be an easy solution. I think that's fine.
Post by Michael Plante
Post by Peter Stuge
Post by Michael Plante
To build the DLL, either changes need to be made to the source to
export the functions, or else a .DEF file must be added.
..
Post by Michael Plante
Post by Peter Stuge
Hm. Could it be generated at release time? Same for dsp, dsw,
vcproj, sln?
dsp, dsw, vcproj, and sln can be generated by programs like "premake".
However, premake appears to have dropped support for vc6 in version 4,
http://premake.sourceforge.net/
I've used premake scripts before (for the Open Dynamics Engine
project), but never written one.
I was thinking even simpler. libssh2 has a make rule to generate dsp
from a header and footer. It seems to work well, but I don't know if
the other files are more (too) complicated.
Post by Michael Plante
The trouble is that DLLs only export symbols you tell the
1) add an attribute to the function definition AND prototype
2) write a .DEF file
Nod. http://www.willus.com/mingw/yongweiwu_stdcall.html gives a nice
overview of Windows library circumstances.
Post by Michael Plante
I don't think any of this .DEF stuff is a v6 issue. It's either an
MSVC issue in general, or a Windows issue in general.
Originally MSVC in general but since MinGW can also deal with them I
guess now it's Windows in general. :)

We may not be able to avoid adding keywords to all declarations and
definitions if we want our exported functions to use the __stdcall
calling convention rather than __cdecl - I think __stdcall is nice
since it would allow libusb to be used by as many DLL consumers as
possible.

http://gcc.gnu.org/wiki/Visibility is also interesting although it
assumes C++, but it has some ready-made declspec macros.


//Peter
Michael Plante
2010-01-13 02:03:28 UTC
Permalink
Post by Michael Plante
* It lacks a project file for MSVC6 (*.dsp, *.dsw; replaces your
*.vcproj, *.sln, respectively, function-wise). If
Post by Michael Plante
you do a "dir/s" in the root of your working copy from a command window
AFTER BUILDING all configurations in 2008,
Post by Michael Plante
and email me the output off-list, I'll make sure my project outputs go
into the same directory. It would also be
Post by Michael Plante
helpful if you'd tell me exactly which compiler/linker switches get used
so I can match those more closely, as your
Post by Michael Plante
project file doesn't seem to show this (apparently vcproj only shows
differences from defaults, rather than a full list of switches).

To summarize:
You have most intermediate files going into "Debug" and "Release"
subdirectories of either the project root or the examples directory. I
believe the debugger won't work properly for the examples, IIRC, as the
.idb/.pdb files have the same name regardless of which executable is being
built. I can come up with an alternative name, probably along the lines of
lsusb__Debug , etc.

You have the example .exe's in examples/ (same dir as source). This appears
to mean that only a debug or release build can exist at one time, or else we
need to suffix the executables. The static .lib also appears to be in the
same directory as the source (libusb/).

I had initially been planning on conforming my outputs to yours, but in
order to support all the configurations, the above is a problem. Things
will be even more complicated if the samples use the DLL rather than the
static LIB, since Windows has to know where to find the DLL, so I think the
samples will be built to use the static LIB.

Unless you feel strongly, I think what I'll do is put

1) intermediate files and final EXEs in directories like
examples/lsusb__Debug
2) intermediate files and final DLLs in directories like libusb/dll__Debug
(along with the import libraries)
3) intermediate files and final static LIBs in directories like
libusb/lib__Debug

and link the examples statically. Any changes/improvements before I
proceed? Should these be further identified as msvc outputs, as opposed to
mingw?

Michael
Peter Stuge
2010-01-13 02:22:11 UTC
Permalink
Post by Michael Plante
Unless you feel strongly, I think what I'll do is put
1) intermediate files and final EXEs in directories like
examples/lsusb__Debug
2) intermediate files and final DLLs in directories like libusb/dll__Debug
(along with the import libraries)
3) intermediate files and final static LIBs in directories like
libusb/lib__Debug
and link the examples statically. Any changes/improvements before
I proceed? Should these be further identified as msvc outputs, as
opposed to mingw?
MinGW should end up building just like on *IX, so it might be a good
idea to specify these as being msvc.

Would the following be awkward?

1) msvc/examples__Debug (just one dir, not per example)
2) msvc/libusb_dll__Debug
3) msvc/libusb_lib__Debug


//Peter
Pete Batard
2010-01-13 02:31:38 UTC
Permalink
Post by Michael Plante
You have most intermediate files going into "Debug" and "Release"
subdirectories of either the project root or the examples directory. I
believe the debugger won't work properly for the examples, IIRC, as the
.idb/.pdb files have the same name regardless of which executable is being
built.
This is configurable, at least in 2008, and one of my last fixes
addressed that by using "$(TargetDir)$(ProjectName).pdb" (with
projectname being either lsusb or xusb). Hoping the same can be done for
MSVC6, if not, we can use harcoded names.
Post by Michael Plante
You have the example .exe's in examples/ (same dir as source). This appears
to mean that only a debug or release build can exist at one time, or else we
need to suffix the executables. The static .lib also appears to be in the
same directory as the source (libusb/).
Yes. I'm trying to get close to the original output directories.
Don't think many people would be impacted by not having Debug and
Release executables at the same time, but if there's a justification for
it, I'll go with whatever seems appropriate.
Post by Michael Plante
I had initially been planning on conforming my outputs to yours, but in
order to support all the configurations, the above is a problem. Things
will be even more complicated if the samples use the DLL rather than the
static LIB, since Windows has to know where to find the DLL, so I think the
samples will be built to use the static LIB.
I have to stress out that I created the .sln/vcproj files very quickly,
and without giving too much consideration to what convention Visual
Studio developers might follow. In fact, I've was trying to get as close
as possible to what GNU make would produce, which is probably not the
best way to approach MSVC output.

I'll be fine with the choices you mentionned, or what Peter suggests in
his reply (considering the number of files generated by MSVC, starting
with an msvc directory might not be a bad idea), but I'd still like to
wait a little to see if other people have a different opinion on where
the MSVC output should go.

Regards,

/Pete
Michael Plante
2010-01-13 01:32:13 UTC
Permalink
Post by Peter Stuge
Post by Michael Plante
Post by Peter Stuge
Post by Michael Plante
* I am building a DLL, but I could build a static library instead.
Could both be built in one go?
Yes. We do need to discuss what they're named, because they can't
have the same name if they're built to the same output directory.
Right, I know the lib vs dll vs lib situation. A subdirectory for
each type would be an easy solution. I think that's fine.
I can do that, but that may not solve everything. The trouble is still what
name to choose, assuming a user might want to copy both .LIB files into
their LIB/ directory for use in other projects. I do that with
pthreadVC2d.lib (don't recall how specific that name is to my build), for
example. Even if no one does that, I would still want to decorate the debug
version with a "d" on the end. E.g., libusb1d.dll, libusb1.dll for
debug/release. Any thoughts here?
Post by Peter Stuge
I was thinking even simpler. libssh2 has a make rule to generate dsp
from a header and footer. It seems to work well, but I don't know if
the other files are more (too) complicated.
I'll have to come back to this.
Post by Peter Stuge
We may not be able to avoid adding keywords to all declarations and
definitions if we want our exported functions to use the __stdcall
calling convention rather than __cdecl - I think __stdcall is nice
since it would allow libusb to be used by as many DLL consumers as
possible.
http://gcc.gnu.org/wiki/Visibility is also interesting although it
assumes C++, but it has some ready-made declspec macros.
So we will use __stdcall and not use a .DEF file, right? This ready-made
code is almost what I need, but it lacks an #ifdef for building a static
lib. I can fix that pretty easily. So we'll have two #defines passed on
the compiler command line: LIBUSB_SOURCE and BUILDING_DLL . The latter
implies the former, so there are 3 possibilties. Apps define neither. I
can probably throw the __stdcall attribute into those macros, as well.
Would it be difficult to pull API_EXPORTED out of config.h and force it into
this role, or should I leave that alone?

Michael
Peter Stuge
2010-01-13 03:08:16 UTC
Permalink
Post by Michael Plante
Post by Peter Stuge
Right, I know the lib vs dll vs lib situation. A subdirectory for
each type would be an easy solution. I think that's fine.
I can do that, but that may not solve everything. The trouble is
still what name to choose, assuming a user might want to copy both
.LIB files into their LIB/ directory for use in other projects. I
do that with pthreadVC2d.lib (don't recall how specific that name
is to my build), for example. Even if no one does that, I would
still want to decorate the debug version with a "d" on the end.
E.g., libusb1d.dll, libusb1.dll for debug/release. Any thoughts
here?
I don't develop in Windows at all, except maybe using MinGW, so I
don't know what the common/smart patterns are for MSVC. :\

Debug/release are usually different targets for applications, right?
So it would be OK to have different filenames for libraries, and they
could co-exist in the same directory. This seems good enough to me,
for switching between static and dynamic libraries it would be
neccessary to change the linker path.

But then the final output dir should be the same both for Debug and
Release builds - does that work if the target names are different?
I guess not because of the idb/pdb files.

So it ends up being one directory per target and build type. Or?
Post by Michael Plante
Post by Peter Stuge
generate dsp
I'll have to come back to this.
Absolutely. Agree it's not the most important problem.
Post by Michael Plante
Post by Peter Stuge
We may not be able to avoid adding keywords to all declarations and
definitions if we want our exported functions to use the __stdcall
calling convention rather than __cdecl - I think __stdcall is nice
since it would allow libusb to be used by as many DLL consumers as
possible.
http://gcc.gnu.org/wiki/Visibility is also interesting although it
assumes C++, but it has some ready-made declspec macros.
So we will use __stdcall and not use a .DEF file, right?
I am not absolutely opposed to a .DEF but if we must add __stdcall in
the code then we might as well add the declspec too. I don't know if
we could get __stdcall without changes in the code?
Post by Michael Plante
LIBUSB_SOURCE and BUILDING_DLL . The latter implies the former, so
there are 3 possibilties. Apps define neither. I can probably throw
the __stdcall attribute into those macros, as well.
Sounds good.
Post by Michael Plante
Would it be difficult to pull API_EXPORTED out of config.h and
force it into this role, or should I leave that alone?
It would be great to be able to re-use it! How do you generate
config.h for MSVC? (It's normally created by the configure script.)


//Peter
Michael Plante
2010-01-13 02:34:05 UTC
Permalink
Post by Peter Stuge
Would the following be awkward?
1) msvc/examples__Debug (just one dir, not per example)
2) msvc/libusb_dll__Debug
3) msvc/libusb_lib__Debug
2&3 are fine.

1 *might* work for the finished files, but I have to stick the intermediate
files elsewhere (because of vc60.idb, vc60.pdb, which lack the target name
in their name). Or maybe it's the other way around. Either way, that
leaves the question of what to call the directories for #1 that have to be
separate.

Michael
Peter Stuge
2010-01-13 02:44:20 UTC
Permalink
Post by Michael Plante
Post by Peter Stuge
Would the following be awkward?
1) msvc/examples__Debug (just one dir, not per example)
2) msvc/libusb_dll__Debug
3) msvc/libusb_lib__Debug
2&3 are fine.
1 *might* work for the finished files, but I have to stick the
intermediate files elsewhere (because of vc60.idb, vc60.pdb, which
lack the target name in their name).
Ah! So it has to be one directory per target. Maybe mix our ideas:

msvc/examples/lsusb__Debug


//Peter
Michael Plante
2010-01-13 02:35:46 UTC
Permalink
Post by Pete Batard
This is configurable, at least in 2008, and one of my last fixes
addressed that by using "$(TargetDir)$(ProjectName).pdb" (with
projectname being either lsusb or xusb). Hoping the same can be done for
MSVC6, if not, we can use harcoded names.
Let me try that and see if I can make Peter's structure work.

Michael
Michael Plante
2010-01-13 02:49:29 UTC
Permalink
Post by Peter Stuge
msvc/examples/lsusb__Debug
Will do. Turns out what Pete suggested still won't help. There are TWO pdb
files output: target.pdb (whatever target is) and vc60.pdb. Then there's
vc60.idb. I have no idea what that's all about.

Michael
Michael Plante
2010-01-13 03:25:17 UTC
Permalink
Post by Peter Stuge
Post by Michael Plante
I can do that, but that may not solve everything. The trouble is
still what name to choose, assuming a user might want to copy both
.LIB files into their LIB/ directory for use in other projects. I
do that with pthreadVC2d.lib (don't recall how specific that name
is to my build), for example. Even if no one does that, I would
still want to decorate the debug version with a "d" on the end.
E.g., libusb1d.dll, libusb1.dll for debug/release. Any thoughts
here?
I don't develop in Windows at all, except maybe using MinGW, so I
don't know what the common/smart patterns are for MSVC. :\
This does cause a linker warning on the debug DLL build (different
filename), when combined with the .DEF file, but if we remove the .DEF file,
no big deal. The idea here is that a dev may want to copy both .dll's to
the system32 directory to avoid having to copy them to every project's
output directory they're used in. In this case, the .dll's need to have
different names.
Post by Peter Stuge
But then the final output dir should be the same both for Debug and
Release builds - does that work if the target names are different?
I guess not because of the idb/pdb files.
I think you're right.
Post by Peter Stuge
So it ends up being one directory per target and build type. Or?
Yes, though if you don't care about debugging, we could at least
theoretically dump all final outputs in the same directory. I do care about
debugging, though.
Post by Peter Stuge
Post by Michael Plante
So we will use __stdcall and not use a .DEF file, right?
I am not absolutely opposed to a .DEF but if we must add __stdcall in
the code then we might as well add the declspec too. I don't know if
we could get __stdcall without changes in the code?
If you want all functions, exported or not, (except those with variable
args; _cdecl has the caller clean up the stack, which is required for
variable argument functions) to use __stdcall, there's a compiler switch:
/Gz . This would not require any code changes. Would you prefer that?
Post by Peter Stuge
Post by Michael Plante
LIBUSB_SOURCE and BUILDING_DLL . The latter implies the former, so
there are 3 possibilties. Apps define neither. I can probably throw
the __stdcall attribute into those macros, as well.
Sounds good.
I'll hold off until we decide on DEF or not.
Post by Peter Stuge
Post by Michael Plante
Would it be difficult to pull API_EXPORTED out of config.h and
force it into this role, or should I leave that alone?
It would be great to be able to re-use it! How do you generate
config.h for MSVC? (It's normally created by the configure script.)
./configure assumes a functional scripting environment (bash). DOS batch
files are not powerful enough. What Pete has done for now is just check the
final output into svn as config_msvc.h, and then #ifdef which one to
#include based on whether _MSC_VER is defined. What I'm recommending here
for Windows (and this assumes no .def file) is to put /D API_EXPORTED=? into
the project settings. In Linux, the autotools stuff would be modified to
put that in CFLAGS or whatever, rather than config.h. I'm very lousy with
autotools, so someone else would have to do it.

And then the #ifdefs would have to go in libusb.h, not libusbi.h. Not as
clean, but it has advantages. In any case, I think I'll submit a version
that uses the .DEF first w/o __stdcall, and then we can come back and change
it, since that's what I already have. Don't want to commit too many changes
in one rev.

Michael
Michael Plante
2010-01-13 03:32:44 UTC
Permalink
In any case, I think I'll submit a version that uses the .DEF first w/o
__stdcall, and then we can come back and change it, since that's what I
already have. Don't want to commit too many changes in one rev.
Ok, it matters where these files go:

libusb-winusb-wip/libusb1.dsw
libusb-winusb-wip/libusb/libusb1_*.dsp
libusb-winusb-wip/examples/lsusb.dsp
libusb-winusb-wip/examples/xusb.dsp



And these are the final results:

libusb-winusb-wip\msvc\dll__Debug\libusb-1.0d.dll
libusb-winusb-wip\msvc\dll__Debug\libusb-1.0d.lib
libusb-winusb-wip\msvc\dll__Release\libusb-1.0.dll
libusb-winusb-wip\msvc\dll__Release\libusb-1.0.lib
libusb-winusb-wip\msvc\examples\lsusb__Debug\lsusb.exe
libusb-winusb-wip\msvc\examples\lsusb__Release\lsusb.exe
libusb-winusb-wip\msvc\examples\xusb__Debug\xusb.exe
libusb-winusb-wip\msvc\examples\xusb__Release\xusb.exe
libusb-winusb-wip\msvc\lib__Debug\libusb-1.0d.lib
libusb-winusb-wip\msvc\lib__Release\libusb-1.0.lib

Anything I should fix?

Thanks,
Michael
Pete Batard
2010-01-14 18:31:40 UTC
Permalink
Post by Michael Plante
libusb-winusb-wip\msvc\dll__Debug\libusb-1.0d.dll
libusb-winusb-wip\msvc\dll__Debug\libusb-1.0d.lib
libusb-winusb-wip\msvc\dll__Release\libusb-1.0.dll
libusb-winusb-wip\msvc\dll__Release\libusb-1.0.lib
libusb-winusb-wip\msvc\examples\lsusb__Debug\lsusb.exe
libusb-winusb-wip\msvc\examples\lsusb__Release\lsusb.exe
libusb-winusb-wip\msvc\examples\xusb__Debug\xusb.exe
libusb-winusb-wip\msvc\examples\xusb__Release\xusb.exe
libusb-winusb-wip\msvc\lib__Debug\libusb-1.0d.lib
libusb-winusb-wip\msvc\lib__Release\libusb-1.0.lib
OK, I'm looking at trying to apply this patch and following the struct
above for Visual Studio 2008 as well.

1. Why the double underscore? Not that I really mind, but is that a
convention or something?

2. I think having both the debug lib produced in a separate directory
and having a "d" added at the end is a bit redundant (especially as the
same is not done for the examples). Personally, I'd ditch the "d" from
the debug libraries.

3. I'm kind of wondering if we'd not be better of starting with a
Release & Debug directories at the top libusb-winusb-wip\Debug,
libusb-winusb-wip\Release and then working our way down to
subdirectories if needed (dll, lib, examples).

I think this is closer to where MSVC users who are new to libusb would
expect to find their files in the first place.

So the structure I'd have in mind would be:

libusb-winusb-wip\Debug\dll\libusb-1.0.dll
libusb-winusb-wip\Debug\dll\libusb-1.0.lib
libusb-winusb-wip\Debug\lib\libusb-1.0.lib
libusb-winusb-wip\Debug\examples\lsusb.exe
libusb-winusb-wip\Debug\examples\xusb.exe
libusb-winusb-wip\Release\dll\libusb-1.0.dll
libusb-winusb-wip\Release\dll\libusb-1.0.lib
libusb-winusb-wip\Release\lib\libusb-1.0.lib
libusb-winusb-wip\Release\examples\lsusb.exe
libusb-winusb-wip\Release\examples\xusb.exe

Would such a directory structure cause a problem with MSVC6?

Regards,

/Pete
Pete Batard
2010-01-14 19:11:18 UTC
Permalink
Post by Pete Batard
libusb-winusb-wip\Debug\examples\lsusb.exe
libusb-winusb-wip\Debug\examples\xusb.exe
libusb-winusb-wip\Release\examples\lsusb.exe
libusb-winusb-wip\Release\examples\xusb.exe
Oh, and if needed, I'd create an intermediate directory (xusb_int,
lsusb_int) for the intermediate files of the executables above
Peter Stuge
2010-01-15 01:00:51 UTC
Permalink
Post by Pete Batard
libusb-winusb-wip\Debug\dll\libusb-1.0.dll
libusb-winusb-wip\Debug\dll\libusb-1.0.lib
libusb-winusb-wip\Debug\lib\libusb-1.0.lib
libusb-winusb-wip\Debug\examples\lsusb.exe
libusb-winusb-wip\Debug\examples\xusb.exe
libusb-winusb-wip\Release\dll\libusb-1.0.dll
libusb-winusb-wip\Release\dll\libusb-1.0.lib
libusb-winusb-wip\Release\lib\libusb-1.0.lib
libusb-winusb-wip\Release\examples\lsusb.exe
libusb-winusb-wip\Release\examples\xusb.exe
I'd like there to be an msvc directory before Debug and Release.
Post by Pete Batard
Oh, I'm not 100% positive, but it may (not sure) be important for
the dsp/dsw files to be CRLF.
Yes, it is.

About the CRLF question I would prefer to keep everything in git
LF-only.

The options in git for automatically converting to/from CRLF could
be used by developers working from git source on Windows. (All files
have CRLF, but only LF is stored in git.)

I imagine that releases will be created and packaged on a *ix system.
Then there could be a script to ensure CRLF for the files that really
require it. Tarball and zip packages, targeted for *ix and Windows
respectively. Should they have different contents? Ie. .zip has CRLF?

It might be nifty to also have an NSIS installer for developers on
Windows. NSIS can run on *ix and still generate the exe installer.
If the zip has CRLF for all files then so should the installer.


Comments?

//Peter
Graeme Gill
2010-01-15 01:16:08 UTC
Permalink
Post by Peter Stuge
I imagine that releases will be created and packaged on a *ix system.
Then there could be a script to ensure CRLF for the files that really
require it. Tarball and zip packages, targeted for *ix and Windows
respectively. Should they have different contents? Ie. .zip has CRLF?
In my experience there is no need to create source or system
files with CRLF for MSWindows, although information files that
the user is likely to open with Notepad (or equivalent) probably
should.

Graeme Gill.
Orin Eman
2010-01-15 02:06:39 UTC
Permalink
Post by Graeme Gill
Post by Peter Stuge
I imagine that releases will be created and packaged on a *ix system.
Then there could be a script to ensure CRLF for the files that really
require it. Tarball and zip packages, targeted for *ix and Windows
respectively. Should they have different contents? Ie. .zip has CRLF?
In my experience there is no need to create source or system
files with CRLF for MSWindows, although information files that
the user is likely to open with Notepad (or equivalent) probably
should.
If the filename ends in .txt, it should have CRLF IMO. Especially the
Windows readme file which almost certainly will be opened in Notepad!

Orin.
Pete Batard
2010-01-15 02:34:43 UTC
Permalink
Post by Orin Eman
If the filename ends in .txt, it should have CRLF IMO. Especially the
Windows readme file which almost certainly will be opened in Notepad!
The current README_msvc.txt does, but then again, the git tree is aimed
at developers, not end users, and how many developers do we expect to
use still use Notepad as their default text editor?

I don't really think end-user readmes, that are not related to
development, need to go into the development tree. As a matter of fact,
the readme and binary files for the WinUSB driver installation are not
in git and currently provided as an entirely separate zip file
(http://libusb-winusb-wip.googlecode.com/files/winusb%20driver.zip)

Regards,

/Pete
Pete Batard
2010-01-15 01:49:57 UTC
Permalink
Post by Peter Stuge
I'd like there to be an msvc directory before Debug and Release.
OK. I can live with that too.
Post by Peter Stuge
About the CRLF question I would prefer to keep everything in git
LF-only.
That's what I've been striving to do (and had a couple botched commits
with). The (non explicitely named) r71 git revision was all about
removing CR/LFs inconsistencies in the source.
Post by Peter Stuge
The options in git for automatically converting to/from CRLF could
be used by developers working from git source on Windows. (All files
have CRLF, but only LF is stored in git.)
Currently I have AutoCrLf set in TortoiseGit. Can't set SafeCrLf as
there seems to be a bug that prevents any commits when set (at least on
Windows 7 x64)
Post by Peter Stuge
It might be nifty to also have an NSIS installer for developers on
Windows.
I don't think that's a priority for now, but why not.

Regards,

/Pete
Pete Batard
2010-01-15 12:52:45 UTC
Permalink
Post by Peter Stuge
Post by Pete Batard
libusb-winusb-wip\Debug\dll\libusb-1.0.dll
libusb-winusb-wip\Debug\dll\libusb-1.0.lib
libusb-winusb-wip\Debug\lib\libusb-1.0.lib
libusb-winusb-wip\Debug\examples\lsusb.exe
libusb-winusb-wip\Debug\examples\xusb.exe
libusb-winusb-wip\Release\dll\libusb-1.0.dll
libusb-winusb-wip\Release\dll\libusb-1.0.lib
libusb-winusb-wip\Release\lib\libusb-1.0.lib
libusb-winusb-wip\Release\examples\lsusb.exe
libusb-winusb-wip\Release\examples\xusb.exe
I'd like there to be an msvc directory before Debug and Release.
Actually, I think instead of msvc we should use win32 and x64 (and yes,
I'm currently playing with x64 compilation in MSVC).

Regards,

/Pete
Pete Batard
2010-01-15 14:24:28 UTC
Permalink
Post by Pete Batard
Post by Peter Stuge
I'd like there to be an msvc directory before Debug and Release.
Actually, I think instead of msvc we should use win32 and x64 (and yes,
I'm currently playing with x64 compilation in MSVC).
Ok, here is the final structure I have on my end:

libusb-winusb-wip\Win32\Debug\dll\libusb-1.0_debug.dll
libusb-winusb-wip\Win32\Debug\dll\libusb-1.0_debug.lib
libusb-winusb-wip\Win32\Debug\lib\libusb-1.0.lib
libusb-winusb-wip\Win32\Debug\examples\lsusb.exe
libusb-winusb-wip\Win32\Debug\examples\xusb.exe
libusb-winusb-wip\Win32\Release\dll\libusb-1.0.dll
libusb-winusb-wip\Win32\Release\dll\libusb-1.0.lib
libusb-winusb-wip\Win32\Release\lib\libusb-1.0.lib
libusb-winusb-wip\Win32\Release\examples\lsusb.exe
libusb-winusb-wip\Win32\Release\examples\xusb.exe

libusb-winusb-wip\x64\Debug\dll\libusb-1.0_debug.dll
libusb-winusb-wip\x64\Debug\dll\libusb-1.0_debug.lib
libusb-winusb-wip\x64\Debug\lib\libusb-1.0.lib
libusb-winusb-wip\x64\Debug\examples\lsusb.exe
libusb-winusb-wip\x64\Debug\examples\xusb.exe
libusb-winusb-wip\x64\Release\dll\libusb-1.0.dll
libusb-winusb-wip\x64\Release\dll\libusb-1.0.lib
libusb-winusb-wip\x64\Release\lib\libusb-1.0.lib
libusb-winusb-wip\x64\Release\examples\lsusb.exe
libusb-winusb-wip\x64\Release\examples\xusb.exe

with intermediate files going to an
"libusb-winusb-wip\x64\Release\lib\libusb-1.0\" or
"libusb-winusb-wip\Win32\Debug\dll\libusb-1.0_debug\", etc. directory
through the use of:
($(SolutionDir)$(PlatformName)\$(ConfigurationName)\<lib|examples>\$(ProjectName)

Win32 and x64 come from the $(PlatformName) MSVC config variable, so I
would prefer keeping these names if possible.

I have now managed to compile and run x64 executables (with the static
library), and everything looks good.

I did have to recompile the pthread-win32 for CVS to produce an x64 dll
and library though...

/Pete
Peter Stuge
2010-01-15 19:39:30 UTC
Permalink
Post by Pete Batard
libusb-winusb-wip\Win32\Debug\dll\libusb-1.0_debug.dll
libusb-winusb-wip\x64\Debug\dll\libusb-1.0_debug.dll
libusb-winusb-wip\x64\Debug\dll\libusb-1.0_debug.lib
libusb-winusb-wip\x64\Debug\lib\libusb-1.0.lib
libusb-winusb-wip\x64\Debug\examples\lsusb.exe
libusb-winusb-wip\x64\Debug\examples\xusb.exe
libusb-winusb-wip\x64\Release\dll\libusb-1.0.dll
I still want msvc at the top level, since there are other ways to
build for win32 and x86_64 (is MS actually calling it x64?) which has
nothing to do with these directories. I expect both MinGW and Cygwin
to build using the same directories as *ix.


//Peter
Orin Eman
2010-01-15 19:54:10 UTC
Permalink
Post by Peter Stuge
Post by Pete Batard
libusb-winusb-wip\Win32\Debug\dll\libusb-1.0_debug.dll
libusb-winusb-wip\x64\Debug\dll\libusb-1.0_debug.dll
libusb-winusb-wip\x64\Debug\dll\libusb-1.0_debug.lib
libusb-winusb-wip\x64\Debug\lib\libusb-1.0.lib
libusb-winusb-wip\x64\Debug\examples\lsusb.exe
libusb-winusb-wip\x64\Debug\examples\xusb.exe
libusb-winusb-wip\x64\Release\dll\libusb-1.0.dll
I still want msvc at the top level, since there are other ways to
build for win32 and x86_64 (is MS actually calling it x64?) which has
nothing to do with these directories. I expect both MinGW and Cygwin
to build using the same directories as *ix.
Yes, MS Visual Studio defaults to x64. Most WDKs (including the current
Win7 WDK) use amd64 instead of x64. You'd be a little more like Visual
Studio defaults if you used Win32\x64\Debug and Win32\x64\Release for the
x64 versions.

Orin.
Pete Batard
2010-01-15 20:02:50 UTC
Permalink
Post by Peter Stuge
I still want msvc at the top level
At this stage, I thing adding msvc on top of it is one directory too
many. It's a long enough arborescence as it is, just to fetch a file, so
I'm against it. msvc should only be used for msvc additional headers and
files.
Post by Peter Stuge
since there are other ways to
build for win32 and x86_64 (is MS actually calling it x64?) which has
nothing to do with these directories.
Yes, the default are x64 and Win32. As Orin points out, you also get
amd64 in the DDK but that's not really relevant here.

My point of view is that non-regular MSVC users like myself will expect
the files to end up in either a Debug, Release, x64 or Win32 directory
at the top level, because that's pretty much the default when you create
a new project with MSVC. I'd rather go for the masses than the classes,
as I think it's messy enough as it is...

If I'm new to the library, and I see x64 or Win32 at the root level, I'd
be pretty sure this is where I have to look for the files. On the other
hand, a directory like msvc that already contains .h files wouldn't be
my first choice...
Post by Peter Stuge
I expect both MinGW and Cygwin
to build using the same directories as *ix.
They do.

Regards,

/Pete

Michael Plante
2010-01-13 03:58:43 UTC
Permalink
Post by Michael Plante
Post by Peter Stuge
Post by Michael Plante
So we will use __stdcall and not use a .DEF file, right?
I am not absolutely opposed to a .DEF but if we must add __stdcall in
the code then we might as well add the declspec too. I don't know if
we could get __stdcall without changes in the code?
If you want all functions, exported or not, (except those with variable
args; _cdecl has the caller clean up the stack, which is required for
/Gz . This would not require any code changes. Would you prefer that?

Ooh. This may still not work. How does a program using the DLL know to use
__stdcall when calling the functions (or perhaps the opposite is true, and
it's people who use _cdecl who have problems)? The decoration is hardly
foolproof, as you've pointed out, and it may even be too late by the time it
gets to the linker. I think we probably will still need a #define symbol.
Making it explicit that way may be safest. But I really don't know. In any
case, I'll wait to hear back on the dsp/dsw files before I mess with the
declspec stuff.

Michael
Michael Plante
2010-01-13 16:14:44 UTC
Permalink
Post by Pete Batard
Finally, as it's likely that we're at least going to try to add HID to
the Windows backend, I'm not sure "libusb-winusb" is still fitting for
the main windows branch. But then again, since the plan is to have the
development windows branch merged with main eventually, it doesn't
matter that much.
Well, additionally, we should think ahead about what the function names and
file names would be for using libusb0.sys . I don't really care where
"template" goes, but windows_usb.c is already as long as linux_usbfs.c, and
longer than darwin_usb.c. We might move the back-back-ends into a separate
file. I'm not terribly familiar with git, but I heard that moving stuff
from file to file is well-handled in the git revision history, since git
doesn't really care which file stuff is in. Yes/no? I know from experience
that SVN is very lousy at that, so perhaps splitting should wait until after
the repo change?

Michael
Pete Batard
2010-01-13 17:48:12 UTC
Permalink
Post by Michael Plante
Well, additionally, we should think ahead about what the function names and
file names would be for using libusb0.sys .
My view on that was, if we're gonna have our own driver in 1.0, we might
as well provide something that's API compatible with WinUSB. So I was
thinking about creating a DLL that exposes the exact same functions as
WinUSB.dll (and maybe adds some for isochronous, etc.), and translates
them to libusb0.sys IOCTLs.

I haven't given it much thought yet, but I believe this would keep
everybody happy (it would in effect provide "WinUSB" on older platforms).
Post by Michael Plante
I don't really care where
"template" goes, but windows_usb.c is already as long as linux_usbfs.c, and
longer than darwin_usb.c.
I know! While I probably have a good part to play for length of this
source, gotta love the simplicity of Microsoft's USB API compared to
other platforms... ;)
Post by Michael Plante
We might move the back-back-ends into a separate
file. I'm not terribly familiar with git, but I heard that moving stuff
from file to file is well-handled in the git revision history, since git
doesn't really care which file stuff is in. Yes/no? I know from experience
that SVN is very lousy at that, so perhaps splitting should wait until after
the repo change?
Roger.

Regards,

/Pete
Michael Plante
2010-01-13 18:20:25 UTC
Permalink
Post by Pete Batard
Post by Michael Plante
Well, additionally, we should think ahead about what the function names
and
Post by Pete Batard
Post by Michael Plante
file names would be for using libusb0.sys .
My view on that was, if we're gonna have our own driver in 1.0, we might
as well provide something that's API compatible with WinUSB. So I was
thinking about creating a DLL that exposes the exact same functions as
WinUSB.dll (and maybe adds some for isochronous, etc.), and translates
them to libusb0.sys IOCTLs.
I haven't studied it enough to know if there's a one-for-one translation,
but that sounds like a good option if it works. We'd still have to name the
DLL something different, particularly for platforms that have both (such as
mine...XP 32-bit). But I figured this was the point of the API_CALL macro
and its replacement, so unless you want to totally dispense with the
additional level of abstraction...
Post by Pete Batard
I haven't given it much thought yet, but I believe this would keep
everybody happy (it would in effect provide "WinUSB" on older platforms).
Wasn't there discussion in the past about WinUSB not providing certain
features, like isochronous transfers? I can't test that, having only an
FT2232D (bulk and control only), but I just wanted to see if those would be
supported with the libusb0.sys back-back-end.


Michael
Michael Plante
2010-01-14 20:44:39 UTC
Permalink
Post by Pete Batard
Post by Michael Plante
libusb-winusb-wip\msvc\dll__Debug\libusb-1.0d.dll
libusb-winusb-wip\msvc\dll__Debug\libusb-1.0d.lib
libusb-winusb-wip\msvc\dll__Release\libusb-1.0.dll
libusb-winusb-wip\msvc\dll__Release\libusb-1.0.lib
libusb-winusb-wip\msvc\examples\lsusb__Debug\lsusb.exe
libusb-winusb-wip\msvc\examples\lsusb__Release\lsusb.exe
libusb-winusb-wip\msvc\examples\xusb__Debug\xusb.exe
libusb-winusb-wip\msvc\examples\xusb__Release\xusb.exe
libusb-winusb-wip\msvc\lib__Debug\libusb-1.0d.lib
libusb-winusb-wip\msvc\lib__Release\libusb-1.0.lib
1. Why the double underscore? Not that I really mind, but is that a
convention or something?
It is a convention (see below). We could do single-underscore. I think the
idea is that some projects might have a single underscore in the name, so
this stands out better to the eye. I'll switch to single, though, if you
want.
Post by Pete Batard
2. I think having both the debug lib produced in a separate directory
and having a "d" added at the end is a bit redundant (especially as the
same is not done for the examples). Personally, I'd ditch the "d" from
the debug libraries.
No, because it matters when you copy the DLLs (by themselves, of course) to
the system32 directory, or the import libraries to your compiler's LIB
directory. I usually do this as a post-build step in my own builds (done it
with pthreads, libftdi, libusb-0.1, and lib3ds, to name a few), though I
didn't here, since not everyone wants them copied. But I agree it's
unnecessary for the static libraries, since those using static libraries are
probably only using them in one or two places, whereas DLLs are likely to be
needed by a lot of stuff, which is the point of having a DLL. If you want
me to take the "d" suffix off of "lib__Debug", that would be fine.

Basically, it's equivalent to having a collision when you do "make install"
in a non-windows system, but I left that (relatively trivial) step out of
the "vanilla" build here, so it's not as obvious that it would happen.
Post by Pete Batard
3. I'm kind of wondering if we'd not be better of starting with a
Release & Debug directories at the top libusb-winusb-wip\Debug,
libusb-winusb-wip\Release and then working our way down to
subdirectories if needed (dll, lib, examples).
That's fine by me. Peter had suggested the other layout, and I don't care
one way or the other.
Post by Pete Batard
I think this is closer to where MSVC users who are new to libusb would
expect to find their files in the first place.
I'm not sure that's true, but it doesn't really matter to me, as I
mentioned. I just took the first reasonable suggestion.
Post by Pete Batard
libusb-winusb-wip\Debug\dll\libusb-1.0.dll
libusb-winusb-wip\Debug\dll\libusb-1.0.lib
libusb-winusb-wip\Debug\lib\libusb-1.0.lib
Yes
Post by Pete Batard
libusb-winusb-wip\Debug\examples\lsusb.exe
libusb-winusb-wip\Debug\examples\xusb.exe
Maybe, maybe not. Note the subdirectories above. I could not control where
the vc60.idb and vc60.pdb files go by themselves, though I don't recall if
they were considered intermediates or final products. Note you also have
vc90.* files in your listing. I'm not sure how different they are (6 vs 9).
Post by Pete Batard
Would such a directory structure cause a problem with MSVC6?
Oh, and if needed, I'd create an intermediate directory (xusb_int,
lsusb_int) for the intermediate files of the executables above
As mentioned, if they turn out to be intermediate files, that might work.
If they're not considered intermediate files, then the examples may have to
stay separate, as before. I'll just have to test it. I think the point in
putting it under MSVC was that someone mentioned MinGW did something
conflicting. The point in the weird directory names was just that that's an
MSVC6 convention when there's more than one project in the same directory
(for example, both a DLL and static LIB, or two different EXEs, or
whatever). Acutally, the convention is weirder, but rational: the first
project you create and/or activate gets plain "Debug", and later ones get
"projectName__Debug" or some such. I at least tried to make it consistent.

But moving everything under a "Debug" hierarchy and "Release" hierarchy
under the root, with multi-level subdirectories instead of long directory
names, is fine by me if this is preferred.

Michael
Pete Batard
2010-01-14 21:09:56 UTC
Permalink
Post by Michael Plante
No, because it matters when you copy the DLLs (by themselves, of course) to
the system32 directory,
Gotcha. Then maybe adding a "_debug" suffix would be more explicit.
Personally, I think I'd want to spot any debug DLL in my system32
directory from a mile away. But if more people use the *d convention,
that's fine too.
Post by Michael Plante
As mentioned, if they turn out to be intermediate files, that might work.
If they're not considered intermediate files, then the examples may have to
stay separate, as before. I'll just have to test it.
OK. Just le me know.
Post by Michael Plante
Acutally, the convention is weirder, but rational: the first
project you create and/or activate gets plain "Debug", and later ones get
"projectName__Debug" or some such. I at least tried to make it consistent.
Well, I'd say if people care enough about following this convention,
they'll just edit their project default to fit their needs.
My guess however is that most libusb users would be open source projects
that need a quick and easy multiplatform USB stack, and are therefore
unlikely to be that concerned about "historical" MSVC conventions.

As a matter of fact, does anybody here has an idea of what the core
audience of libusb is? How widely do you think libusb would be used in
regular corporate proprietary projects, as opposed to smaller open
source endeavours for instance?

Regards,

/Pete
Graeme Gill
2010-01-15 01:07:35 UTC
Permalink
Post by Pete Batard
As a matter of fact, does anybody here has an idea of what the core
audience of libusb is? How widely do you think libusb would be used in
regular corporate proprietary projects, as opposed to smaller open
source endeavours for instance?
It's very hard to judge. On the one hand making it works on
MSWindows increases the potential interest by a factor of 9.
It also reduces the barrier for MSWindows only application
to be ported to other platforms (OS X, Linux being the
main ones, possibly embed depending on libusb support).
On the other hand the LGPL licensing acts a deterrent,
just because of the hassle factor.

Graeme Gill.
Peter Stuge
2010-01-15 01:29:51 UTC
Permalink
Post by Graeme Gill
How widely do you think libusb would be used in regular corporate
proprietary projects, as opposed to smaller open source
endeavours for instance?
(The open source endeavours are not always smaller! :)
Post by Graeme Gill
It's very hard to judge. On the one hand making it works on
MSWindows increases the potential interest by a factor of 9.
It also reduces the barrier for MSWindows only application
to be ported to other platforms (OS X, Linux being the
main ones, possibly embed depending on libusb support).
On the other hand the LGPL licensing acts a deterrent,
just because of the hassle factor.
Well put.

One way we might be able to help libusb adoption is to provide some
recipes for easy license compliance, maybe even example projects. I
was thinking lately that it would be excellent for the purpose of
LGPL compliance to not have to ship a thousand object files but
instead have a single archive for the application - and a fairly
simple linker stage that to link app with libusb. I don't know how
feasible this is with current toolchains though. (MS and GNU..)

It's kind of backwards - using .a/.lib to store applications.


//Peter
Michael Plante
2010-01-14 21:34:30 UTC
Permalink
Post by Pete Batard
Post by Michael Plante
No, because it matters when you copy the DLLs (by themselves, of
course) to
Post by Pete Batard
Post by Michael Plante
the system32 directory,
Gotcha. Then maybe adding a "_debug" suffix would be more explicit.
Personally, I think I'd want to spot any debug DLL in my system32
directory from a mile away. But if more people use the *d convention,
that's fine too.
Either way is fine by me. I don't mind having those in my system32
directory at all; I'm not sure what the implication here is. If there
weren't a speed issue, I'd rather ALL of my DLLs be debug. But whatever.
I'll go ahead and rename them. Keeping it to a single character is only
important if you're adding a whole bunch more decorations, as some very
build-time-configurable and/or multi-compiler libraries do (like pthreads).
Post by Pete Batard
Well, I'd say if people care enough about following this convention,
I just said it's default, so I used it. Since you've already updated your
project files, I'll follow your layout (except, for now, I'm going to keep
the examples in subdirectories until I test more). I'll try to post the new
project files to the list today or tomorrow. Oh, I'm not 100% positive, but
it may (not sure) be important for the dsp/dsw files to be CRLF.

Michael
Michael Plante
2010-01-15 01:14:49 UTC
Permalink
Post by Peter Stuge
I'd like there to be an msvc directory before Debug and Release.
OK, I'll do that. I haven't started yet.
Post by Peter Stuge
I imagine that releases will be created and packaged on a *ix system.
Then there could be a script to ensure CRLF for the files that really
require it. Tarball and zip packages, targeted for *ix and Windows
respectively. Should they have different contents? Ie. .zip has CRLF?
If that's not more difficult than just doing it for DSP/DSW, sure. That
said, Winzip and WinRAR support tgz, and WinRAR supports tbz2. zip is
supported natively from XP on (which annoys me to no end, as it slows
everything down and makes the "search" function not work well, but I
digress). Then there are free programs (7-zip?). So I'd only bother if the
archives have different contents.
Post by Peter Stuge
It might be nifty to also have an NSIS installer for developers on
Windows. NSIS can run on *ix and still generate the exe installer.
If the zip has CRLF for all files then so should the installer.
I think an installer would only be useful for precompiled binaries. I
prefer to have more control over where source code winds up. But that's
fine if someone wants to do it.


Michael
Michael Plante
2010-01-15 02:36:24 UTC
Permalink
Post by Peter Stuge
LGPL compliance to not have to ship a thousand object files but
instead have a single archive for the application - and a fairly
simple linker stage that to link app with libusb. I don't know how
feasible this is with current toolchains though. (MS and GNU..)
A command line tool shipped with vc6 is capable of adding, removing, and
extracting object files from static libraries. I'm pretty sure much older
Microsoft compilers also had a similar tool. This means you could ship the
static .LIB and people could extract the .OBJ files at will.

Michael
Peter Stuge
2010-01-15 03:45:20 UTC
Permalink
Post by Michael Plante
Post by Peter Stuge
LGPL compliance to not have to ship a thousand object files but
instead have a single archive for the application - and a fairly
simple linker stage that to link app with libusb. I don't know how
feasible this is with current toolchains though. (MS and GNU..)
A command line tool shipped with vc6 is capable of adding, removing,
and extracting object files from static libraries. I'm pretty sure
much older Microsoft compilers also had a similar tool. This means
you could ship the static .LIB and people could extract the .OBJ
files at will.
That was LIB.EXE back in the DOS day, right? :)

But what makes it awkward is that instead of going from many .obj
+.lib to one .exe there is now a .lib step in between which gathers
up all the .obj files. I don't think the problem is to hide the .obj
files so much as it might be to generate the "application" .lib.


//Peter
Michael Plante
2010-01-15 02:38:51 UTC
Permalink
Post by Pete Batard
Post by Orin Eman
If the filename ends in .txt, it should have CRLF IMO. Especially the
Windows readme file which almost certainly will be opened in Notepad!
The current README_msvc.txt does, but then again, the git tree is aimed
at developers, not end users, and how many developers do we expect to
use still use Notepad as their default text editor?
I do. It loads essentially instantaneously; I've never had any other GUI
program that I can recall load noticeably faster. In fact, if I don't
already have some alternative open, I even look at source code in it
sometimes.


Michael
Orin Eman
2010-01-15 06:32:15 UTC
Permalink
Post by Michael Plante
Post by Pete Batard
Post by Orin Eman
If the filename ends in .txt, it should have CRLF IMO. Especially the
Windows readme file which almost certainly will be opened in Notepad!
The current README_msvc.txt does, but then again, the git tree is aimed
at developers, not end users, and how many developers do we expect to
use still use Notepad as their default text editor?
I do. It loads essentially instantaneously; I've never had any other GUI
program that I can recall load noticeably faster. In fact, if I don't
already have some alternative open, I even look at source code in it
sometimes.
Yes, me too. Often for things like bat and inf files! I certainly wouldn't
want to wait for Visual Studio to load its slothful self just to look at a
text file.

Programming gets done mostly in Visual Studio, or vim if I happen to be
using Cygwin.

Orin.
Michael Plante
2010-01-15 04:28:23 UTC
Permalink
Post by Peter Stuge
Post by Michael Plante
Post by Peter Stuge
LGPL compliance to not have to ship a thousand object files but
instead have a single archive for the application - and a fairly
simple linker stage that to link app with libusb. I don't know how
feasible this is with current toolchains though. (MS and GNU..)
A command line tool shipped with vc6 is capable of adding, removing,
and extracting object files from static libraries. I'm pretty sure
much older Microsoft compilers also had a similar tool. This means
you could ship the static .LIB and people could extract the .OBJ
files at will.
But what makes it awkward is that instead of going from many .obj
+.lib to one .exe there is now a .lib step in between which gathers
up all the .obj files. I don't think the problem is to hide the .obj
files so much as it might be to generate the "application" .lib.
I'm not sure I see why would the vendor would want to bundle the files this
way...but yeah, that's awkward. I can't think of a good solution.
Peter Stuge
2010-01-15 04:50:23 UTC
Permalink
Post by Michael Plante
I'm not sure I see why would the vendor would want to bundle the
files this way...but yeah, that's awkward.
To simplify relinking with libusb as much as possible - it also gives
an impression of revealing less information about the application.

(Although same info could be found in the .exe with a debugger!)


//Peter
Michael Plante
2010-01-15 05:31:27 UTC
Permalink
Post by Peter Stuge
Post by Michael Plante
I'm not sure I see why would the vendor would want to bundle the
files this way...but yeah, that's awkward.
To simplify relinking with libusb as much as possible
I suppose without a Makefile this could be a problem. Finding a project and
putting a link to it as an example should be good enough. I was going to
suggest d2xx, but they omitted a Makefile. :(
Post by Peter Stuge
- it also gives
an impression of revealing less information about the application.
(Although same info could be found in the .exe with a debugger!)
Impression, yes, though an exe certainly takes more time to pick apart: the
modules are not clearly delineated, functions frequently aren't in
contiguous blocks, there are fewer original symbol names around (IIRC), and
use of a packer makes things a bit more challenging. But my point about the
extraction utility is that the library processing is no more difficult to
undo than if they tarred the object files up and calling it a .LIB; the
names are still there and all. Moreover, IDA, the most likely tool these
days, when given a LIB, will offer to open any of the object files, cutting
out another step. I guess if a dishonest engineer is trying to convince the
bean counters to let him use an LGPL project, that's useful...

What might be better is to compile a list of legit reasons for a company to
adopt the library, in spite of the likelihood the app will be more exposed.
An easier target would be companies that can afford to give the software
away and charge for the hardware, but choose not to distribute source; they
have less to lose. Atmel is one company that gives (closed) software away,
while TI generally does not. Maybe Philip or Xiaofan could jump in with
comments about Microchip. Altera and Xilinx would be tougher, due to IP
cores. If I were the proprietary vendor, it would matter more whether the
trade secrets are in hardware or software. This is a good situation for
low-level libraries like libusb.

Michael
Loading...