www.digitalmars.com         C & C++   DMDScript  

c++ - CPU USage Dll??

reply "Tobi Mobile" <tobi klangwerk.de> writes:
Hi there coders..

i am totally new to cpp and i am trying to make a dll that returns th
cpuusage,
what i have done is this :
----------------------------------------------------------------------------
----------------------------
// cpuusage.cpp (Windows NT/2000)
//
// Returns the CPU usage in percent on Windows NT/2000
//

#include <windows.h>
#include <conio.h>
#include <stdio.h>

#define SystemBasicInformation 0
#define SystemPerformanceInformation 2
#define SystemTimeInformation 3

#define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 +
(double)((x).LowPart))

/* The exported functions */
extern "C"
{
__declspec(dllexport) UINT GetCPUusage();
}

typedef struct
{
    DWORD dwUnknown1;
    ULONG uKeMaximumIncrement;
    ULONG uPageSize;
    ULONG uMmNumberOfPhysicalPages;
    ULONG uMmLowestPhysicalPage;
    ULONG uMmHighestPhysicalPage;
    ULONG uAllocationGranularity;
    PVOID pLowestUserAddress;
    PVOID pMmHighestUserAddress;
    ULONG uKeActiveProcessors;
    BYTE bKeNumberProcessors;
    BYTE bUnknown2;
    WORD wUnknown3;
} SYSTEM_BASIC_INFORMATION;

typedef struct
{
    LARGE_INTEGER liIdleTime;
    DWORD dwSpare[76];
} SYSTEM_PERFORMANCE_INFORMATION;

typedef struct
{
    LARGE_INTEGER liKeBootTime;
    LARGE_INTEGER liKeSystemTime;
    LARGE_INTEGER liExpTimeZoneBias;
    ULONG uCurrentTimeZoneId;
    DWORD dwReserved;
} SYSTEM_TIME_INFORMATION;

typedef LONG (WINAPI *PROCNTQSI)(UINT,PVOID,ULONG,PULONG);

PROCNTQSI NtQuerySystemInformation;

UINT GetCPUusage() //dllMain() //
{
    SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo;
    SYSTEM_TIME_INFORMATION SysTimeInfo;
    SYSTEM_BASIC_INFORMATION SysBaseInfo;
    double dbIdleTime;
    double dbSystemTime;
    LONG status;
    LARGE_INTEGER liOldIdleTime = {0,0};
    LARGE_INTEGER liOldSystemTime = {0,0};
    UINT x=0;

    NtQuerySystemInformation = (PROCNTQSI)GetProcAddress(
GetModuleHandle("ntdll"), "NtQuerySystemInformation" );

    if (!NtQuerySystemInformation)
        return (0);

    // get number of processors in the system
    status = NtQuerySystemInformation(
SystemBasicInformation,&SysBaseInfo,sizeof(SysBaseInfo),NULL );
    if (status != NO_ERROR)
        return (0);

    //printf("\nCPU Usage (press any key to exit): ");
    while( x != 2 )
    {
        // get new system time
        status = NtQuerySystemInformation(
SystemTimeInformation,&SysTimeInfo,sizeof(SysTimeInfo),0 );
        if (status!=NO_ERROR)
            return (0);

        // get new CPU's idle time
        status = NtQuerySystemInformation(
SystemPerformanceInformation,&SysPerfInfo,sizeof(SysPerfInfo),NULL );
        if (status != NO_ERROR)
            return (0);

        // if it's a first call - skip it
        if (liOldIdleTime.QuadPart != 0)
        {
            // CurrentValue = NewValue - OldValue
            dbIdleTime = Li2Double(SysPerfInfo.liIdleTime) -
Li2Double(liOldIdleTime);
            dbSystemTime = Li2Double(SysTimeInfo.liKeSystemTime) -
Li2Double(liOldSystemTime);

            // CurrentCpuIdle = IdleTime / SystemTime
            dbIdleTime = dbIdleTime / dbSystemTime;

            // CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) /
NumberOfProcessors
            dbIdleTime = 100.0 - dbIdleTime * 100.0 /
(double)SysBaseInfo.bKeNumberProcessors + 0.5;

            //printf("\b\b\b\b%3d%",(UINT)dbIdleTime);
         //printf ("Usage : ",(UINT)dbIdleTime);
        }

        // store new CPU's idle and system time
        liOldIdleTime = SysPerfInfo.liIdleTime;
        liOldSystemTime = SysTimeInfo.liKeSystemTime;
        x++;
    }
   return (UINT)dbIdleTime;
}
----------------------------------------------------------------------------
-------------------------

so please be so nice and help me out..

when i compile this script typing "dmc -mn -WD cpuusage2"
all seems to be right, than the optlink compiler starts and prints the
following:
----------------------------------------------------------------------------
-------------------------
C:\dm\bin>dmc -mn -WD cpuusage
link cpuusage,,,,cpuusage/noi;
OPTLINK (R) for Win32  Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

cpuusage.obj(cpuusage)
 Error 42: Symbol Undefined _GetProcAddress 8
cpuusage.obj(cpuusage)
 Error 42: Symbol Undefined _GetModuleHandleA 4
C:\dm\bin\..\lib\SNN.lib(isctype)
 Error 42: Symbol Undefined _GetStringTypeA 20
C:\dm\bin\..\lib\SNN.lib(tolower)
 Error 42: Symbol Undefined _LCMapStringA 24
C:\dm\bin\..\lib\SNN.lib(MBTOWC)
 Error 42: Symbol Undefined _MultiByteToWideChar 24
C:\dm\bin\..\lib\SNN.lib(thsup)
 Error 42: Symbol Undefined _GetCurrentThreadId 0
C:\dm\bin\..\lib\SNN.lib(semlock)
 Error 42: Symbol Undefined _CreateSemaphoreA 16
C:\dm\bin\..\lib\SNN.lib(semlock)
 Error 42: Symbol Undefined _ReleaseSemaphore 12
C:\dm\bin\..\lib\SNN.lib(semlock)
 Error 42: Symbol Undefined _WaitForSingleObject 8
C:\dm\bin\..\lib\SNN.lib(except)
 Error 42: Symbol Undefined _SetUnhandledExceptionFilter 4
C:\dm\bin\..\lib\SNN.lib(signal)
 Error 42: Symbol Undefined _SetConsoleCtrlHandler 8
C:\dm\bin\..\lib\SNN.lib(ehsup)
 Error 42: Symbol Undefined _RtlUnwind 16
C:\dm\bin\..\lib\SNN.lib(rtti)
 Error 42: Symbol Undefined _RaiseException 16
C:\dm\bin\..\lib\SNN.lib(cinit)
 Error 42: Symbol Undefined _GetEnvironmentStrings 0
C:\dm\bin\..\lib\SNN.lib(cinit)
 Error 42: Symbol Undefined _GetVersion 0
C:\dm\bin\..\lib\SNN.lib(cinit)
 Error 42: Symbol Undefined _FreeEnvironmentStringsA 4
C:\dm\bin\..\lib\SNN.lib(sbrk)
 Error 42: Symbol Undefined _VirtualFree 12
C:\dm\bin\..\lib\SNN.lib(sbrk)
 Error 42: Symbol Undefined _VirtualAlloc 16
C:\dm\bin\..\lib\SNN.lib(_exit)
 Error 42: Symbol Undefined _ExitProcess 4
C:\dm\bin\..\lib\SNN.lib(setnterr)
 Error 42: Symbol Undefined _GetLastError 0
C:\dm\bin\..\lib\SNN.lib(w32fater)
 Error 42: Symbol Undefined _GetStdHandle 4
C:\dm\bin\..\lib\SNN.lib(w32fater)
 Error 42: Symbol Undefined _WriteConsoleA 20

--- errorlevel 22
----------------------------------------------------------------------------
-------------------------

so.. any ideas on this??
what have i done wrong??

regards,
tobias wölki

-----------------------------------------------------
http://www.klangwerk.de
http://www.paraphonatic.de
http://www.tomcloud.de
mobile://+49.(0).172.5223442

ACHTUNG NEU :
Die Foren vom Klangwerk:
http://forum.klangwerk.de
http://www.hardcorebase.de
Einfach mal reinschauen und mitquatschen!!

EXTREM GEIL:
Besucht unseren neuen Shop..
http://www.equisto.de/klangwerk
-----------------------------------------------------
Jun 05 2003
parent reply "Walter" <walter digitalmars.com> writes:
You'll need a DllMain() for your dll.

"Tobi   Mobile" <tobi klangwerk.de> wrote in message
news:bbn6uk$2m5q$1 digitaldaemon.com...
 Hi there coders..

 i am totally new to cpp and i am trying to make a dll that returns th
 cpuusage,
 what i have done is this :
 --------------------------------------------------------------------------

 ----------------------------
 // cpuusage.cpp (Windows NT/2000)
 //
 // Returns the CPU usage in percent on Windows NT/2000
 //

 #include <windows.h>
 #include <conio.h>
 #include <stdio.h>

 #define SystemBasicInformation 0
 #define SystemPerformanceInformation 2
 #define SystemTimeInformation 3

 #define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 +
 (double)((x).LowPart))

 /* The exported functions */
 extern "C"
 {
 __declspec(dllexport) UINT GetCPUusage();
 }

 typedef struct
 {
     DWORD dwUnknown1;
     ULONG uKeMaximumIncrement;
     ULONG uPageSize;
     ULONG uMmNumberOfPhysicalPages;
     ULONG uMmLowestPhysicalPage;
     ULONG uMmHighestPhysicalPage;
     ULONG uAllocationGranularity;
     PVOID pLowestUserAddress;
     PVOID pMmHighestUserAddress;
     ULONG uKeActiveProcessors;
     BYTE bKeNumberProcessors;
     BYTE bUnknown2;
     WORD wUnknown3;
 } SYSTEM_BASIC_INFORMATION;

 typedef struct
 {
     LARGE_INTEGER liIdleTime;
     DWORD dwSpare[76];
 } SYSTEM_PERFORMANCE_INFORMATION;

 typedef struct
 {
     LARGE_INTEGER liKeBootTime;
     LARGE_INTEGER liKeSystemTime;
     LARGE_INTEGER liExpTimeZoneBias;
     ULONG uCurrentTimeZoneId;
     DWORD dwReserved;
 } SYSTEM_TIME_INFORMATION;

 typedef LONG (WINAPI *PROCNTQSI)(UINT,PVOID,ULONG,PULONG);

 PROCNTQSI NtQuerySystemInformation;

 UINT GetCPUusage() //dllMain() //
 {
     SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo;
     SYSTEM_TIME_INFORMATION SysTimeInfo;
     SYSTEM_BASIC_INFORMATION SysBaseInfo;
     double dbIdleTime;
     double dbSystemTime;
     LONG status;
     LARGE_INTEGER liOldIdleTime = {0,0};
     LARGE_INTEGER liOldSystemTime = {0,0};
     UINT x=0;

     NtQuerySystemInformation = (PROCNTQSI)GetProcAddress(
 GetModuleHandle("ntdll"), "NtQuerySystemInformation" );

     if (!NtQuerySystemInformation)
         return (0);

     // get number of processors in the system
     status = NtQuerySystemInformation(
 SystemBasicInformation,&SysBaseInfo,sizeof(SysBaseInfo),NULL );
     if (status != NO_ERROR)
         return (0);

     //printf("\nCPU Usage (press any key to exit): ");
     while( x != 2 )
     {
         // get new system time
         status = NtQuerySystemInformation(
 SystemTimeInformation,&SysTimeInfo,sizeof(SysTimeInfo),0 );
         if (status!=NO_ERROR)
             return (0);

         // get new CPU's idle time
         status = NtQuerySystemInformation(
 SystemPerformanceInformation,&SysPerfInfo,sizeof(SysPerfInfo),NULL );
         if (status != NO_ERROR)
             return (0);

         // if it's a first call - skip it
         if (liOldIdleTime.QuadPart != 0)
         {
             // CurrentValue = NewValue - OldValue
             dbIdleTime = Li2Double(SysPerfInfo.liIdleTime) -
 Li2Double(liOldIdleTime);
             dbSystemTime = Li2Double(SysTimeInfo.liKeSystemTime) -
 Li2Double(liOldSystemTime);

             // CurrentCpuIdle = IdleTime / SystemTime
             dbIdleTime = dbIdleTime / dbSystemTime;

             // CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) /
 NumberOfProcessors
             dbIdleTime = 100.0 - dbIdleTime * 100.0 /
 (double)SysBaseInfo.bKeNumberProcessors + 0.5;

             //printf("\b\b\b\b%3d%",(UINT)dbIdleTime);
          //printf ("Usage : ",(UINT)dbIdleTime);
         }

         // store new CPU's idle and system time
         liOldIdleTime = SysPerfInfo.liIdleTime;
         liOldSystemTime = SysTimeInfo.liKeSystemTime;
         x++;
     }
    return (UINT)dbIdleTime;
 }
 --------------------------------------------------------------------------

 -------------------------

 so please be so nice and help me out..

 when i compile this script typing "dmc -mn -WD cpuusage2"
 all seems to be right, than the optlink compiler starts and prints the
 following:
 --------------------------------------------------------------------------

 -------------------------
 C:\dm\bin>dmc -mn -WD cpuusage
 link cpuusage,,,,cpuusage/noi;
 OPTLINK (R) for Win32  Release 7.50B1
 Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

 cpuusage.obj(cpuusage)
  Error 42: Symbol Undefined _GetProcAddress 8
 cpuusage.obj(cpuusage)
  Error 42: Symbol Undefined _GetModuleHandleA 4
 C:\dm\bin\..\lib\SNN.lib(isctype)
  Error 42: Symbol Undefined _GetStringTypeA 20
 C:\dm\bin\..\lib\SNN.lib(tolower)
  Error 42: Symbol Undefined _LCMapStringA 24
 C:\dm\bin\..\lib\SNN.lib(MBTOWC)
  Error 42: Symbol Undefined _MultiByteToWideChar 24
 C:\dm\bin\..\lib\SNN.lib(thsup)
  Error 42: Symbol Undefined _GetCurrentThreadId 0
 C:\dm\bin\..\lib\SNN.lib(semlock)
  Error 42: Symbol Undefined _CreateSemaphoreA 16
 C:\dm\bin\..\lib\SNN.lib(semlock)
  Error 42: Symbol Undefined _ReleaseSemaphore 12
 C:\dm\bin\..\lib\SNN.lib(semlock)
  Error 42: Symbol Undefined _WaitForSingleObject 8
 C:\dm\bin\..\lib\SNN.lib(except)
  Error 42: Symbol Undefined _SetUnhandledExceptionFilter 4
 C:\dm\bin\..\lib\SNN.lib(signal)
  Error 42: Symbol Undefined _SetConsoleCtrlHandler 8
 C:\dm\bin\..\lib\SNN.lib(ehsup)
  Error 42: Symbol Undefined _RtlUnwind 16
 C:\dm\bin\..\lib\SNN.lib(rtti)
  Error 42: Symbol Undefined _RaiseException 16
 C:\dm\bin\..\lib\SNN.lib(cinit)
  Error 42: Symbol Undefined _GetEnvironmentStrings 0
 C:\dm\bin\..\lib\SNN.lib(cinit)
  Error 42: Symbol Undefined _GetVersion 0
 C:\dm\bin\..\lib\SNN.lib(cinit)
  Error 42: Symbol Undefined _FreeEnvironmentStringsA 4
 C:\dm\bin\..\lib\SNN.lib(sbrk)
  Error 42: Symbol Undefined _VirtualFree 12
 C:\dm\bin\..\lib\SNN.lib(sbrk)
  Error 42: Symbol Undefined _VirtualAlloc 16
 C:\dm\bin\..\lib\SNN.lib(_exit)
  Error 42: Symbol Undefined _ExitProcess 4
 C:\dm\bin\..\lib\SNN.lib(setnterr)
  Error 42: Symbol Undefined _GetLastError 0
 C:\dm\bin\..\lib\SNN.lib(w32fater)
  Error 42: Symbol Undefined _GetStdHandle 4
 C:\dm\bin\..\lib\SNN.lib(w32fater)
  Error 42: Symbol Undefined _WriteConsoleA 20

 --- errorlevel 22
 --------------------------------------------------------------------------

 -------------------------

 so.. any ideas on this??
 what have i done wrong??

 regards,
 tobias wölki

 -----------------------------------------------------
 http://www.klangwerk.de
 http://www.paraphonatic.de
 http://www.tomcloud.de
 mobile://+49.(0).172.5223442

 ACHTUNG NEU :
 Die Foren vom Klangwerk:
 http://forum.klangwerk.de
 http://www.hardcorebase.de
 Einfach mal reinschauen und mitquatschen!!

 EXTREM GEIL:
 Besucht unseren neuen Shop..
 http://www.equisto.de/klangwerk
 -----------------------------------------------------

Jun 05 2003
parent reply "Tobi Mobile" <tobi klangwerk.de> writes:
Hi Walter,

and thank you first for your reply,
i have noticed that i need a DllMain(), bu i am not clear where to put it,
and how the
syntax is..

do i have the includes in the dllmain??
pleas show me where to put it that my script runs..

thanks in advance..

tobi;)
"Walter" <walter digitalmars.com> schrieb im Newsbeitrag
news:bbnu1d$b19$1 digitaldaemon.com...
 You'll need a DllMain() for your dll.

 "Tobi   Mobile" <tobi klangwerk.de> wrote in message
 news:bbn6uk$2m5q$1 digitaldaemon.com...
 Hi there coders..

 i am totally new to cpp and i am trying to make a dll that returns th
 cpuusage,
 what i have done is this :

-------------------------------------------------------------------------- --
 ----------------------------
 // cpuusage.cpp (Windows NT/2000)
 //
 // Returns the CPU usage in percent on Windows NT/2000
 //

 #include <windows.h>
 #include <conio.h>
 #include <stdio.h>

 #define SystemBasicInformation 0
 #define SystemPerformanceInformation 2
 #define SystemTimeInformation 3

 #define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 +
 (double)((x).LowPart))

 /* The exported functions */
 extern "C"
 {
 __declspec(dllexport) UINT GetCPUusage();
 }

 typedef struct
 {
     DWORD dwUnknown1;
     ULONG uKeMaximumIncrement;
     ULONG uPageSize;
     ULONG uMmNumberOfPhysicalPages;
     ULONG uMmLowestPhysicalPage;
     ULONG uMmHighestPhysicalPage;
     ULONG uAllocationGranularity;
     PVOID pLowestUserAddress;
     PVOID pMmHighestUserAddress;
     ULONG uKeActiveProcessors;
     BYTE bKeNumberProcessors;
     BYTE bUnknown2;
     WORD wUnknown3;
 } SYSTEM_BASIC_INFORMATION;

 typedef struct
 {
     LARGE_INTEGER liIdleTime;
     DWORD dwSpare[76];
 } SYSTEM_PERFORMANCE_INFORMATION;

 typedef struct
 {
     LARGE_INTEGER liKeBootTime;
     LARGE_INTEGER liKeSystemTime;
     LARGE_INTEGER liExpTimeZoneBias;
     ULONG uCurrentTimeZoneId;
     DWORD dwReserved;
 } SYSTEM_TIME_INFORMATION;

 typedef LONG (WINAPI *PROCNTQSI)(UINT,PVOID,ULONG,PULONG);

 PROCNTQSI NtQuerySystemInformation;

 UINT GetCPUusage() //dllMain() //
 {
     SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo;
     SYSTEM_TIME_INFORMATION SysTimeInfo;
     SYSTEM_BASIC_INFORMATION SysBaseInfo;
     double dbIdleTime;
     double dbSystemTime;
     LONG status;
     LARGE_INTEGER liOldIdleTime = {0,0};
     LARGE_INTEGER liOldSystemTime = {0,0};
     UINT x=0;

     NtQuerySystemInformation = (PROCNTQSI)GetProcAddress(
 GetModuleHandle("ntdll"), "NtQuerySystemInformation" );

     if (!NtQuerySystemInformation)
         return (0);

     // get number of processors in the system
     status = NtQuerySystemInformation(
 SystemBasicInformation,&SysBaseInfo,sizeof(SysBaseInfo),NULL );
     if (status != NO_ERROR)
         return (0);

     //printf("\nCPU Usage (press any key to exit): ");
     while( x != 2 )
     {
         // get new system time
         status = NtQuerySystemInformation(
 SystemTimeInformation,&SysTimeInfo,sizeof(SysTimeInfo),0 );
         if (status!=NO_ERROR)
             return (0);

         // get new CPU's idle time
         status = NtQuerySystemInformation(
 SystemPerformanceInformation,&SysPerfInfo,sizeof(SysPerfInfo),NULL );
         if (status != NO_ERROR)
             return (0);

         // if it's a first call - skip it
         if (liOldIdleTime.QuadPart != 0)
         {
             // CurrentValue = NewValue - OldValue
             dbIdleTime = Li2Double(SysPerfInfo.liIdleTime) -
 Li2Double(liOldIdleTime);
             dbSystemTime = Li2Double(SysTimeInfo.liKeSystemTime) -
 Li2Double(liOldSystemTime);

             // CurrentCpuIdle = IdleTime / SystemTime
             dbIdleTime = dbIdleTime / dbSystemTime;

             // CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) /
 NumberOfProcessors
             dbIdleTime = 100.0 - dbIdleTime * 100.0 /
 (double)SysBaseInfo.bKeNumberProcessors + 0.5;

             //printf("\b\b\b\b%3d%",(UINT)dbIdleTime);
          //printf ("Usage : ",(UINT)dbIdleTime);
         }

         // store new CPU's idle and system time
         liOldIdleTime = SysPerfInfo.liIdleTime;
         liOldSystemTime = SysTimeInfo.liKeSystemTime;
         x++;
     }
    return (UINT)dbIdleTime;
 }

-------------------------------------------------------------------------- --
 -------------------------

 so please be so nice and help me out..

 when i compile this script typing "dmc -mn -WD cpuusage2"
 all seems to be right, than the optlink compiler starts and prints the
 following:

-------------------------------------------------------------------------- --
 -------------------------
 C:\dm\bin>dmc -mn -WD cpuusage
 link cpuusage,,,,cpuusage/noi;
 OPTLINK (R) for Win32  Release 7.50B1
 Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

 cpuusage.obj(cpuusage)
  Error 42: Symbol Undefined _GetProcAddress 8
 cpuusage.obj(cpuusage)
  Error 42: Symbol Undefined _GetModuleHandleA 4
 C:\dm\bin\..\lib\SNN.lib(isctype)
  Error 42: Symbol Undefined _GetStringTypeA 20
 C:\dm\bin\..\lib\SNN.lib(tolower)
  Error 42: Symbol Undefined _LCMapStringA 24
 C:\dm\bin\..\lib\SNN.lib(MBTOWC)
  Error 42: Symbol Undefined _MultiByteToWideChar 24
 C:\dm\bin\..\lib\SNN.lib(thsup)
  Error 42: Symbol Undefined _GetCurrentThreadId 0
 C:\dm\bin\..\lib\SNN.lib(semlock)
  Error 42: Symbol Undefined _CreateSemaphoreA 16
 C:\dm\bin\..\lib\SNN.lib(semlock)
  Error 42: Symbol Undefined _ReleaseSemaphore 12
 C:\dm\bin\..\lib\SNN.lib(semlock)
  Error 42: Symbol Undefined _WaitForSingleObject 8
 C:\dm\bin\..\lib\SNN.lib(except)
  Error 42: Symbol Undefined _SetUnhandledExceptionFilter 4
 C:\dm\bin\..\lib\SNN.lib(signal)
  Error 42: Symbol Undefined _SetConsoleCtrlHandler 8
 C:\dm\bin\..\lib\SNN.lib(ehsup)
  Error 42: Symbol Undefined _RtlUnwind 16
 C:\dm\bin\..\lib\SNN.lib(rtti)
  Error 42: Symbol Undefined _RaiseException 16
 C:\dm\bin\..\lib\SNN.lib(cinit)
  Error 42: Symbol Undefined _GetEnvironmentStrings 0
 C:\dm\bin\..\lib\SNN.lib(cinit)
  Error 42: Symbol Undefined _GetVersion 0
 C:\dm\bin\..\lib\SNN.lib(cinit)
  Error 42: Symbol Undefined _FreeEnvironmentStringsA 4
 C:\dm\bin\..\lib\SNN.lib(sbrk)
  Error 42: Symbol Undefined _VirtualFree 12
 C:\dm\bin\..\lib\SNN.lib(sbrk)
  Error 42: Symbol Undefined _VirtualAlloc 16
 C:\dm\bin\..\lib\SNN.lib(_exit)
  Error 42: Symbol Undefined _ExitProcess 4
 C:\dm\bin\..\lib\SNN.lib(setnterr)
  Error 42: Symbol Undefined _GetLastError 0
 C:\dm\bin\..\lib\SNN.lib(w32fater)
  Error 42: Symbol Undefined _GetStdHandle 4
 C:\dm\bin\..\lib\SNN.lib(w32fater)
  Error 42: Symbol Undefined _WriteConsoleA 20

 --- errorlevel 22

-------------------------------------------------------------------------- --
 -------------------------

 so.. any ideas on this??
 what have i done wrong??

 regards,
 tobias wölki

 -----------------------------------------------------
 http://www.klangwerk.de
 http://www.paraphonatic.de
 http://www.tomcloud.de
 mobile://+49.(0).172.5223442

 ACHTUNG NEU :
 Die Foren vom Klangwerk:
 http://forum.klangwerk.de
 http://www.hardcorebase.de
 Einfach mal reinschauen und mitquatschen!!

 EXTREM GEIL:
 Besucht unseren neuen Shop..
 http://www.equisto.de/klangwerk
 -----------------------------------------------------


Jun 05 2003
parent "Walter" <walter digitalmars.com> writes:
I suggest getting the book "Advanced Windows" by Jeffrey Richter from
www.digitalmars.com/bibliography.html

It explains in detail how to set up DllMain(), what its arguments are, what
the contraints are, setting up the .def file, etc. It's not something I can
set out in a few lines.

"Tobi   Mobile" <tobi klangwerk.de> wrote in message
news:bbpcog$1k7j$1 digitaldaemon.com...
 Hi Walter,

 and thank you first for your reply,
 i have noticed that i need a DllMain(), bu i am not clear where to put it,
 and how the
 syntax is..

 do i have the includes in the dllmain??
 pleas show me where to put it that my script runs..

 thanks in advance..

 tobi;)
 "Walter" <walter digitalmars.com> schrieb im Newsbeitrag
 news:bbnu1d$b19$1 digitaldaemon.com...
 You'll need a DllMain() for your dll.

 "Tobi   Mobile" <tobi klangwerk.de> wrote in message
 news:bbn6uk$2m5q$1 digitaldaemon.com...
 Hi there coders..

 i am totally new to cpp and i am trying to make a dll that returns th
 cpuusage,
 what i have done is this :


--------------------------------------------------------------------------
 --
 ----------------------------
 // cpuusage.cpp (Windows NT/2000)
 //
 // Returns the CPU usage in percent on Windows NT/2000
 //

 #include <windows.h>
 #include <conio.h>
 #include <stdio.h>

 #define SystemBasicInformation 0
 #define SystemPerformanceInformation 2
 #define SystemTimeInformation 3

 #define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 +
 (double)((x).LowPart))

 /* The exported functions */
 extern "C"
 {
 __declspec(dllexport) UINT GetCPUusage();
 }

 typedef struct
 {
     DWORD dwUnknown1;
     ULONG uKeMaximumIncrement;
     ULONG uPageSize;
     ULONG uMmNumberOfPhysicalPages;
     ULONG uMmLowestPhysicalPage;
     ULONG uMmHighestPhysicalPage;
     ULONG uAllocationGranularity;
     PVOID pLowestUserAddress;
     PVOID pMmHighestUserAddress;
     ULONG uKeActiveProcessors;
     BYTE bKeNumberProcessors;
     BYTE bUnknown2;
     WORD wUnknown3;
 } SYSTEM_BASIC_INFORMATION;

 typedef struct
 {
     LARGE_INTEGER liIdleTime;
     DWORD dwSpare[76];
 } SYSTEM_PERFORMANCE_INFORMATION;

 typedef struct
 {
     LARGE_INTEGER liKeBootTime;
     LARGE_INTEGER liKeSystemTime;
     LARGE_INTEGER liExpTimeZoneBias;
     ULONG uCurrentTimeZoneId;
     DWORD dwReserved;
 } SYSTEM_TIME_INFORMATION;

 typedef LONG (WINAPI *PROCNTQSI)(UINT,PVOID,ULONG,PULONG);

 PROCNTQSI NtQuerySystemInformation;

 UINT GetCPUusage() //dllMain() //
 {
     SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo;
     SYSTEM_TIME_INFORMATION SysTimeInfo;
     SYSTEM_BASIC_INFORMATION SysBaseInfo;
     double dbIdleTime;
     double dbSystemTime;
     LONG status;
     LARGE_INTEGER liOldIdleTime = {0,0};
     LARGE_INTEGER liOldSystemTime = {0,0};
     UINT x=0;

     NtQuerySystemInformation = (PROCNTQSI)GetProcAddress(
 GetModuleHandle("ntdll"), "NtQuerySystemInformation" );

     if (!NtQuerySystemInformation)
         return (0);

     // get number of processors in the system
     status = NtQuerySystemInformation(
 SystemBasicInformation,&SysBaseInfo,sizeof(SysBaseInfo),NULL );
     if (status != NO_ERROR)
         return (0);

     //printf("\nCPU Usage (press any key to exit): ");
     while( x != 2 )
     {
         // get new system time
         status = NtQuerySystemInformation(
 SystemTimeInformation,&SysTimeInfo,sizeof(SysTimeInfo),0 );
         if (status!=NO_ERROR)
             return (0);

         // get new CPU's idle time
         status = NtQuerySystemInformation(
 SystemPerformanceInformation,&SysPerfInfo,sizeof(SysPerfInfo),NULL );
         if (status != NO_ERROR)
             return (0);

         // if it's a first call - skip it
         if (liOldIdleTime.QuadPart != 0)
         {
             // CurrentValue = NewValue - OldValue
             dbIdleTime = Li2Double(SysPerfInfo.liIdleTime) -
 Li2Double(liOldIdleTime);
             dbSystemTime = Li2Double(SysTimeInfo.liKeSystemTime) -
 Li2Double(liOldSystemTime);

             // CurrentCpuIdle = IdleTime / SystemTime
             dbIdleTime = dbIdleTime / dbSystemTime;

             // CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) /
 NumberOfProcessors
             dbIdleTime = 100.0 - dbIdleTime * 100.0 /
 (double)SysBaseInfo.bKeNumberProcessors + 0.5;

             //printf("\b\b\b\b%3d%",(UINT)dbIdleTime);
          //printf ("Usage : ",(UINT)dbIdleTime);
         }

         // store new CPU's idle and system time
         liOldIdleTime = SysPerfInfo.liIdleTime;
         liOldSystemTime = SysTimeInfo.liKeSystemTime;
         x++;
     }
    return (UINT)dbIdleTime;
 }


--------------------------------------------------------------------------
 --
 -------------------------

 so please be so nice and help me out..

 when i compile this script typing "dmc -mn -WD cpuusage2"
 all seems to be right, than the optlink compiler starts and prints the
 following:


--------------------------------------------------------------------------
 --
 -------------------------
 C:\dm\bin>dmc -mn -WD cpuusage
 link cpuusage,,,,cpuusage/noi;
 OPTLINK (R) for Win32  Release 7.50B1
 Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

 cpuusage.obj(cpuusage)
  Error 42: Symbol Undefined _GetProcAddress 8
 cpuusage.obj(cpuusage)
  Error 42: Symbol Undefined _GetModuleHandleA 4
 C:\dm\bin\..\lib\SNN.lib(isctype)
  Error 42: Symbol Undefined _GetStringTypeA 20
 C:\dm\bin\..\lib\SNN.lib(tolower)
  Error 42: Symbol Undefined _LCMapStringA 24
 C:\dm\bin\..\lib\SNN.lib(MBTOWC)
  Error 42: Symbol Undefined _MultiByteToWideChar 24
 C:\dm\bin\..\lib\SNN.lib(thsup)
  Error 42: Symbol Undefined _GetCurrentThreadId 0
 C:\dm\bin\..\lib\SNN.lib(semlock)
  Error 42: Symbol Undefined _CreateSemaphoreA 16
 C:\dm\bin\..\lib\SNN.lib(semlock)
  Error 42: Symbol Undefined _ReleaseSemaphore 12
 C:\dm\bin\..\lib\SNN.lib(semlock)
  Error 42: Symbol Undefined _WaitForSingleObject 8
 C:\dm\bin\..\lib\SNN.lib(except)
  Error 42: Symbol Undefined _SetUnhandledExceptionFilter 4
 C:\dm\bin\..\lib\SNN.lib(signal)
  Error 42: Symbol Undefined _SetConsoleCtrlHandler 8
 C:\dm\bin\..\lib\SNN.lib(ehsup)
  Error 42: Symbol Undefined _RtlUnwind 16
 C:\dm\bin\..\lib\SNN.lib(rtti)
  Error 42: Symbol Undefined _RaiseException 16
 C:\dm\bin\..\lib\SNN.lib(cinit)
  Error 42: Symbol Undefined _GetEnvironmentStrings 0
 C:\dm\bin\..\lib\SNN.lib(cinit)
  Error 42: Symbol Undefined _GetVersion 0
 C:\dm\bin\..\lib\SNN.lib(cinit)
  Error 42: Symbol Undefined _FreeEnvironmentStringsA 4
 C:\dm\bin\..\lib\SNN.lib(sbrk)
  Error 42: Symbol Undefined _VirtualFree 12
 C:\dm\bin\..\lib\SNN.lib(sbrk)
  Error 42: Symbol Undefined _VirtualAlloc 16
 C:\dm\bin\..\lib\SNN.lib(_exit)
  Error 42: Symbol Undefined _ExitProcess 4
 C:\dm\bin\..\lib\SNN.lib(setnterr)
  Error 42: Symbol Undefined _GetLastError 0
 C:\dm\bin\..\lib\SNN.lib(w32fater)
  Error 42: Symbol Undefined _GetStdHandle 4
 C:\dm\bin\..\lib\SNN.lib(w32fater)
  Error 42: Symbol Undefined _WriteConsoleA 20

 --- errorlevel 22


--------------------------------------------------------------------------
 --
 -------------------------

 so.. any ideas on this??
 what have i done wrong??

 regards,
 tobias wölki

 -----------------------------------------------------
 http://www.klangwerk.de
 http://www.paraphonatic.de
 http://www.tomcloud.de
 mobile://+49.(0).172.5223442

 ACHTUNG NEU :
 Die Foren vom Klangwerk:
 http://forum.klangwerk.de
 http://www.hardcorebase.de
 Einfach mal reinschauen und mitquatschen!!

 EXTREM GEIL:
 Besucht unseren neuen Shop..
 http://www.equisto.de/klangwerk
 -----------------------------------------------------



Jun 05 2003