Создание DLL библиотеки
17.06.2015, 23:44. Показов 382. Ответов 0
есть код для рисования призмы:
C++ | 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
| #include <glut.h>
#include <math.h>
#include <iostream>
#include <conio.h>
#include <Windows.h>
#include <gl\GL.h>
#include <gl\GLU.h>
using namespace std;
#define PI 3.14159265359
#define n 11
typedef void (*fptrInt2)(int, int);
typedef void (*fptrInt3)(int,int, int);
typedef void (*fptrNull)();
int ox=0,oy=0,oz=100;
float radius = 50.0;
class Prizma
{
public:
static void display()
{
float segment = 2*PI / n;
struct point
{
float x,y,z;
} a[n+1],b[n+1];
for(int i=0;i<=n;i++){
float x = radius * sin(i*segment);
float y = radius * cos(i*segment);
a[i].x=x;
a[i].y=y;
a[i].z=oz;
b[i].x=x;
b[i].y=y;
b[i].z=-oz;};
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(90,1,0,0);
glEnable(GL_DEPTH_TEST);
glBegin(GL_QUADS);
for (int i=0;i<n;i++)
{
glColor3f(sinf(i),sinf(i+5),sinf(i+2));
glVertex3f(a[i].x,a[i].y,a[i].z);
glVertex3f(a[i+1].x,a[i+1].y,a[i+1].z);
glVertex3f(b[i+1].x,b[i+1].y,b[i+1].z);
glVertex3f(b[i].x,b[i].y,b[i].z);
};
glVertex3f(a[0].x,a[0].y,a[0].z);
glVertex3f(a[n-1].x,a[n-1].y,a[n-1].z);
glVertex3f(b[n-1].x,b[n-1].y,b[n-1].z);
glVertex3f(b[0].x,b[0].y,b[0].z);
glEnd();
glBegin(GL_LINE_STRIP);
for(int i=0;i<=n;i++)
{
glColor3f(0,0,0);
glVertex3f(a[i].x,a[i].y,a[i].z);
};
glEnd();
glBegin(GL_LINE_STRIP);
for(int i=0;i<=n;i++)
{
glColor3f(0,0,0);
glVertex3f(b[i].x,b[i].y,b[i].z);
}
glEnd();
glBegin(GL_LINE_STRIP);
for (int i=0;i<=n;i++)
{
glColor3f(0,0,0);
glVertex3f(a[i].x,a[i].y,a[i].z);
glVertex3f(b[i].x,b[i].y,b[i].z);
glVertex3f(a[i].x,a[i].y,a[i].z);
}
glEnd();
glPopMatrix();
glutSwapBuffers();
}
static void MousePresedMove(int x, int y)
{
if((x>=0&&x<=400)&&(y>=0&&y<=400))
{
glutPostRedisplay();
glRotatef (x-ox,0,1,0);
glRotatef (y-oy,-1,0,0);
ox=x; oy=y;
}
}
static void SKeyboard(int key, int x, int y)
{
switch(key)
{
case GLUT_KEY_UP: { if (oz!=250) {radius++; oz=oz+2;
glutPostRedisplay();}}
break;
case GLUT_KEY_DOWN: { if (oz!=0) {radius--; oz=oz-2;
glutPostRedisplay();}}
break;
}
}
void (*pMouse)(int, int);
void Initialize()
{
glClearColor(0.0, 0.0, 0.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-200,200,200,-200,-500,500);
glMatrixMode(GL_MODELVIEW);
// pMouse = MousePresedMove;
}
};
int main(int argc, char** argv)
{
Prizma p;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(400, 400);
glutInitWindowPosition(483,184 );
glutCreateWindow("Prizma");
p.Initialize();
glutMotionFunc((fptrInt2) &Prizma::MousePresedMove);
//glutMotionFunc(&p.MousePresedMove);
glutSpecialFunc((fptrInt3) &Prizma::SKeyboard);
glutDisplayFunc((fptrNull) &Prizma::display);
glutMainLoop();
return 0;
} |
|
Как запихать класс Prizma в библиотеку Dll и как к ней обращаться?
Сделал DLL:
C++ | 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
104
105
106
107
108
109
110
111
112
113
114
| // workdll.cpp: определяет экспортированные функции для приложения DLL.
//
#include "stdafx.h"
#include <glut.h>
#include <math.h>
#include <iostream>
#include <gl\GL.h>
#include <gl\GLU.h>
using namespace std;
#define PI 3.14159265359
#define n 11
typedef void (*fptrInt2)(int, int);
typedef void (*fptrInt3)(int,int, int);
typedef void (*fptrNull)();
int ox=0,oy=0,oz=100;
float radius = 50.0;
class Prizma
{
public:
static __declspec(dllexport) void display()
{
float segment = 2*PI / n;
struct point
{
float x,y,z;
} a[n+1],b[n+1];
for(int i=0;i<=n;i++){
float x = radius * sin(i*segment);
float y = radius * cos(i*segment);
a[i].x=x;
a[i].y=y;
a[i].z=oz;
b[i].x=x;
b[i].y=y;
b[i].z=-oz;};
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(90,1,0,0);
glEnable(GL_DEPTH_TEST);
glBegin(GL_QUADS);
for (int i=0;i<n;i++)
{
glColor3f(sinf(i),sinf(i+5),sinf(i+2));
glVertex3f(a[i].x,a[i].y,a[i].z);
glVertex3f(a[i+1].x,a[i+1].y,a[i+1].z);
glVertex3f(b[i+1].x,b[i+1].y,b[i+1].z);
glVertex3f(b[i].x,b[i].y,b[i].z);
};
glVertex3f(a[0].x,a[0].y,a[0].z);
glVertex3f(a[n-1].x,a[n-1].y,a[n-1].z);
glVertex3f(b[n-1].x,b[n-1].y,b[n-1].z);
glVertex3f(b[0].x,b[0].y,b[0].z);
glEnd();
glBegin(GL_LINE_STRIP);
for(int i=0;i<=n;i++)
{
glColor3f(0,0,0);
glVertex3f(a[i].x,a[i].y,a[i].z);
};
glEnd();
glBegin(GL_LINE_STRIP);
for(int i=0;i<=n;i++)
{
glColor3f(0,0,0);
glVertex3f(b[i].x,b[i].y,b[i].z);
}
glEnd();
glBegin(GL_LINE_STRIP);
for (int i=0;i<=n;i++)
{
glColor3f(0,0,0);
glVertex3f(a[i].x,a[i].y,a[i].z);
glVertex3f(b[i].x,b[i].y,b[i].z);
glVertex3f(a[i].x,a[i].y,a[i].z);
}
glEnd();
glPopMatrix();
glutSwapBuffers();
}
static __declspec(dllexport) void MousePresedMove(int x, int y)
{
if((x>=0&&x<=400)&&(y>=0&&y<=400))
{
glutPostRedisplay();
glRotatef (x-ox,0,1,0);
glRotatef (y-oy,-1,0,0);
ox=x; oy=y;
}
}
static __declspec(dllexport) void SKeyboard(int key, int x, int y)
{
switch(key)
{
case GLUT_KEY_UP: { if (oz!=250) {radius++; oz=oz+2;
glutPostRedisplay();}}
break;
case GLUT_KEY_DOWN: { if (oz!=0) {radius--; oz=oz-2;
glutPostRedisplay();}}
break;
}
}
void (*pMouse)(int, int);
void __declspec(dllexport) Initialize()
{
glClearColor(0.0, 0.0, 0.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-200,200,200,-200,-500,500);
glMatrixMode(GL_MODELVIEW);
// pMouse = MousePresedMove;
}
}; |
|
Правильно ли только?
И если правильно как обратиться к нему из программы?
Добавлено через 53 минуты
Вот что сделал с DLL:
C++ | 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
104
105
106
107
108
109
110
111
| // workdll.cpp: определяет экспортированные функции для приложения DLL.
//
#include "stdafx.h"
#include <glut.h>
#include <math.h>
#include <iostream>
#include <gl\GL.h>
#include <gl\GLU.h>
using namespace std;
#define PI 3.14159265359
#define n 11
typedef void (*fptrInt2)(int, int);
typedef void (*fptrInt3)(int,int, int);
typedef void (*fptrNull)();
int ox=0,oy=0,oz=100;
float radius = 50.0;
extern "C" __declspec(dllexport) void display()
{
float segment = 2*PI / n;
struct point
{
float x,y,z;
} a[n+1],b[n+1];
for(int i=0;i<=n;i++){
float x = radius * sin(i*segment);
float y = radius * cos(i*segment);
a[i].x=x;
a[i].y=y;
a[i].z=oz;
b[i].x=x;
b[i].y=y;
b[i].z=-oz;};
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(90,1,0,0);
glEnable(GL_DEPTH_TEST);
glBegin(GL_QUADS);
for (int i=0;i<n;i++)
{
glColor3f(sinf(i),sinf(i+5),sinf(i+2));
glVertex3f(a[i].x,a[i].y,a[i].z);
glVertex3f(a[i+1].x,a[i+1].y,a[i+1].z);
glVertex3f(b[i+1].x,b[i+1].y,b[i+1].z);
glVertex3f(b[i].x,b[i].y,b[i].z);
};
glVertex3f(a[0].x,a[0].y,a[0].z);
glVertex3f(a[n-1].x,a[n-1].y,a[n-1].z);
glVertex3f(b[n-1].x,b[n-1].y,b[n-1].z);
glVertex3f(b[0].x,b[0].y,b[0].z);
glEnd();
glBegin(GL_LINE_STRIP);
for(int i=0;i<=n;i++)
{
glColor3f(0,0,0);
glVertex3f(a[i].x,a[i].y,a[i].z);
};
glEnd();
glBegin(GL_LINE_STRIP);
for(int i=0;i<=n;i++)
{
glColor3f(0,0,0);
glVertex3f(b[i].x,b[i].y,b[i].z);
}
glEnd();
glBegin(GL_LINE_STRIP);
for (int i=0;i<=n;i++)
{
glColor3f(0,0,0);
glVertex3f(a[i].x,a[i].y,a[i].z);
glVertex3f(b[i].x,b[i].y,b[i].z);
glVertex3f(a[i].x,a[i].y,a[i].z);
}
glEnd();
glPopMatrix();
glutSwapBuffers();
}
extern "C" __declspec(dllexport) void MousePresedMove(int x, int y)
{
if((x>=0&&x<=400)&&(y>=0&&y<=400))
{
glutPostRedisplay();
glRotatef (x-ox,0,1,0);
glRotatef (y-oy,-1,0,0);
ox=x; oy=y;
}
}
extern "C" __declspec(dllexport) void SKeyboard(int key, int x, int y)
{
switch(key)
{
case GLUT_KEY_UP: { if (oz!=250) {radius++; oz=oz+2;
glutPostRedisplay();}}
break;
case GLUT_KEY_DOWN: { if (oz!=0) {radius--; oz=oz-2;
glutPostRedisplay();}}
break;
}
}
void (*pMouse)(int, int);
extern "C" void __declspec(dllexport) Initialize()
{
glClearColor(0.0, 0.0, 0.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-200,200,200,-200,-500,500);
glMatrixMode(GL_MODELVIEW);
// pMouse = MousePresedMove;
} |
|
С программой:
C++ | 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
| #include <glut.h>
#include <math.h>
#include <iostream>
#include <conio.h>
#include <Windows.h>
#include <gl\GL.h>
#include <gl\GLU.h>
using namespace std;
#define PI 3.14159265359
#define n 11
typedef void (*fptrInt2)(int, int);
typedef void (*fptrInt3)(int,int, int);
typedef void (*fptrNull)();
int ox=0,oy=0,oz=100;
float radius = 50.0;
int main(int argc, char** argv)
{
typedef void(*funkclass) ();
HMODULE hlib=LoadLibrary(TEXT("worldll.dll"));
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(400, 400);
glutInitWindowPosition(483,184 );
glutCreateWindow("Prizma");
funkclass Initialize; (funkclass)GetProcAddress(hlib, "Initialize");
glutMotionFunc((fptrInt2) (funkclass)GetProcAddress(hlib, "MousePresedMove"));
//glutMotionFunc(&p.MousePresedMove);
glutSpecialFunc((fptrInt3) (funkclass)GetProcAddress(hlib, "SKeyboard"));
glutDisplayFunc((fptrNull) (funkclass)GetProcAddress(hlib, "display"));
FreeLibrary(hlib);
glutMainLoop();
return 0;
} |
|
DLL создаётся, программа компилируется но результата нету, почему?
0
|