Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 05-18-2004, 09:19 AM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,486
sde is on a distinguished road
win api programming

i know how to import a windows dll in c#, but i haven't done much c++ programming.

i want to use winmm to access midi function.

in c#, i would do this:
Code:
[DllImport("winmm.dll")] 
public static extern int midiOutOpen(ref int lphMidiOut, int uDeviceID, int dwCallback, int dwInstance, int dwFlags)
what is the equivalent in c++?
__________________
Mike
sde is offline   Reply With Quote
Old 05-18-2004, 11:13 AM   #2 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
two ways. you can link implicitly, by adding it to the linker parameters of your project. this is the easiest way (and generally what is done with all library dlls). or you can link explicitly by calling LoadLibrary(), linking your functions manually using GetProcAddress(), and releasing the dll with FreeLibrary().

in unix, you would use dlopen() for explicit linking.
joe_bruin is offline   Reply With Quote
Old 05-18-2004, 01:06 PM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,486
sde is on a distinguished road
thanks joe.

#include <MMSystem.h>

that did it. now i just got to find out why i get all these 'undefined identifier' compiler errors when i include this library width c++.
__________________
Mike
sde is offline   Reply With Quote
Old 05-20-2004, 10:41 PM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,486
sde is on a distinguished road
windows programming .. ugggh .. i'm not even sure if i'm approaching this right.

so far, i have been able to import mmsystem, and load the winmm dll, but i'm not sure how to call this: http://msdn.microsoft.com/library/de...getnumdevs.asp

it is supposed to return the number of midi inputs you have.

how would you call that function? here is what i have so far to load the library:
Code:
#include "stdafx.h"
#include "windows.h"
#include "mmsystem.h"

int _tmain(int argc, _TCHAR* argv[])
{
	HINSTANCE hLib=LoadLibrary("winmm.dll");

	if(hLib == NULL)
	{
		std::cout << "hLib is NULL";
		getchar();
		return 0;
	}

	unsigned long   iNumDevs, i;

	// here i want to call midiInGetNumDevs()
	// and assign it to iNumDevs


  FreeLibrary((HMODULE)hLib);
  getchar();
	
	return 0;
}
does it even look like i'm on the right track?
__________________
Mike
sde is offline   Reply With Quote
Old 05-20-2004, 11:03 PM   #5 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
there's no real point to doing this. just add winmm.dll to your linker parameters (should be somewhere in your project settings), and you will not have to jump any hoops to call your function.

if you want to use explicit loading, you should not include mmsystem.h. the functions prototypes in it would be useless, since the linker can't link against the library (in explicit loading, you are the linker).
joe_bruin is offline   Reply With Quote
Old 05-20-2004, 11:18 PM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,486
sde is on a distinguished road
YES! Thanks again Joe! =)

Code:
#include "stdafx.h"
#include "windows.h"

int _tmain(int argc, _TCHAR* argv[])
{
	unsigned long   iNumDevs,oNumDevs;

	iNumDevs = midiInGetNumDevs();
	oNumDevs = midiOutGetNumDevs();

	std::cout << "You Have " << iNumDevs << " MIDI Input Device(s)\n";
	std::cout << "and " << oNumDevs << " MIDI Output Device(s).";

  getchar();	
	return 0;
}
Output:
Quote:
You Have 2 MIDI Input Device(s)
and 7 MIDI Output Device(s).
__________________
Mike
sde is offline   Reply With Quote
Old 06-11-2006, 10:15 AM   #7 (permalink)
Redline
PHP Student
 
Join Date: Oct 2004
Location: Forest Grove, OR
Posts: 150
Redline is on a distinguished road
Send a message via AIM to Redline Send a message via MSN to Redline
Out of curiosity Mike, which compiler were you using for this? I'm starting to read up on C, and have had issues including various windows.h's in my compiler of choice, Borland turbo. I have a trial version of visual c++, but that seems to just be complicating things for me
__________________
Current Project
Redline is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparison of Different Programming Languages Punch-M6.net All Other Coding Languages 23 04-19-2007 01:34 PM
About the API forum. Valmont Platform/API C++ 0 09-26-2004 06:08 AM
Windows Programming Help Amaranthine Standard C, C++ 4 05-14-2004 12:48 PM
Why SCO Thinks It Can Win redhead Code Newbie News 0 04-05-2004 04:51 AM
CLI for noobies: shell programming sde Code Newbie News 0 03-15-2004 12:33 PM


All times are GMT -8. The time now is 09:18 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting