C++ Problem mit __stdcall

Hi Leute, ich bin schon fast am Verzweifeln.. ich habe folgenden code:

Code:
private:
    void Init() const;

    typedef NTSTATUS (WINAPI *P_NTQSI)( SYSTEM_INFORMATION_CLASS, PVOID, ULONG, PULONG );

    mutable bool m_bInitialised;

    mutable P_NTQSI m_p_NtQuerySystemInformation;
    mutable int m_processorCount;
    mutable unsigned __int64 m_lastIdleTime, m_lastUserTime, m_lastKernelTime; 
    int m_scaleFactor;

und bekomme da folgende Fehler:
d:\CPU\CpuUsage.cpp(23): error C3861: 'm_p_NtQuerySystemInformation': Bezeichner wurde auch mit einer argumentbezogenen Suche nicht gefunden
d:\CPU\CpuUsage.h(33): error C2059: Syntaxfehler: '__stdcall'
d:\CPU\CpuUsage.h(33): error C2059: Syntaxfehler: '__stdcall'
d:\CPU\CpuUsage.h(33): error C2061: Syntaxfehler: Bezeichner 'SYSTEM_INFORMATION_CLASS'
d:\CPU\CpuUsage.h(33): error C2061: Syntaxfehler: Bezeichner 'SYSTEM_INFORMATION_CLASS'
d:\CPU\CpuUsage.h(33): error C2091: Funktionsergebnis ist eine Funktion
d:\CPU\CpuUsage.h(33): error C2091: Funktionsergebnis ist eine Funktion
d:\CPU\CpuUsage.h(37): error C2146: Syntaxfehler: Fehlendes ';' vor Bezeichner 'm_p_NtQuerySystemInformation'
d:\CPU\CpuUsage.h(37): error C2146: Syntaxfehler: Fehlendes ';' vor Bezeichner 'm_p_NtQuerySystemInformation'
d:\CPU\CpuUsage.h(37): error C2501: 'CCpuUsage::m_p_NtQuerySystemInformation': Fehlende Speicherklasse oder Typspezifizierer
d:\CPU\CpuUsage.h(37): error C2501: 'CCpuUsage::m_p_NtQuerySystemInformation': Fehlende Speicherklasse oder Typspezifizierer
d:\CPU\CpuUsage.h(37): error C2501: 'CCpuUsage::P_NTQSI': Fehlende Speicherklasse oder Typspezifizierer
d:\CPU\CpuUsage.h(37): error C2501: 'CCpuUsage::P_NTQSI': Fehlende Speicherklasse oder Typspezifizierer

Sieht jemand, was ich falsch mache? Laut MSDN ist die Syntax für __stdcall richtig so...

EDIT: 26 Hits schon, und keiner weiß was :(
 
Ich würde dir gerne helfen aber das ist schon Hardcore das problem was du hast ... ich habe diese Deklarationen noch nie gesehen ...

sag mir mal was du da machen wolltest vllt bekomm ich so einen Gedankensblitz der dir helfen könnte
 
Eine Frage noch, gibt der Compiler nicht an in welcher Zeile der Fehler ist ?
 
Meistens ist der fehler eine zeile davor.

und ein:
Code:
void Init() const;

sieht für mich sehr merkwürdig aus.

mfg
 
ja meine ich auch ... wenn du eine Konstante erstellen willst ist die Sytax in C++

const int .....;
 
also erstens geht das mit dem const so, kann man machen, und zweitens, hab ich die fehler trotzdem noch, wenn ich das wegnehme...
 
void Init() const;
sollte man nicht mit einer konstanten Variablendekleration verwechseln, nur so nebenbei.
Bei typedefs bin ich mir nicht sicher ob diese im Klassenrumpf stehen dürfen.
 
Hier mal der Komplettsource.. ich find einfach den Fehler nicht und werde fast bescheuert...
.h:
Code:
#if !defined(AFX_CPUUSAGE_H__A81CF652_6568_4BBB_91DA_4C1A40237D10__INCLUDED_)
#define AFX_CPUUSAGE_H__A81CF652_6568_4BBB_91DA_4C1A40237D10__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <afxwin.h>
#include <winternl.h>

#include <vector>

//=======================================================================================
//
// INTERFACE: Class CCpuUsage
//
//=======================================================================================
class CCpuUsage  
{
public:
	CCpuUsage();
	virtual ~CCpuUsage();

    inline bool GetSupported();
    int GetCpuUsage( int* pKernelPercent = NULL, int* pUserPercent = NULL );
    void SetScale( int factor = 100 );
    int GetScale() const { return m_scaleFactor; }

private:
    void Init();

    typedef NTSTATUS (WINAPI* P_NTQSI)( SYSTEM_INFORMATION_CLASS, PVOID, ULONG, PULONG );

    mutable bool m_bInitialised;

    mutable P_NTQSI m_p_NtQuerySystemInformation;
    mutable int m_processorCount;
    mutable unsigned __int64 m_lastIdleTime, m_lastUserTime, m_lastKernelTime; 
    int m_scaleFactor;
};

//---------------------------------------------------------------------------------------
// INLINE IMPLEMENTATION: Class CCpuUsage
//---------------------------------------------------------------------------------------

bool CCpuUsage::GetSupported()
{
    if( ! m_bInitialised )
        Init();
    return m_p_NtQuerySystemInformation != NULL;
}

//---------------------------------------------------------------------------------------

#endif // !defined(AFX_CPUUSAGE_H__A81CF652_6568_4BBB_91DA_4C1A40237D10__INCLUDED_)

.cpp:
Code:
#include "stdafx.h"
#include "CpuUsage.h"

using namespace std;


#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//from the "ntstatus.h" file:
#define STATUS_SUCCESS ((NTSTATUS)0x00000000L) // ntsubauth

//---------------------------------------------------------------------------------------

CCpuUsage::CCpuUsage()
{
    m_bInitialised = false;
    m_processorCount = 0;
    m_p_NtQuerySystemInformation = NULL;
    m_lastIdleTime = m_lastUserTime = m_lastKernelTime = 0; 
    m_scaleFactor = 100;
}

//---------------------------------------------------------------------------------------

CCpuUsage::~CCpuUsage()
{
    //unused
}

//---------------------------------------------------------------------------------------

void CCpuUsage::Init()
{
    m_bInitialised = true;

    //--- check if we have at least Win 2000
    OSVERSIONINFO ovi = { sizeof(ovi) };
    ::GetVersionEx( &ovi );
    if( ovi.dwMajorVersion < 5 )
        return;

    HMODULE hMod = ::GetModuleHandle( _T("ntdll.dll") );
    if( hMod )
        m_p_NtQuerySystemInformation = reinterpret_cast<P_NTQSI>(
                    ::GetProcAddress( hMod, "NtQuerySystemInformation" ) );

    if( m_p_NtQuerySystemInformation )
    {
        //--- get number of processors
        SYSTEM_BASIC_INFORMATION sbi = { 0 };
        NTSTATUS res = m_p_NtQuerySystemInformation( SystemBasicInformation, 
                                                     &sbi, sizeof(sbi), NULL );
        if( res == STATUS_SUCCESS )
            m_processorCount = sbi.NumberOfProcessors;
    }
}

//---------------------------------------------------------------------------------------

int CCpuUsage::GetCpuUsage( int* pKernelPercent, int* pUserPercent ) 
{
    if( ! m_bInitialised )
        Init();   

    // default values will indicate error
    if( pKernelPercent ) *pKernelPercent = -1;
    if( pUserPercent ) *pUserPercent = -1;

    // return if the function is not supported ---
    if( ! m_p_NtQuerySystemInformation )
        return -1;

    bool bSuccess = false;
    unsigned __int64 kernelTime = 0, userTime = 0, idleTime = 0;

    vector<SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION> sppi( m_processorCount );
    NTSTATUS res = m_p_NtQuerySystemInformation( SystemProcessorPerformanceInformation,
              &sppi[0], sizeof(sppi[0]) * sppi.size(), NULL );
    if( res == STATUS_SUCCESS )
    {
        //--- sum CPU usage times for all processors in the system
        for( int i = 0; i < m_processorCount; i++ )
        {
            kernelTime += sppi[i].KernelTime.QuadPart;
            userTime += sppi[i].UserTime.QuadPart;
            idleTime += sppi[i].IdleTime.QuadPart;
        }

        //--- calculate percentages of whatever scale the user of the class wants

        unsigned __int64 kernelTimeDiff = kernelTime - m_lastKernelTime;
        unsigned __int64 userTimeDiff = userTime - m_lastUserTime;
        unsigned __int64 idleTimeDiff = idleTime - m_lastIdleTime;

        unsigned __int64 totalTimeDiff = kernelTimeDiff + userTimeDiff;
        if( totalTimeDiff == 0 ) totalTimeDiff = 1;
        int totalUsagePercent = (totalTimeDiff - idleTimeDiff) * m_scaleFactor / totalTimeDiff;

        if( pKernelPercent )
            *pKernelPercent = (kernelTimeDiff - idleTimeDiff) * m_scaleFactor / totalTimeDiff;
        if( pUserPercent )
            *pUserPercent = userTimeDiff * m_scaleFactor / totalTimeDiff;

        m_lastKernelTime = kernelTime;
        m_lastUserTime = userTime;
        m_lastIdleTime = idleTime;

        return totalUsagePercent;
    }
    
    return -1;
}

EDIT: wie ihr seht, habe ich das const mal weggenommen, was leider auch nix bringt :(
 
Zurück
Oben