Best way to combine few c++ sources

So, I have written source that extracts binary data from wav file. And I have written another source that displays that data in window. What is the best way to use them both. Do I just copy one into another and compile only one? Or is there another way?
Regardless of what approach you take, you'll have to rewrite one of them since you can only have one instance of Main so let's call that step one. Next will be deciding the format of the data so that the two pieces of code can communicate with each other; that we can't really help with since we can't see your code. But if you're confident that you can do it by yourself then call that step two. After that, the method that you use to put them together is pretty arbitrary. You could copy and paste one to the other, dump one into a header file and just include it (which is essentially the same thing), or link one to the other. Copy and pasting should be sufficient, but if you are looking to learn something then I encourage that you link the two together.
I managed to connect them with header files but now only one source is executing. Here are files
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <stdlib.h>
#include <string.h>
#include<windows.h>
#include "exdata.h"


using namespace std;
#define WIN32_LEAN_AND_MEAN

LRESULT CALLBACK WndProc(HWND hwndMain, UINT uMsg, WPARAM wParam, LPARAM lParam);


INT APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
	LPSTR lpCmdLine, int nShowCmd)
{
	WNDCLASSEX windowClass;
	windowClass.lpszClassName = "Main Class";
	windowClass.cbClsExtra = NULL;
	windowClass.cbWndExtra = NULL;
	windowClass.cbSize = sizeof(WNDCLASSEX);
	windowClass.hbrBackground = (HBRUSH)CreateSolidBrush(RGB(247, 247, 247));
	windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
	windowClass.hIcon = LoadIcon(NULL, MAKEINTRESOURCE(IDI_APPLICATION));
	windowClass.hIconSm = (HICON)LoadImage(NULL, MAKEINTRESOURCE(IDI_APPLICATION), IMAGE_ICON, 16, 16, NULL);
	windowClass.hInstance = hInstance;
	windowClass.lpfnWndProc = WndProc;
	windowClass.lpszMenuName = NULL;
	windowClass.style = CS_VREDRAW | CS_HREDRAW;
	RegisterClassEx(&windowClass);

	HWND Main = CreateWindowEx(NULL, "Main Class", "Basic Window",
		WS_OVERLAPPEDWINDOW | WS_VISIBLE,
		100, 100, 500, 500,
		NULL, NULL, hInstance, NULL);


	if (!Main)
		return(0);


	MSG msg;
	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return msg.wParam;
}

int aa1 = 0;

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_CREATE:
	{
		//creation coding
	}
	break;
	TCHAR aa[2];
	
	TCHAR ab[2];
	
	TCHAR ac[2];
	/*
	TCHAR ad[2];
	TCHAR ae[2];
	TCHAR af[2];
	
	*/
	case WM_PAINT:
	{
		
		char buffer[65];
		PAINTSTRUCT Ps;
		HDC hdc;
		hdc = BeginPaint(hwnd, &Ps);
		SetBkColor(hdc, RGB(255, 255, 255));
		SetTextColor(hdc, RGB(0, 0, 0));
		TextOut(hdc, 10, 10, aa, wsprintf(aa, "%d", camp));
		TextOut(hdc, 20, 10, ab, wsprintf(ab, "%d", aa1));
		TextOut(hdc, 30, 10, ac, wsprintf(ac, "%d", aa1));
		//TextOut(hdc, 40, 10, ad, wsprintf(ad, "%d", "3"));
		//TextOut(hdc, 50, 10, ae, wsprintf(ae, "%d", "4"));
		//TextOut(hdc, 60, 10, af, wsprintf(af, "%d", "5"));
		EndPaint(hwnd, &Ps);
	}
	break;
	case WM_CLOSE:
	{
		PostQuitMessage(WM_QUIT);
	}
	break;
	default:
		return(DefWindowProc(hwnd, message, wParam, lParam));
	}



	return(0);
}


exdata.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <stdio.h>
#include <iostream>
#include <math.h> 
#include "exdata.h"
using namespace std;

// An unsigned char can store 1 Bytes (8bits) of data (0-255)
typedef char16_t BYTE;

// Get the size of a file
long getFileSize(FILE *file)
{
	long lCurPos, lEndPos;
	lCurPos = ftell(file);
	fseek(file, 0, 2);
	lEndPos = ftell(file);
	fseek(file, lCurPos, 0);
	return lEndPos;
}
float camp;
int main()
{
	const char *filePath = "t2.wav";
	BYTE *fileBuf;			// Pointer to our buffered data
	//BYTE *amp;
	FILE *file = NULL;		// File pointer
	FILE *data;
	FILE *bin;
	
	if ((file = fopen(filePath, "rb")) == NULL)
		cout << "Could not open specified file" << endl;
	else
		cout << "File opened successfully" << endl;
		
	long fileSize = getFileSize(file);

	fileBuf = new BYTE[fileSize];
	//amp = new BYTE[fileSize];

	fread(fileBuf, fileSize, 1, file);
	data = fopen("data.txt", "w");
	bin = fopen("bin.txt", "w");
	//float camp;
	//amplitude amp1;
	int sum = 0;
	int enbl = 0;
	for (int i = 5000; i <80000; i+=2){
		

		//int amp = fileBuf[i];
		int amp =fileBuf[i];
		
		if (amp > 32768){
			camp = amp - 32768;
		}
		if (amp <= 32767){
			camp = amp + 32768;
		}
		//printf("%f ",camp);
		fprintf(data,"%f\n", camp);
		if (camp > 40000){
			enbl = 1;
		}
		if (camp < 40000){
			enbl = 0;
			
			
		}
		if (enbl == 1){
			sum += 1;
		}
		
		if (sum > 30&&enbl==0){
			fprintf(bin, "1\n");
			
			sum = 0;
		}
		if (sum < 20 &&sum>5&&enbl==0){
			fprintf(bin, "0\n");
			sum = 0;

		}
		
		//fprintf(bin, "%d\n",sum);
		//printf("%d\n", sum);
	}
	cin.get();
	delete[]fileBuf;
	fclose(data);
	fclose(file);   // Almost forgot this 




	cout << "Done" << endl;
	return 0;


}


exdata.h
extern float camp;

Only my exdata.cpp is executing. I don't see window that should appear from main.cpp. anybody know what is going on? exdata.cpp should execute silently and give me data to show on window in main.cpp.
Last edited on
I managed to do it, all in one file. I also managed to do it with header file but for now I find it easier to put it all in same file.
Last edited on
Topic archived. No new replies allowed.