0
I’m having trouble executing a code that uses a function of a DLL, which has a pointer as argument, according to the prototype:
DLLIMPORT void add_std_func(object list)
Follow the macro definitions DLLIMPORT
:
#if BUILDING_DLL
#define DLLIMPORT __declspec(dllexport)
#else
#define DLLIMPORT __declspec(dllimport)
#endif
and kind object
:
typedef char *string;
/*...*/
typedef void *pointer
/*...*/
typedef struct str_Intern_Object Intern_Object, *object;
/*...*/
typedef struct str_Class *Class;
struct str_Class{
const string name;
const Class super;
const size_t size;
void (* ctor)(object, pointer);
void (* dtor)(object);
};
struct str_Intern_Object{
pointer data;
Class class_pointer;
};
The problem is that if the function add_std_func
is defined outside the DLL (in the project itself or in a static library), the code works normally; but, when it is in the DLL, the code causes a segmentation failure when accessing the parameter list
. The DLL is added via argument to the compiler link (GCC).
Does anyone know why this is happening?
A DLL is a dynamic library (Dynamically Linked Library). Why are you trying to turn on a DLL statically? The normal is to call Loadlibrary within the program. Loadlibrary give the place and name of the DLL you should add. If not added, the program cannot find the function.
– Kyle A
In this case, the DLL is only an independent part of the code, but it must be present, being that only
add_std_func
and another function for callback registration are directly called by the main code. The idea is only to be able to update the DLL without having to recompile the rest of the project.– thiagofleal
So you don’t want static link. You’re calling
LoadLibrary
andGetProcAddress
before callingadd_std_func
?– Kyle A
The DLL is added to Linker during compilation, so it is loaded when the application is initialized (generating an error message when not found). The point is that the DLL is found and the function
add_std_func
is executed, but there is a segmentation failure when the function tries to access the parameter, which does not happen if it is in a static library.– thiagofleal
I don’t know a way to connect a DLL statically. You must have a 'header' at build time that declares the functions that the DLL provides, but the link happens when running with Loadlibrary and Getprocaddress.
– Kyle A
There is a header where the function
add_std_func
is declared. The DLL, in this case, functions as a library, but is loaded at runtime rather than compilation, as in the case of static libraries. In that case, there is no need to useLoadLibrary
andGetProcAddress
and I wouldn’t want to use them because I want to keep the code as portable as possible.– thiagofleal
What the code looks like where you’re accessing
list
?– Kyle A
This code is a bit extensive and has dependencies, but I’ll leave the link to the project on github here.
– thiagofleal