4

I'm working on importing an old C windows driver project that was created in Visual c++ 6.0 into visual studio 2012. The way that the structs were defined are causing errors in vs2012.

typedef struct {
    LINK               Link;
    HANDLE             hFile;
    BYTE               handleType;
    OVERLAPPED         Overlapped;
    CRITICAL_SECTION   csIoCtrl;
} USB_HANDLE, *PUSB_HANDLE;

typedef struct {
    USB_HANDLE;        //error occurs here saying nothing was declared for USB_HANDLE
    LIST               PipeList;
    BOOL               bRemoved;
    CRITICAL_SECTION   csPipeList;
    SP_DEVICE_INTERFACE_DETAIL_DATA *InterfaceData;
} USB_DEVICE, *PUSB_DEVICE;

The project then uses calls like USB_DEVICE mydevice; mydevice->hfile = handle;

Is this type of structure possible in vs2012?

(edit - though these do show as errors, visual studio 2012 did compile and successfully build a solution. I will be testing the driver to see if everything works properly soon.)

Errors:

struct declaration error message

member error message

A work around that I thought I could use was making the USB_DEVICE struct:

typedef struct {
    USB_HANDLE         USB_HANDLE;        
    LIST               PipeList;
    BOOL               bRemoved;
    CRITICAL_SECTION   csPipeList;
    SP_DEVICE_INTERFACE_DETAIL_DATA *InterfaceData;
} USB_DEVICE, *PUSB_DEVICE;

Then I could make the rest of the calls: mydevice->USB_HANDLE.hfile = handle;

Is this an equivalent statement?

2
  • 3
    You can fix this by giving a name to the USB_HANDLE in the USB_DEVICE. Commented Apr 4, 2013 at 0:45
  • We shouldn't have to ask what the error message says, as it should be in your first sentence: "I'm getting the following error message in VS2012: ...". Please enlighten us with this critical information. Commented Apr 4, 2013 at 1:38

2 Answers 2

1

Define a macro to declare the USB_HANDLE and then use it in both. Like,

#define HANDLE_BODY                \
   LINK               Link;        \
   HANDLE             hFile;       \
   BYTE               handleType;  \
   OVERLAPPED         Overlapped;  \
   CRITICAL_SECTION   csIoCtrl;

typedef struct {
   HANDLE_BODY
} USB_HANDLE, *PUSB_HANDLE;

typedef struct {
    HANDLE_BODY
    LIST               PipeList;
    BOOL               bRemoved;
    CRITICAL_SECTION   csPipeList;
    SP_DEVICE_INTERFACE_DETAIL_DATA *InterfaceData;
} USB_DEVICE, *PUSB_DEVICE;

You can create a union if you also need that. Otherwise, you may need some special non-standard compiler options. For instance, many compiler support transparent_union, which would also solve your issue. However, I don't think Visual C++ supports this. But maybe someone more knowledgeable of these products can help.

Sign up to request clarification or add additional context in comments.

1 Comment

You might also like to place a comment about the problem. I wouldn't recommend this for new code, but it may allow you to work around the issue and at least get the system running with the new tool.
0

It seems that the type USB_HANDLE in USB_DEVICE does not define any variable.

typedef struct {
    USB_HANDLE         handler;  // handler is missing?
    LIST               PipeList;
    BOOL               bRemoved;
    CRITICAL_SECTION   csPipeList;
    SP_DEVICE_INTERFACE_DETAIL_DATA *InterfaceData;
} USB_DEVICE, *PUSB_DEVICE;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.