tags:

views:

114

answers:

4

Can I link a member function like this in some way? redeclaring the method as a member and get it call the Mmsystem.h method to not have to wrap it?

#include <windows.h>
#include <Mmsystem.h>

  namespace SoundLib {

 public class CWave
 {
 public:
  // WaveIn call
  external UINT waveOutGetNumDevs(VOID);
 };

}
+1  A: 

Sorry, no, you can't.

Autopulated
+1  A: 

No, you have to wrap it. Additionally, your code has some errors, such as external versus extern (though that was theoretical anyway) and public before your class.

GMan
Thanks! I'm really not a C++ programmer. I just playing with it. Anyway, using VS2008 it not complaims about public before the class name. But like you said its theoretical. I'm going to wrap it.
Ruben Trancoso
+4  A: 

No, but you can wrap it with inline and even static and hope that compiler is smart enough (which it likely is).

class CWave {
public:
    static inline UINT waveOutGetNumDevs(void) { return ::waveOutGetNumDevs(); }
};
Michael Krelin - hacker
This code will cause infinite recursion.
R Samuel Klatchko
should be `{ return ::waveOutGetNumDevs(); }`
John Knoeller
Thanks, guys, of course. I've fixed it.
Michael Krelin - hacker
+5  A: 

You will need to explicitly call the function you wrapped:

class CWave
{
public:
    static UINT waveOutGetNumDevs(VOID)
    {
        return ::waveOutGetNumDevs();
    }
};

Note the double colon. Since your method and the global function have the same name, you need the double colon to prevent infinite recursion.

R Samuel Klatchko