在尝试使用带有CALLBACK功能的midiInOpen时,为什么会出现访问冲突? [英] Why am I getting an access violation when trying to use midiInOpen with CALLBACK function?

查看:169
本文介绍了在尝试使用带有CALLBACK功能的midiInOpen时,为什么会出现访问冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试使用时不断收到访问权限: 



无符号长结果;

HMIDIIN      inHandle;

result = midiInOpen(& inHandle,1,(DWORD)midiCallback,0,CALLBACK_FUNCTION);



I尝试了一切。除了我,它似乎对每个人都有用。为什么在指定CALLBACK时会出现访问冲突?如果我只使用MidiInOpen(inHandle,0,0,0,0)它会运行 但没有办法处理事件..



更新: 

访问冲突似乎只发生在我编译下64。在x86和Win32下编译它似乎解决了这个问题。有谁知道这是为什么?

 #include" stdafx.h" 
#include< iostream>
#include< cstdlib>
#include< windows.h>
#include< Mmsystem.h>
#include< stdio.h>
using namespace std;

void CALLBACK midiCallback(HMIDIIN句柄,UINT uMsg,DWORD dwInstance,DWORD dwParam1,DWORD dwParam2)
{
switch(uMsg)
{
case MIM_OPEN:
cout<< " ----- ----- OPENED" << ENDL;
休息;
case MIM_CLOSE:
cout<< "-----一切都在关闭.-----" << ENDL;
休息;
case MIM_DATA:
cout<< "-----显然是我的数据.-----" << ENDL;
休息;
case MIM_LONGDATA:
cout<< " ----- ----- LONGDATA'D" << ENDL;
休息;
case MIM_ERROR:
cout<< " ----- ----- ERROR" << ENDL;
休息;
case MIM_LONGERROR:
cout<< " ----- LONGERROR。 EVEN WORSE .-----" << ENDL;
休息;
}
cout<< "dwInstance is" << dwInstance<< ENDL;
cout<< "Handle is" <<句柄<< ENDL;
cout<< "dwParam1是" << dwParam1<< ENDL; // dwParam1是打包到unsigned long
cout<<<<<<<< "dwParam1_hiword是" << HIWORD(dwParam1)<< ENDL; // velocity
cout<< "dwParam1_loword是" << LOWORD(dwParam1)<< ENDL; // keyID
cout<< "dwParam2是" << dwParam2<< ENDL; // dwParam2是按键的时间戳
cout<< "uMsg是" << uMsg<< ENDL;
cout<< " -----" << ENDL;
}


无效MidiThing(){
MIDIINCAPS麦克风;

未签名的长期结果;
HMIDIIN inHandle;

unsigned long iNumDevs,i;
iNumDevs = midiInGetNumDevs(); / *获取此计算机中MIDI输入设备的数量* /

/ *浏览所有这些设备,显示其名称* /
for(i = 0; i< iNumDevs ; i ++)
{
/ *获取有关下一个设备的信息* /
if(!midiInGetDevCaps(i,& mic,sizeof(MIDIINCAPS)))
{
/ *显示其设备ID和名称* /
wcout<< "设备ID ["] << i<< "]:" << mic.szPname<< ENDL;
}
}
cout<< ENDL;




//打开默认的MIDI输入设备。 (DevID 0)
result = midiInOpen(& inHandle,1,(DWORD)midiCallback,0,CALLBACK_FUNCTION);
// result = midiInOpen(& inHandle,0,0,0,0);


if(result!= MMSYSERR_NOERROR){
cout<< "midiInOpen()失败... rv =" <<结果<< ENDL;
}
其他
{
midiInStart(inHandle);

}

cout<< ENDL;
cout<< "按\"ESC \"退出。" << ENDL;
while(1){
if(GetAsyncKeyState(VK_ESCAPE))
{
break;
cout<< "出口=真QUOT。 << ENDL;
}
睡眠(100);
}

midiInStop(inHandle);
midiInReset(inHandle);
midiInClose(inHandle);

cout<< ENDL;
cout<< inHandle<< "是MIDIIN句柄。" << ENDL;
cout<< ENDL;
cout<< "MIDI现在关闭。" << ENDL;
}

int main(int argc,char * argv [])
{
MidiThing();
cout<< "退出是成功的"。 << ENDL;
返回EXIT_SUCCESS;
}




Eric M Lieber

解决方案


 //打开默认的MIDI输入设备。 (DevID 0)
result = midiInOpen(& inHandle,1,(DWORD)midiCallback,0,CALLBACK_FUNCTION);


您好,


在您的评论中写入DeviceId 0,但是你给了函数中的Id 1.


试试这个:

 UINT deviceId = 0; 
result = midiInOpen(& inHandle,deviceId,(DWORD_PTR)(void *)midiCallback,0,CALLBACK_FUNCTION);

查看文档:< a href ="https://msdn.microsoft.com/de-de/library/windows/desktop/dd798458(v=vs.85).aspx">
https://msdn.microsoft.com/ de-de / library / windows / desktop / dd798458(v = vs.85).aspx


HTH,Guido



I keep getting an access violation when trying to use: 

unsigned long result;
HMIDIIN      inHandle;

result = midiInOpen(&inHandle, 1, (DWORD)midiCallback, 0, CALLBACK_FUNCTION);

I have tried everything. It seems to work for everyone but me. Why would I get an access violation when specifying a CALLBACK? If I use just MidiInOpen(inHandle,0,0,0,0) it runs  but there is no way to process events..

Update: 
The access violation seem to only occur when I compile it under x64. Having compiled it under x86 and Win32 seems to resolve this problem. Does anyone know why this is?

#include"stdafx.h"
#include<iostream>
#include<cstdlib>
#include<windows.h>
#include<Mmsystem.h>
#include<stdio.h>
using namespace std;

void CALLBACK midiCallback(HMIDIIN handle, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
{
	switch (uMsg)
	{
	case MIM_OPEN:
		cout << "-----OPENED.-----" << endl;
		break;
	case MIM_CLOSE:
		cout << "-----EVERYTHING IS CLOSING.-----" << endl;
		break;
	case MIM_DATA:
		cout << "-----APPARENTLY THERE I5 DATA.-----" << endl;
		break;
	case MIM_LONGDATA:
		cout << "-----LONGDATA'D.-----" << endl;
		break;
	case MIM_ERROR:
		cout << "-----ERROR.-----" << endl;
		break;
	case MIM_LONGERROR:
		cout << "-----LONGERROR.  EVEN WORSE.-----" << endl;
		break;
	}
	cout << "dwInstance is " << dwInstance << endl;
	cout << "Handle is " << handle << endl;
	cout << "dwParam1 is " << dwParam1 << endl; //dwParam1 is the bytes of the MIDI Message packed into an unsigned long
	cout << "dwParam1_hiword is " << HIWORD(dwParam1) << endl; //velocity
	cout << "dwParam1_loword is " << LOWORD(dwParam1) << endl; //keyID
	cout << "dwParam2 is " << dwParam2 << endl; //dwParam2 is the timestamp of key press
	cout << "uMsg is " << uMsg << endl;
	cout << "-----" << endl;
}


void MidiThing() {
	MIDIINCAPS     mic;

	unsigned long result;
	HMIDIIN      inHandle;

	unsigned long    iNumDevs, i;
	iNumDevs = midiInGetNumDevs();  /* Get the number of MIDI In devices in this computer */

									/* Go through all of those devices, displaying their names */
	for (i = 0; i < iNumDevs; i++)
	{
		/* Get info about the next device */
		if (!midiInGetDevCaps(i, &mic, sizeof(MIDIINCAPS)))
		{
			/* Display its Device ID and name */
			wcout << "Device ID [" << i << "]: " << mic.szPname << endl;
		}
	}
	cout << endl;




	// Open the default MIDI In device. (DevID 0)
	result = midiInOpen(&inHandle, 1, (DWORD)midiCallback, 0, CALLBACK_FUNCTION);
//	result = midiInOpen(&inHandle, 0, 0, 0, 0);


	if (result != MMSYSERR_NOERROR) {
		cout << "midiInOpen() failed...rv= " << result << endl;
	}
	else
	{
		midiInStart(inHandle);

	}

	cout << endl;
	cout << "Press \"ESC\" to quit." << endl;
	while (1) {
		if (GetAsyncKeyState(VK_ESCAPE))
		{
			break;
			cout << "exit=true." << endl;
		}
		Sleep(100);
	}

	midiInStop(inHandle);
	midiInReset(inHandle);
	midiInClose(inHandle);

	cout << endl;
	cout << inHandle << " was the MIDIIN handle." << endl;
	cout << endl;
	cout << "MIDI is closed now." << endl;
}

int main(int argc, char *argv[])
{
	MidiThing();
	cout << "Exit is success." << endl;
	return EXIT_SUCCESS;
}


Eric M Lieber

解决方案

	// Open the default MIDI In device. (DevID 0)
	result = midiInOpen(&inHandle, 1, (DWORD)midiCallback, 0, CALLBACK_FUNCTION);

Hello,

in your comment you write DeviceId 0, but you give Id 1 in the function.

Try this:

UINT deviceId = 0;
result = midiInOpen(&inHandle, deviceId, (DWORD_PTR)(void*)midiCallback, 0, CALLBACK_FUNCTION);

Have a look at the documentation: https://msdn.microsoft.com/de-de/library/windows/desktop/dd798458(v=vs.85).aspx

HTH, Guido


这篇关于在尝试使用带有CALLBACK功能的midiInOpen时,为什么会出现访问冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆