NO

Author Topic: Import libraries for the Universal C Runtime  (Read 5378 times)

Offline Vortex

  • Member
  • *
  • Posts: 865
    • http://www.vortex.masmcode.com
Import libraries for the Universal C Runtime
« on: December 06, 2023, 06:38:41 PM »
Hello,

The attachment contains the 32-bit and 64-bit versions of the import library for Universal C Runtime. The libraries are created from the text file listing the functions exported by UCRT.

A quick example :

Code: [Select]
#include <stdio.h>
#include <stdarg.h>

extern FILE* __cdecl __acrt_iob_func(unsigned Index);

#define _stdin  (__acrt_iob_func(0))
#define _stdout (__acrt_iob_func(1))
#define _stderr (__acrt_iob_func(2))

char *_strupr(char *str);
unsigned long _getdrives( void );

int __cdecl __stdio_common_vfprintf(unsigned __int64 _Options, FILE* _Stream, char const* _Format , int _Locale, va_list);

int printf(const char * format, ...)
{
int retVal;
va_list vl;
va_start(vl, format);
retVal = __stdio_common_vfprintf(0, _stdout,format, 0, vl);
va_end(vl);
return retVal;
}

int main(int argc,char *argv[])
{
char szDrvMsg[] = "A:\n";
char mystr[]="This is a string printed with UCRT printf.\n";
unsigned long uDriveMask;

printf("%s\n",_strupr(mystr));

printf("Detected logical drives:\n");

uDriveMask = _getdrives();

while (uDriveMask) {
if (uDriveMask & 1)
printf(szDrvMsg);
++szDrvMsg[0];
         uDriveMask >>= 1;
      }

return 0;
}

Determining the functions imported by the example code :

Code: [Select]
\PellesC\bin\podump.exe /IMPORTS Hello32.exe
Code: [Select]
Dump of Hello32.exe

File type: EXE

        Imported symbols

        api-ms-win-crt-stdio-l1-1-0.dll
               0 time date stamp (Thu Jan  1 03:00:00 1970)

        hint  name
           0  __acrt_iob_func
           3  __stdio_common_vfprintf

        api-ms-win-crt-string-l1-1-0.dll
               0 time date stamp (Thu Jan  1 03:00:00 1970)

        hint  name
          3D  _strupr

        api-ms-win-crt-filesystem-l1-1-0.dll
               0 time date stamp (Thu Jan  1 03:00:00 1970)

        hint  name
          15  _getdrives

        KERNEL32.dll
               0 time date stamp (Thu Jan  1 03:00:00 1970)

        hint  name
           0  GetCommandLineA
           0  ExitProcess
Code it... That's all...

Offline Akko

  • Member
  • *
  • Posts: 31
Re: Import libraries for the Universal C Runtime
« Reply #1 on: December 11, 2023, 12:24:43 PM »
Thanks for sharing!
I may be dense, but what is the benefit over using Pelles C functions directly?

Offline Vortex

  • Member
  • *
  • Posts: 865
    • http://www.vortex.masmcode.com
Re: Import libraries for the Universal C Runtime
« Reply #2 on: December 11, 2023, 03:17:12 PM »
Hi Akko,

Pelle's C run-rime library is very good. If one day MS is deciding to remove the traditional msvcrt.dll, the replacement will be the new Universal C Runtime. My library is just an attempt to be prepared for tomorrow.
Code it... That's all...

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Import libraries for the Universal C Runtime
« Reply #3 on: December 12, 2023, 02:34:22 PM »
If someone want to compare different functions, how those works other than Pelles C crt, how someone do that without different compiler system ?
msvcrt.dll and ucrtbase.dll + others are Windows OS dlls, that will be mostly in every Windows OSes
Also a linker's map-file is easier to read.

Also poasm users needs simple way to print out variables, while testing and sharing code examples.

« Last Edit: December 12, 2023, 07:05:07 PM by TimoVJL »
May the source be with you

Offline Vortex

  • Member
  • *
  • Posts: 865
    • http://www.vortex.masmcode.com
Re: Import libraries for the Universal C Runtime
« Reply #4 on: February 22, 2024, 07:23:39 PM »
Hello,

The MS tools to build the import libraries can be obtained from here :

https://github.com/Data-Oriented-House/PortableBuildTools
Code it... That's all...