When I import the DLL from a program, I can read the global variables
(e.g. CSC_FFSW_U), but when I try to write them I get a Segment
Violation exception.
double k = CSC_FFSW_U.field; // this works
CSC_FFSW_U.field = 2.0; // this causes a segment violation
When I import the DLL from a program, I can read the global variables
(e.g. CSC_FFSW_U), but when I try to write them I get a Segment
Violation exception.
How do you "write them"?
How are they declared to the C compiler?
Win32 DLL-shared variables are really pointers (much like functions are
in C); when reading, things works smoothly because the compiler silently perform the indirection; but on writing, you need to perform explicit dereference. One way is to do it is to code explicitly
*CSC_FFSW_U = 1;
but for more than 20 years now, the solution uses to be to "decorate"
the declaration of the variable with __declspec(dllimport); then the
compiler will insert the required code.
To sum up, the issue in my code comes indeed from not being able to put the dllimport/dllexport, but the old LCC version I'm using has some weird behaviour with dllimport and I think I won't be able to fix the problem that way. However, the newerversion of LCC doesn't have this issue and should work fine.
Thanks Antoine and Jacob for your help.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 185 |
Nodes: | 16 (1 / 15) |
Uptime: | 169:04:04 |
Calls: | 3,766 |
Calls today: | 4 |
Files: | 11,191 |
Messages: | 3,474,219 |