Salve,

ho scritto una piccola classe per gestire le funzioni waveIn della waveForm API di windows. La classe è composta da questi due files:

waveCapture.h
waveCapture.cpp

mentre la classe funziona benissimo all'interno di main() ho un problema ad usarla dentro ad un thread (l'inizializzazione va a buon termine ma chiamando il metodo principale mi torna un unhanlde exception: Access violation writing location)

ecco il codice del programma thread:

codice:
#include <stdio.h>
#include <stdlib.h>
#include "waveCapture.h"

DWORD WINAPI startRecorder(const LPVOID lpParam);
DWORD WINAPI stopRecorder(void);

bool stopThreadFlag = false;

struct parametri
{
	WORD uDevice;
	DWORD nSamplesPerSec;
	WORD wBitsPerSample;
	WORD nChannels;
	const char* szFilePath;
};

int main()
{
	parametri *p      = new (parametri);
	p->uDevice        = 0;
	p->nSamplesPerSec = 44100;
	p->wBitsPerSample = 16;
	p->nChannels      = WAVE_STEREO;
	p->szFilePath     = "C:\\Users\\giangaetano\\Desktop\\mmio\\waveCapture.WAVE";

	HANDLE hthread[2];
	DWORD dwID[2];

	// Launch Capturing Thread: thread[0]
	hthread[0] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)&startRecorder,p,0,&dwID[0]);

	printf("Started capturing...(press any key to stop)\n\n");
	system("pause");

	// Once any key is pressed, stop thread[0] by launching thread[1]
	hthread[1] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)&stopRecorder,NULL,0,&dwID[1]);
	CloseHandle(hthread[1]);
	CloseHandle(hthread[0]);

	printf("\nStopped capturing!\n\n");

	system("pause");
	delete p;
	return EXIT_SUCCESS;
}

DWORD WINAPI startRecorder(const LPVOID lpParam)
{
	// Get the params
	parametri p;
	p = *((parametri*)lpParam);

	// Init waveCapture class
	waveCapture pwc;
	printf("%s, %d, %d, %d\n",
		waveCapture::szVersion,
		pwc.__dwSamplePerSec(),
		pwc.__wBitsPerSample(),
		pwc.__nChannels()
		);

	// Start capturing
	pwc.start();

	// Stop capturing:
	pwc.stop();

	return 0;
}

DWORD WINAPI stopRecorder(void)
{
	stopThreadFlag = true;
	return 0;
}
C'è qualche accorgimento speciale che devo seguire se sviluppo una classe che potrebbe essere usata da dentro un thread?

grazie