Link to home
Start Free TrialLog in
Avatar of XPUSR
XPUSR

asked on

header file conflict in VC++6.0[WinXP]

Hi,

I am attempting to gain access to a USB Device on my PC. I have wrote a simple program in Visual C++ 6.0. The problem is that when I include the "hidsdi.h" header file and compile the program I get numerous errors:

example errors:
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(52) : warning C4005: 'STATUS_WAIT_0' : macro redefinition
g:\program files\microsoft visual studio\vc98\include\winnt.h(1053) : see previous definition of 'STATUS_WAIT_0'

I presum there is some conflict between the ntstatus.h and the winnt.h files but this only occurs when I include the "hidsdi.h" file.

Any suggestions will be appreciated,

Thanks

J
Avatar of jkr
jkr
Flag of Germany image

That is a problem, as both files define these status macros. Quick solution - if you have

#include <windows.h>
//...
#include "hidsdi.h"

change it to

#include <windows.h>
//...
#define WIN32_NO_STATUS
#include "hidsdi.h"
#undef WIN32_NO_STATUS
Avatar of XPUSR
XPUSR

ASKER

I gave it a go but it didn't make any difference??

any other ideas??

Thanks
Did you do a 'clean' before building the project again?
Avatar of XPUSR

ASKER

Yes,

I did a clean...

I only posted 2 of the errrors I actually get the following list,



:\program files\microsoft visual studio\vc98\include\ntstatus.h(52) : warning C4005: 'STATUS_WAIT_0' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1053) : see previous definition of 'STATUS_WAIT_0'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(58) : warning C4005: 'STATUS_ABANDONED_WAIT_0' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1054) : see previous definition of 'STATUS_ABANDONED_WAIT_0'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(60) : warning C4005: 'STATUS_USER_APC' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1055) : see previous definition of 'STATUS_USER_APC'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(63) : warning C4005: 'STATUS_TIMEOUT' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1056) : see previous definition of 'STATUS_TIMEOUT'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(64) : warning C4005: 'STATUS_PENDING' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1057) : see previous definition of 'STATUS_PENDING'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(96) : warning C4005: 'STATUS_SEGMENT_NOTIFICATION' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1058) : see previous definition of 'STATUS_SEGMENT_NOTIFICATION'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(135) : warning C4005: 'STATUS_GUARD_PAGE_VIOLATION' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1059) : see previous definition of 'STATUS_GUARD_PAGE_VIOLATION'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(136) : warning C4005: 'STATUS_DATATYPE_MISALIGNMENT' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1060) : see previous definition of 'STATUS_DATATYPE_MISALIGNMENT'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(137) : warning C4005: 'STATUS_BREAKPOINT' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1061) : see previous definition of 'STATUS_BREAKPOINT'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(138) : warning C4005: 'STATUS_SINGLE_STEP' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1062) : see previous definition of 'STATUS_SINGLE_STEP'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(182) : warning C4005: 'STATUS_ACCESS_VIOLATION' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1063) : see previous definition of 'STATUS_ACCESS_VIOLATION'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(183) : warning C4005: 'STATUS_IN_PAGE_ERROR' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1064) : see previous definition of 'STATUS_IN_PAGE_ERROR'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(185) : warning C4005: 'STATUS_INVALID_HANDLE' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1065) : see previous definition of 'STATUS_INVALID_HANDLE'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(200) : warning C4005: 'STATUS_NO_MEMORY' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1066) : see previous definition of 'STATUS_NO_MEMORY'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(206) : warning C4005: 'STATUS_ILLEGAL_INSTRUCTION' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1067) : see previous definition of 'STATUS_ILLEGAL_INSTRUCTION'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(214) : warning C4005: 'STATUS_NONCONTINUABLE_EXCEPTION' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1068) : see previous definition of 'STATUS_NONCONTINUABLE_EXCEPTION'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(215) : warning C4005: 'STATUS_INVALID_DISPOSITION' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1069) : see previous definition of 'STATUS_INVALID_DISPOSITION'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(316) : warning C4005: 'STATUS_ARRAY_BOUNDS_EXCEEDED' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1070) : see previous definition of 'STATUS_ARRAY_BOUNDS_EXCEEDED'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(317) : warning C4005: 'STATUS_FLOAT_DENORMAL_OPERAND' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1071) : see previous definition of 'STATUS_FLOAT_DENORMAL_OPERAND'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(318) : warning C4005: 'STATUS_FLOAT_DIVIDE_BY_ZERO' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1072) : see previous definition of 'STATUS_FLOAT_DIVIDE_BY_ZERO'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(319) : warning C4005: 'STATUS_FLOAT_INEXACT_RESULT' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1073) : see previous definition of 'STATUS_FLOAT_INEXACT_RESULT'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(320) : warning C4005: 'STATUS_FLOAT_INVALID_OPERATION' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1074) : see previous definition of 'STATUS_FLOAT_INVALID_OPERATION'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(321) : warning C4005: 'STATUS_FLOAT_OVERFLOW' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1075) : see previous definition of 'STATUS_FLOAT_OVERFLOW'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(322) : warning C4005: 'STATUS_FLOAT_STACK_CHECK' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1076) : see previous definition of 'STATUS_FLOAT_STACK_CHECK'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(323) : warning C4005: 'STATUS_FLOAT_UNDERFLOW' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1077) : see previous definition of 'STATUS_FLOAT_UNDERFLOW'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(324) : warning C4005: 'STATUS_INTEGER_DIVIDE_BY_ZERO' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1078) : see previous definition of 'STATUS_INTEGER_DIVIDE_BY_ZERO'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(325) : warning C4005: 'STATUS_INTEGER_OVERFLOW' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1079) : see previous definition of 'STATUS_INTEGER_OVERFLOW'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(326) : warning C4005: 'STATUS_PRIVILEGED_INSTRUCTION' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1080) : see previous definition of 'STATUS_PRIVILEGED_INSTRUCTION'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(429) : warning C4005: 'STATUS_STACK_OVERFLOW' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1081) : see previous definition of 'STATUS_STACK_OVERFLOW'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(490) : warning C4005: 'STATUS_CONTROL_C_EXIT' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1082) : see previous definition of 'STATUS_CONTROL_C_EXIT'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(749) : warning C4005: 'STATUS_FLOAT_MULTIPLE_FAULTS' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1083) : see previous definition of 'STATUS_FLOAT_MULTIPLE_FAULTS'
g:\program files\microsoft visual studio\vc98\include\ntstatus.h(750) : warning C4005: 'STATUS_FLOAT_MULTIPLE_TRAPS' : macro redefinition
        g:\program files\microsoft visual studio\vc98\include\winnt.h(1084) : see previous definition of 'STATUS_FLOAT_MULTIPLE_TRAPS'
g:\program files\microsoft visual studio\vc98\include\winddk.h(117) : error C2065: '__asm__' : undeclared identifier
g:\program files\microsoft visual studio\vc98\include\winddk.h(117) : error C2146: syntax error : missing ';' before identifier '__volatile__'
g:\program files\microsoft visual studio\vc98\include\winddk.h(117) : error C2065: '__volatile__' : undeclared identifier
g:\program files\microsoft visual studio\vc98\include\winddk.h(118) : error C2143: syntax error : missing ')' before ':'
g:\program files\microsoft visual studio\vc98\include\winddk.h(120) : error C2059: syntax error : ')'
g:\program files\microsoft visual studio\vc98\include\winddk.h(130) : error C2146: syntax error : missing ';' before identifier 'KSPIN_LOCK'
g:\program files\microsoft visual studio\vc98\include\winddk.h(130) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

host.exe - 7 error(s), 32 warning(s)
Ooops - you are not supposed to have DDK headers in your VC6 include directory, this will cause *tons* of other problems...
Avatar of XPUSR

ASKER

Do you know how I can solve this?

Do I have to get my hands on the MS DDK, or can I simply delete these DDK headers from the include directory and if I do this where do I put them?

Sorry for the idiot questions!!!

Thanks
J
>>can I simply delete these DDK headers from the include directory

Nope, you most likely have already overwritten a few - the DDK headers include e.g. a 'winnt.h' also. If they came separately, see which files you copied there. Usually, you would keep all of them in a separate directory. BTW, I just noticed that 'hidsdi.h' also is a DDK file - why would you need to include that?
Avatar of XPUSR

ASKER

Here is my code

I am going to reinstall VC++, hopefully this will restore all to the way it was before!

Do I need to get MSDDK? as I just downloaded the ddk files from the net and copied them to my vc++ include folder?

Thanks again


//***********************************************

#include "windows.h"
#include "stdio.h"
#include "setupapi.h"
#include "hidsdi.h"

int main(int argc, char* argv[])
      {      
      char data[4];
      char data2[4];
      DWORD junk;
      char temp;

      HANDLE hdevice = CreateFile("\\\\.\\h:", GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);

      if (hdevice == INVALID_HANDLE_VALUE)
            {
            printf("Unable to open the device - error %d\n", GetLastError());
            return 1;
            }
            else
            {
            printf("Access to usb device granted:\n");
            }

GUID hidGUID; //declaring GUID, this is where the problem starts  

     
while(1){
                  if (ReadFile(hdevice, data2, 1, &junk, NULL))
                  {
                        printf("\nThe device returned:  ");
                        for (int i = 0; i < 4; i++)
                              printf("%c",data2[i]);
                        printf("\n\nCNTL C  to exit\n\n");      
                  }
                  else
                  {
                        printf("Error: NORead\n\n");
                  }
            }
            CloseHandle(hdevice);
            return 0;
      }
>>Do I need to get MSDDK?

Only if you want to create a device driver.

>>GUID hidGUID; //declaring GUID, this is where the problem starts  

If you need the declarations for GUID, include 'objbase.h'.
Avatar of XPUSR

ASKER

I don't need to create a device driver just need to get read access to a usb device.
I need to declare "HidD_GetHidGuid()" amoung others.

As far as I know this belongs to 'hidsdi.h'?


>>I need to declare "HidD_GetHidGuid()" amoung others.
>>As far as I know this belongs to 'hidsdi.h'?

Hmm, 'hidsdi.h' does not use 'ntstatus.h', so this file should not be the problem...
Avatar of XPUSR

ASKER

but hidsdi.h calls hidusage.h and "hidpi.h" which in turn call other .h files which use ntstatus.h and this brings me back to my original errors...

I think I need the MSDDK as this contains all these files?
>>I think I need the MSDDK as this contains all these files?

Yes, or just extract the declaration:

void __stdcall
HidD_GetHidGuid (
    LPGUID   HidGuid
   );

Avatar of XPUSR

ASKER

i extracted the function void __stdcall HidD_GetHidGuid ( LPGUID   HidGuid);
It works...

But when I try to pass HidGuid into it I get an error

ERROR:
host.obj : error LNK2001: unresolved external symbol "void __stdcall HidD_GetHidGuid(struct _GUID *)"(HidD_GetHidGuid@@YGXPAU_GUID@@@Z)

//*******************************
//MY CODE
//WITH void __stdcallHidD_GetHidGuid (LPGUID   HidGuid) INSIDE MAIN

int main(int argc, char* argv[])
{
void __stdcallHidD_GetHidGuid (LPGUID   HidGuid);

GUID HidGuid;
HidD_GetHidGuid(&HidGuid);

return 0;
}

 
//******************************



AND IF I PUT THE void __stdcallHidD_GetHidGuid (LPGUID   HidGuid); outside main I get this error
g:\documents and settings\fin\desktop\fyp-nov\usbwindows\host\host.cpp(121) : error C2373: 'HidD_GetHidGuid' : redefinition; different type modifiers

I must be doing something stupid?? Have been working on this for the past few hours now and still no sucess.
Thanks for your time
 
You need to either add a .lib file or load the DLL the function resides in dynamically. The lib would either be hidclass.lib or hidparse.lib (give it a try, I really don't know which one it is)
HidD_GetHidGuid() is probably a function with C namemangling and the declaration shoud be inside extern "C".
Avatar of XPUSR

ASKER

JensUniweb I put the code in an extern "C", unfortunately it had no effect...

jkr, i think you are on the right track, the HidD_GetHidGuid() function resides in hid.lib but  how do I load it dynamically? I looked on the net for info on this but got nothing?
To load it dynamicly you have to do a loadlibrary() and then a getprocaddress().

Do you know the name in the .dll file. Is it like _Hid... or just Hid.... If it is without the _ you problably need to use __winapi or something like that. Not puting the _ infront of the name looking for it in the dll.

All this is called namemangling.
Avatar of XPUSR

ASKER

the file is just "hid.dll".

do I pass the lib name into the loadlibrary function and then call get procaddress?

loadlibrary("hid.dll");
getprocaddress();

Or how do i do it??

Thanks
SOLUTION
Avatar of JensUniweb
JensUniweb
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
extern "C" void __stdcall HidD_GetHidGuid ( LPGUID   HidGuid );

That should do the trick to compile. If the name in the .lib/.def is HidD_GetHidGuid with no _ infront and no C++ namemangling.
Avatar of XPUSR

ASKER

I am still having problems using LoadLibrary,

This is the code I am using.
LoadLibrary("G:\Program Files\Microsoft Visual Studio\VC98\Lib\hid.dll");

HHMODULE hModule=GetModuleHandle("G:\Program Files\Microsoft Visual Studio\VC98\Lib\hid.dll");

GetProcAddress(hModule,HidD_GetHidGuid);

GUID HidGuid; //Parameter I need to pass to the HidD_Get... function
HidD_GetHidGuid(&HidGuid); //This is the function I need access to!

OUTSIDE MAIN
extern "C" void __stdcall HidD_GetHidGuid (LPGUID   HidGuid);

The compiler errors i recieve are
error C2065: 'HHMODULE' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'hModule'
error C2065: 'hModule' : undeclared identifier
error C2440: '=' : cannot convert from 'struct HINSTANCE__ *' to 'int'
error C2065: 'HidD_GetHidGuid' : undeclared identifier

>>This is the code I am using.

This should be more like

typedef void ( __stdcall *pfnHidD_GetHidGuid) ( LPGUID   HidGuid );

HINSTANCE hDll = LoadLibrary("hid.dll");

pfnHidD_GetHidGuid pHidD_GetHidGuid = GetProcAddress(hModule,"HidD_GetHidGuid");

GUID HidGuid; //Parameter I need to pass to the HidD_Get... function
pHidD_GetHidGuid(&HidGuid); //This is the function I need access to!
Avatar of XPUSR

ASKER

I am still not getting this... Below is my code... Can you understand what is happening???

I am sorry to annoy you again so ill throw in an extra 100 points...
This is really bugging me so your help is really appreciated,
Thanks again,
J


int main
{
HINSTANCE hDll = LoadLibrary("hid.dll");
HHMODULE hModule=GetModuleHandle("hid.dll");
pfnHidD_GetHidGuid pHidD_GetHidGuid = GetProcAddress(hModule,"HidD_GetHidGuid");

//FUNCTION I NEED ACCESS TO
GUID HidGuid;
HidD_GetHidGuid(&HidGuid);

      
}

extern "C" void __stdcall HidD_GetHidGuid (LPGUID   HidGuid);
typedef void ( __stdcall *pfnHidD_GetHidGuid) ( LPGUID   HidGuid );

NOW MY ERRORS(10):
error C2065: 'HHMODULE' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'hModule'
error C2065: 'hModule' : undeclared identifier
error C2440: '=' : cannot convert from 'struct HINSTANCE__ *' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
error C2065: 'pfnHidD_GetHidGuid' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'pHidD_GetHidGuid'
error C2065: 'pHidD_GetHidGuid' : undeclared identifier
warning C4129: 'U' : unrecognized character escape sequence
error C2065: 'HidD_GetHidGuid' : undeclared identifier
error C2373: 'HidD_GetHidGuid' : redefinition; different type modifiers
error C2378: 'pfnHidD_GetHidGuid' : redefinition; symbol cannot be overloaded with a typedef
Use

typedef void ( __stdcall *pfnHidD_GetHidGuid) ( LPGUID   HidGuid );

HINSTANCE hDll = LoadLibrary("hid.dll");

pfnHidD_GetHidGuid pHidD_GetHidGuid = GetProcAddress(hDll,"HidD_GetHidGuid");

GUID HidGuid;
pHidD_GetHidGuid(&HidGuid);

There is no such thing as a HHMODULE and also no need to call 'GetModuleHandle()'
Avatar of XPUSR

ASKER

Thanks,

that has brought me down to one error
with the following line of code
//************************************
pfnHidD_GetHidGuid pHidD_GetHidGuid = GetProcAddress(hDll,"HidD_GetHidGuid");
//************************************

ERROR:

: error C2440: 'initializing' : cannot convert from 'int (__stdcall *)(void)' to 'void (__stdcall *)(struct _GUID *)'
Ooops :o)

pfnHidD_GetHidGuid pHidD_GetHidGuid = (pfnHidD_GetHidGuid) GetProcAddress(hDll,"HidD_GetHidGuid");
Avatar of XPUSR

ASKER

Thanks a million JKR, At long last its working.

I'll up the point 100 for this next question...
 
I need to do the same for the following function

"BOOLEAN HidD_GetAttributes(IN HANDLE  HidDeviceObject,OUT PHIDD_ATTRIBUTES  Attributes);"

This is the code I have tried:
int main{

typedef struct _HIDD_ATTRIBUTES {
  ULONG  Size;
  USHORT  VendorID;
  USHORT  ProductID;
  USHORT  VersionNumber;
} HIDD_ATTRIBUTES, *PHIDD_ATTRIBUTES;

typedef int ( __stdcall *pfnHidD_GetAttributes) ( HANDLE  HidDeviceObject)(PHIDD_ATTRIBUTES  Attributes);
pfnHidD_GetAttributes pHidD_GetAttributes = (pfnHidD_GetAttributes) GetProcAddress(hDll,"HidD_GetHidGuid");
pfnHidD_GetAttributes(&HidDeviceObject,&Attributes);

}

: error C2091: function returns function
: error C2065: 'HidDeviceObject' : undeclared identifier
: error C2065: 'Attributes' : undeclared identifier
: error C2564: 'int (__cdecl *(__stdcall *)(void *))(struct main::_HIDD_ATTRIBUTES *)' : function-style conversion to builtin type takes only one argument
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of XPUSR

ASKER

Thanks a million....

All is working for now!

J
You're welcome :o)
Hi XPUSR,
I have some questions about USB and I hope you would help me.
My email is : Ayd192@Hotmail.com

Thanx
sir,
  what are the nescessary things to develop a Device driver program.specifically USB.Is it possible to design a device driver using MFC,without DDK.please send me a sample code with explanation.

with regards,
Antony
sir,
     when i run my simple USB program,there are some errors in winddk.h.please tell me how can i rectify it.whare i can get windows DDK. My mail id : maharaj_be@yahoo.co.in

Antony