the first function is called from dll_1, this function calls the second function from dll_2, the second function calls the third function from dll_1, the third function calls the fourth function from dll_2, the fourth function displays an inscription. how to do it? here are my attempts to write code.

dll_1:

#include "stdafx.h" #include <iostream> using namespace std; void first_func(void) { cout << "First function in first dll\n"; three_func(); } void second_func(void) { cout << "second function in first dll.\n"; four_func(); } _declspec(dllexport) void three_func(void) { three_func(); } _declspec(dllexport) void four_func(void) { four_func(); } 

dll_2:

 #include "stdafx.h" #include <iostream> using namespace std; void three_func(void) { cout << "three function in second dll\n"; second_func(); } void four_func(void) { cout << "four function in second dll\nНу нифига себе."; } _declspec(dllexport) void second_func(void) { second_func(); } 
  • So do as you describe - Vladimir Martyanov
  • Uh ... And for what the strange construction _declspec(dllexport) void three_func(void) { three_func(); } _declspec(dllexport) void three_func(void) { three_func(); } ? Why it is impossible without it, and declspec to hang on the original function? Plus you need a header, of course. - VladD
  • is it easier? I wrote void first_func (void) in the header; void second_func (void); void three_func (void); void four_func (void); - Oleg Brony

1 answer 1

I would do this.

In the first DLL in the exported header (Dll1.h):

 #ifdef DLL1_EXPORTS #define DLL1_API __declspec(dllexport) #else #define DLL1_API __declspec(dllimport) #endif DLL1_API void first_func(void); DLL1_API void second_func(void); 

In the cpp-file:

 #include "stdafx.h" #include "Dll1.h" #include "Dll2.h" DLL1_API void first_func(void) { cout << "First function in first dll\n"; three_func(); } DLL1_API void second_func(void) { cout << "second function in first dll.\n"; four_func(); } 

In the properties of the project in the Preprocessor definitions added DLL1_EXPORTS (required!).

I would do the same with Dll2. Everything!


Perhaps it makes sense for the exported functions to add extern "C" (of course, in the same macro).