NO

Author Topic: Using MS standard headers on PellesC  (Read 19775 times)

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1571
Using MS standard headers on PellesC
« on: March 22, 2014, 08:19:53 PM »
I spent a couple of hours to look on how to directly import native MS headers in PellesC.
The discrepancies are:
  • standard headers for C99 and C11 compatibility
  • Problems on Math due to C99 and C11 extensions
  • An apparently misuse of pasting operators in driverspecs.h (called by winNT.h)
The first point to consider is that PellesC is strictly compliant with C99 and C11, MS VC++ not! It includes C11++ that, unfortunately is not compatible with C11. In plane words the standard header layout is completely different from that of MS, things are declared in different stdxxxx.h files and this creates some problem.
The math type complex is a basic type for C99/C11, while MS defines it as a struct. This generates errors using the MS math.h header.
In driverspecs.h there are the lines:
Code: [Select]
#define __drv_out(annotes) __post __$drv_group(##__drv_nop(annotes))
and
Code: [Select]
#define __drv_when(cond, annotes) \
  __drv_declspec("SAL_when(" SPECSTRINGIZE(cond) ")") __$drv_group(##__drv_nop(annotes))
Where the pasting operator (##) is not prepended by anything, and this is an error as stated also on MSDN help. This error produce a series of warnings of this type:
Quote
C:\PellesC\Include\winnt.h(1202): warning #1058: Invalid token produced by ##, from '(' and '__drv_nop'.
The problem can be easily solved by setting off the warning using a pragma, or by modifying the original MS def in driverspecs.h as follows:
Code: [Select]
#define __drv_out(annotes) __post __$drv_group(__drv_nop(annotes))and
Code: [Select]
#define __drv_when(cond, annotes) \
  __drv_declspec("SAL_when(" SPECSTRINGIZE(cond) ")") __$drv_group(__drv_nop(annotes))

Moreover in "shellapi.h" there is this line
Code: [Select]
//          PATH                    =   c:\windows\system32;C:\windows;c:\;C:\Program Files\Compilers\
which end with a backspace that triggers the warning:
Quote
C:\PellesC\Include\shellapi.h(666): warning #1063: Single-line comment contains escaped new-line.
To solve it edit shellapi.h adding a space at the end of the line.

Anyway to use the windows headers file is possible. They can live along with PellesC, and is possible to compile using directly the standard MS headers.
Now I will explain how to, of course there will be other problems that I still have not discovered compiling my sources.
I used the SDK WIN7 SP1.

To use Headers strictly follow the instructions here.
Let me know what problems you encounter.
« Last Edit: April 04, 2014, 06:04:20 PM by frankie »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1554
Re: Using MS standard headers on PellesC
« Reply #1 on: March 22, 2014, 09:04:26 PM »
Why touch to PellesC include when include path can changed as project based ?
Or in register or XML.
Maybe %PellesCDir% is important too for pomake ?

@Frankie
poide needs second copy as to new include/lib folder

\
 \bin\poide.exe
 \bin\Intl\rsrc0009.dll
 \bin\AddIns\
 \include\
 \include\Win\
 \lib
 \lib\Win\
 \lib\Win64\

other bins must be in PATH

This way we can have untouched PellesC and WSDK version in use ?

Any comments ?

« Last Edit: March 23, 2014, 10:53:22 AM by timovjl »
May the source be with you

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1571
Re: Using MS standard headers on PellesC
« Reply #2 on: March 22, 2014, 09:44:52 PM »
Hi Timo,
Just because I have seen that some directories seems to be hardcoded in the compiler, or in the project files (.ppj and .ppw).
In this case when trying to compile existent projects it seems to look in the original directories  :P
Could you make some checks?
I have already found something to be touched in "stat.h" and "strsafe.h".
Does it works in WIN64?

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1554
Re: Using MS standard headers on PellesC
« Reply #3 on: March 24, 2014, 11:40:48 AM »
Just because I have seen that some directories seems to be hardcoded in the compiler, or in the project files (.ppj and .ppw).
Hardcoded %PellesCDir% only in poide's internal make. pomake can use %PellesCDir%.

PellesC poide with option -xml it is easy to make another copy of PellesC folder for testing environment and copy WSDK files into it. No messing with original folder at all.
May the source be with you

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1571
Re: Using MS standard headers on PellesC
« Reply #4 on: March 24, 2014, 12:18:31 PM »
Thanks Timo!  ;)
I have made some more checks and discovered that is enough to replace headers in Include/Win directory.
All other files must remain that coming for PellesC distribution.
I'll write a detailed HowTo later.
Basically PellesC works with no problems with MS headers, apart the small hacking indicated in my first post and some other I have found.
For me is clear that the headers packed in the PellesC distribution are there just to install a ready to run compiler suite.
Infact the SDK's could not be redistribuited, and downloading an SDK install it and use is not so simple to explain to first time users. That's why Pelle make the decision to include a subset of headers, that IMHO are still enough unless you need a very advanced library or feature  :P
But the point is, considering that Pelle should know that his compiler suite could use MS headers, he has not made public the feature for at least the advanced users...  :o
New incompatibility are from the undeployed __declspec(selectany) and some other small issues that I'm hacking.
I have also copied new libraries in the lib folder and they works OK, unless the uuid.lib that triggers a linker error for an 'unknown codeview symbol 0x00). No problem compiling without debug information. Unless you don't need a very recent UUID you can still use the original library when compiling debuggable executables.

Last, to all PellesC users, I don't understand why nobody give any feedback. Is this issue of any interest only for me and Timo?  :-\
(I could say that me and Timo know how to make it, so .... why do we have to waste time to write posts about it?  ;D )
More seriously this is the main reason of irritation for Pelle, and I have to fully agree with him...
« Last Edit: March 24, 2014, 12:22:24 PM by frankie »

Offline jj2007

  • Member
  • *
  • Posts: 441
Re: Using MS standard headers on PellesC
« Reply #5 on: March 24, 2014, 04:51:54 PM »
Hi Frankie and Timo,

Just want to say YES, this is a good initiative, and you are doing a very good job (no thumbs up icon here - MODERATOOOOOOR!!!!!)
« Last Edit: March 25, 2014, 01:27:08 AM by jj2007 »

Offline DMac

  • Member
  • *
  • Posts: 244
Re: Using MS standard headers on PellesC
« Reply #6 on: March 24, 2014, 05:35:31 PM »
Although, I have not had need up to this point for more than what is included in the standard Pelle's download, I appreciate the fact that if I do in the future want to include some of the missing elements of the windows SDK in my applications I can refer to this thread and get things up and running quickly.

Thanks Frankie and Timo for your time and effort on this!  :D

JJ2007 - You can select the thumbs up from the Message icon drop down in the Post reply editor.
No one cares how much you know,
until they know how much you care.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1571
Re: Using MS standard headers on PellesC
« Reply #7 on: March 24, 2014, 06:45:31 PM »
Thanks to all  :)
But the feedback we need is on other possible issues. I'm still looking for other drawbacks compiling and recompiling my projects that could don't include all possible headers/libraries, or the one you may have used in your application (header or library, console or GUI functions, etc.).
What we need to help us is that you experiment on your system recompiling your projects and reporting the problems if any.
« Last Edit: March 24, 2014, 06:47:54 PM by frankie »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1554
Re: Using MS standard headers on PellesC
« Reply #8 on: March 24, 2014, 07:01:05 PM »
uuid.diff from PellesC uuid.lib and WSDK 7.1 uuid.lib
and uuid_1.lib generated with from WSDK uuid.lib
« Last Edit: March 24, 2014, 07:05:23 PM by timovjl »
May the source be with you

Offline jj2007

  • Member
  • *
  • Posts: 441
Re: Using MS standard headers on PellesC
« Reply #9 on: March 25, 2014, 01:31:08 AM »
JJ2007 - You can select the thumbs up from the Message icon drop down in the Post reply editor.

Done. The Masm forum, which also uses SMF, has a better (IMO) icon list, see here for example.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1571
Re: Using MS standard headers on PellesC
« Reply #10 on: March 25, 2014, 09:00:32 AM »
Thanks Timo.
Anyway the the linker problem seems to be related only to the debug section of the executable, that contains a symbol code unknown to PellesC codeview. I think this is from the new MS revisions of CodeView that are not pubblic (it's long time that MS doesn't pubblish an updated documentation). Probably a pdb reference or a new code for OLE/AUTO debuug.
So it should be safe to use it for release versions (without debugging info), or at least they can use Timo's library made with polib.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1554
Re: Using MS standard headers on PellesC
« Reply #11 on: March 31, 2014, 06:40:23 AM »
As pocc.exe support AMD64/x64, it is possible to test those WSDK headers for 64-bit too in 32-bit environment and with x64 libs linking is possible too when 64-bit libs are copied from lib\x64 to lib\Win64  folder.

With this AddIn Create/Open 32-bit project to 64 bit project project is possible to copy to 64-bit version easily.

EDIT:
StrAlign.h line 113 without <wchar.h>
Code: [Select]
#endif // _PREFAST_
wchar_t * wcscpy(wchar_t * dst, const wchar_t * src); //<- insert this
    return wcscpy(Destination, Source);
#pragma warning(pop)

FixHdrLst.zip for testing. run it in PellesC base dir, it uses include/Win/ path and fix driverspecs.h and Stralign.h as Frankie shows.
« Last Edit: April 06, 2014, 03:26:29 PM by TimoVJL »
May the source be with you

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1571
Re: Using MS standard headers on PellesC
« Reply #12 on: April 01, 2014, 11:06:01 AM »
Timo the insertion of wchar was already in the instructions, but the list numering was missed. It is the point 10.
I added numbering now.
The inclusion is on line 98 because if you define '_STRALIGN_USE_SECURE_CRT=1' also the function 'ua_wcscpy_s' is defined as 'wcscpy_s' and then requires whchar.h definitions.
Anyway the best place for the inclusion should be at top of the header just after the module symbole definition:
Code: [Select]
#if !defined(__STRALIGN_H_) && !defined(MIDL_PASS)
#define __STRALIGN_H_

#include <wchar.h>      //Line 46 of WIN7-sp1 SDK

Anyway considering the views and that up to now just 3 peoples downloaded the utility doesn't seem that this argument is of so big interest...  :(
« Last Edit: April 01, 2014, 04:30:46 PM by frankie »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1554
Re: Using MS standard headers on PellesC
« Reply #13 on: April 01, 2014, 08:10:43 PM »
pobr.exe doesn't like WSDK header files :(
Those f... annotations >:(
May the source be with you

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1571
Re: Using MS standard headers on PellesC
« Reply #14 on: April 02, 2014, 08:16:00 AM »
pobr seems to work for me  :(
Have you used the /W switch for windows mode?