cdlllcc-win32

Segment violation writing to variable in DLL (lcc-win32)


I've built a DLL with a few functions and global variables. Then I've used buildlib to create an import library for it.

The .exp file is:

CSC_FFSW.dll
_CSC_FFSW_B                _CSC_FFSW_B        data
_CSC_FFSW_DWork            _CSC_FFSW_DWork    data
_CSC_FFSW_M                _CSC_FFSW_M        data
_CSC_FFSW_U                _CSC_FFSW_U        data
_CSC_FFSW_Y                _CSC_FFSW_Y        data
_CSC_FFSW_initialize       _CSC_FFSW_initialize
_CSC_FFSW_step0            _CSC_FFSW_step0
_CSC_FFSW_step1            _CSC_FFSW_step1

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.

Instead of using an import library, I tried manually importing the symbols from the DLL using:

dllHandle = LoadLibrary("CSC_FFSW.dll");
myType* pCSC_FFSW_U = (myType*)GetProcAddress(dllHandle, "_CSC_FFSW_U");
...
etc.

With this approach I can write to the variables fine. However, this method is not so nice because it requires more manual, error prone work.

Should it be possible to have read-write access to the variables in the import library created by buildlib? How should I specify this in the .exp file?

Many thanks,

Miguel


Solution

  • The issue was caused by missing __declspec(dllimport) and __declspec(dllexport) in the declaration of the variables.

    See https://groups.google.com/forum/#!topic/comp.compilers.lcc/FrIyE0HMI04 for more details.