Thread: Visual C++ Linking with mmsystem.h

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    8

    Visual C++ Linking with mmsystem.h

    Hello I am trying to write a simple sound recorder in a win32 forms application using visual c++ and am having problems linking to mmsystem.h I have the recorder working fine in a console application but cannot get it to work as a win32 app. when trying to reference the function waveInGetNumDevs() I get a linking error when trying to compile:

    Error 1 error LNK2028: unresolved token (0A000031) "extern "C" unsigned int __stdcall waveInGetNumDevs(void)" (?waveInGetNumDevs@@$$J10YGIXZ) referenced in function "public: __clrcall record::Form1::Form1(void)" (??0Form1@record@@$$FQ$AAM@XZ) record.objrecord


    I am assuming this has to do with managed and unmanaged code mixed together. So i made a header file referencing just the needed function and surrounded it with #pragma unmanaged and am compiling with /clr option.

    Here is the header file:
    Code:
    #sound.h
    #include "windows.h"
    #include "mmsystem.h"
    #pragma unmanaged
    WINMMAPI  UINT WINAPI waveInGetNumDevs(void);
    Here is the code generating the error:
    Code:
    #include "sound.h"
    #pragma managed
    namespace record {
    
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    
    	public ref class Form1 : public System::Windows::Forms::Form
    	{
    		HWAVEIN hwin;
    		MMRESULT result;
    		int numDevices;
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
    			numDevices = waveInGetNumDevs();
    		}
    Any help on this matter would be appreciated. Thanks a lot.

    --koooee

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    mmsystem.h is a header and you don't link with headers, you link with libraries. There is probably a library you need to explicitly link with (winmm.lib if I'm not mistaken) in your project settings.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    8
    i feel stupid....(that was in my console version of the code) thanks for the reply.

    if anyone is wondering...put this line in stdafx.h

    Code:
    #pragma comment(lib, "winmm.lib")

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  4. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 08:13 PM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM