ThreadInit.cpp 1.65 KB
Newer Older
Jonas Stienen's avatar
Jonas Stienen committed
1
#include <ITAAsioInterface.h>
2

Jonas Stienen's avatar
Jonas Stienen committed
3
4
5
6
#include <process.h>
#include <stdio.h>
#include <string>

7
#ifndef  _WIN32_WINNT // @todo: remove
8
#define _WIN32_WINNT 0x0501
9
10
#endif

Jonas Stienen's avatar
Jonas Stienen committed
11
12
#include <windows.h>

Jonas Stienen's avatar
Jonas Stienen committed
13

14
15
int test( const char* pszDriverName )
{
Jonas Stienen's avatar
Jonas Stienen committed
16
17
18
19
	ITAsioInitializeLibrary();

	// Treiber anzeigen
	long lDrivers = ITAsioGetNumDrivers();
20
21
22
23
24
25
	if( lDrivers > 0 )
	{
		printf( "Folgende ASIO-Treiber wurden gefunden:\n\n" );
		for( long i = 0; i < lDrivers; i++ )
		{
			printf( "\t[%d]\t%s\n", i + 1, ITAsioGetDriverName( i ) );
Jonas Stienen's avatar
Jonas Stienen committed
26
		}
27
28
29
30
	}
	else
	{
		printf( "Keine ASIO-Treiber gefunden!\n" );
Jonas Stienen's avatar
Jonas Stienen committed
31
		return 0;
32
	}
Jonas Stienen's avatar
Jonas Stienen committed
33
34

	// Treiber initialisieren
35
	printf( "Initialisiere Treiber \"%s\"\n", pszDriverName );
Jonas Stienen's avatar
Jonas Stienen committed
36
	ASIOError ae = ITAsioInitializeDriver( pszDriverName );
37
38
39
	if( ae == ASE_OK )
	{
		printf( "Initialisierung erfolgreich!" );
Jonas Stienen's avatar
Jonas Stienen committed
40
		ITAsioFinalizeDriver();
41
42
43
44
	}
	else
	{
		printf( "Initialisierung fehlgeschlagen (errorcode %d: %s)\n", ae, ITAsioGetErrorStr( ae ) );
Jonas Stienen's avatar
Jonas Stienen committed
45

Jonas Stienen's avatar
Jonas Stienen committed
46
47
48
49
50
51
52
53
		return -1;
	}

	ITAsioFinalizeLibrary();

	return 0;
}

54
55
56
void ThreadProc( void* pParam )
{
	printf( "Thread ist gestartet!\n" );
Jonas Stienen's avatar
Jonas Stienen committed
57
58
59
60

	// COM initialisieren (Appartment)
	//CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

61
62
	if( test( ( const char* ) pParam ) != 0 )
	{
Jonas Stienen's avatar
Jonas Stienen committed
63
64
65
66
67
68
		//CoUninitialize();
	}

	_endthread();
}

69
70
int main( int argc, char* argv[] )
{
Jonas Stienen's avatar
Jonas Stienen committed
71
72
73
74

	// COM initialisieren (Appartment)
	//CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

75
76
77
	if( argc != 2 )
	{
		fprintf( stderr, "Syntax: ThreadInit TREIBERNUMMER\n" );
Jonas Stienen's avatar
Jonas Stienen committed
78
79
80
81
82
		return 255;
	}

	bool bThreaded = true;

Jonas Stienen's avatar
Jonas Stienen committed
83
84
	if( bThreaded )
	{
85
86
87
88
89
90
91
		HANDLE hThread = ( HANDLE ) _beginthread( ThreadProc, 0, argv[ 1 ] );
		WaitForSingleObject( hThread, INFINITE );
	}
	else
	{
		test( argv[ 1 ] );
	}
Jonas Stienen's avatar
Jonas Stienen committed
92
93
94
95
96

	//CoUninitialize();

	return 0;
}