News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

converting an usb.h include file

Started by Siekmanski, October 12, 2015, 09:22:31 AM

Previous topic - Next topic

Siekmanski

I'm converting an usb.h include file.


struct usb_device
{
    struct usb_device *next, *prev;
    char filename[LIBUSB_PATH_MAX];
    struct usb_bus *bus;
    struct usb_device_descriptor descriptor;
    struct usb_config_descriptor *config;
    void *dev; /* Darwin support */
    unsigned char devnum;
    unsigned char num_children;
    struct usb_device **children;
};


Is this the correct conversion to ASM ?


usb_device              struct
    next                DWORD ?
    prev                DWORD ?
    filename            BYTE LIBUSB_PATH_MAX dup (?)
    bus                 DWORD ?
    descriptor          usb_device_descriptor <>
    config              DWORD ?
    dev                 DWORD ? ; * Darwin support
    devnum              BYTE ?
    num_children        BYTE ?
    children            DWORD ? ; **children --> I assume this is a pointer to a pointer ?
usb_device              ends

Creative coders use backward thinking techniques as a strategy.

dedndave


jj2007

I'm no good in C, the line  struct usb_device *next, *prev; looks odd.
If you are unsure, and you can use it in C to compile a fake program, use e.g.
_asm {
  int 3
  lea eax, somestruct
  lea ecx, somestruct.next
}

... and run it with Olly.

Siekmanski

#3
Hi Dave,
I use libusb-win32  http://sourceforge.net/projects/libusb-win32/files/latest/download?source=files
This lib is also used to communicate with the usb dongles used for Software Defined Radio.

Hi Jochen,
I don't have a C/C++ compiler installed.

I have converted a lot of C/C++ include files but now I'm also confused by these lines:

   struct usb_device *next, *prev;

And is, "struct usb_config_descriptor *config;" a pointer to a struct or is it an included struct ???

Edit: corrected link to  libusb-win32.
Creative coders use backward thinking techniques as a strategy.

qWord

the structure translation is OK.
**x means pointer to pointer, struct foo *p is pointer to structure foo. In C you can have several declarators (next,prev) in one declaration - the asterisk * belongs to the declarator.
MREAL macros - when you need floating point arithmetic while assembling!

rrr314159

I'm no expert but a couple points,

struct usb_device *next, *prev

Evidently this implements a linked list, pointing at the next and prev structs in the list. So you ought to be able to represent them as two DWORDS, or, "ptr whatever". That reserves two DWORDS also, of course. A peculiar fact about JWasm (maybe ML also): once it sees that "ptr" it assumes a DWORD (or QWORD, in 64-bit). So you can write "ptr it_doesnt_matter_what_you_put_here" and it still works!

struct usb_config_descriptor *config

- I think it's a pointer to a struct, like the two above

Quote**children --> I assume this is a pointer to a pointer ?

- yes; which as far as asm struct cares, is just another pointer

[edit] wrote this b4 seeing qWord's post, guess it's still relevant
I am NaN ;)

qWord

Quote from: rrr314159 on October 12, 2015, 10:33:24 AMSo you can write "ptr it_doesnt_matter_what_you_put_here" and it still works!
If T is not declared for "ptr T", MASM does a structure forward declaration. If T is then used as anything else than a structure (or declaration of it), MASM throws an error.
MREAL macros - when you need floating point arithmetic while assembling!

Siekmanski

qWord, thanks for the confirmation.  :t
Creative coders use backward thinking techniques as a strategy.

rrr314159

Quote from: qWordIf T is not declared for "ptr T", MASM does a structure forward declaration. If T is then used as anything else than a structure (or declaration of it), MASM throws an error.

- makes sense. But, interestingly, if T isn't declared at all, JWasm throws no error, reserves a DWORD or QWORD, no problem. You can then go ahead and use that pointer as usual
I am NaN ;)

qWord

Quote from: rrr314159 on October 12, 2015, 11:17:47 AMBut, interestingly, if T isn't declared at all, JWasm throws no error, reserves a DWORD or QWORD, no problem.
indeed -  I also recognized that MASM allows that (intended?). However an quick test also showed that using T as PROC name cause an internal assembler error (v6 and 8 tested).

regards
MREAL macros - when you need floating point arithmetic while assembling!

TouEnMasm


this include is tested with ml 6.15 on win 10,it work
Fa is a musical note to play with CL

Siekmanski

Thanks ToutEnMasm,

I'll have a look at this one, is it from the win sdk ?
Creative coders use backward thinking techniques as a strategy.

Zen

SIEKMANSKI,
Where the heck is usb.h ??? I downloaded the source and looked all through the files and could not find it,...although I found some very similar files,...
(I downloaded version 1.0.20)

dedndave


Zen

Could it be: struct libusb_device ???
...declared but not defined in libusb.h,...