10-13-2016 11:37 AM
I've got an error handler library that I use in all my projects. I've extended it to include a pathname it can use to output errors to the caller's preferred log file name. This works fine when the library source is attached to a project that needs it.
However, when I move to a DLL project which uses the same library, I'm running into problems.
I've simply done some DLLEXPORT / DLLIMPORT to expose this pathname to the DLL for its internal use. But when I do, I get errors when trying to strcpy or sprintf to it.
ErrorHandler.c
char errLog[MAX_PATHNAME_LEN] = {ERROR_LOG_FILE};
ErrorHandler.h
#define ERROR_LOG_FILE "error.log" // default output log file
extern char errLog[MAX_PATHNAME_LEN];
void ErrorMessage(char* logFile, double code, err_type_enum type, int line, char* function, char* file, int flags, char* string);
DLL source file.c
char DLLEXPORT errLog[MAX_PATHNAME_LEN];
DLL source file.h
char DLLIMPORT errLog[260];
The above is compiled into a DLL. Now at the test project which has this DLL attached, here are my tests...
ErrorMessage("C:\\Users\\user\\Desktop\\ERROR_NEW.log", 666, 1, 1, __FUNCTION__, __FILE__, ERR_OUT_LOG, "Oops!");
Passing this literal works!
sprintf(errLog, "C:\\Users\\user\\Desktop\\ERROR_2.log");
This gives a GPF, "FATAL RUN-TIME ERROR: "test.c", line 375, col 38, thread id 0x00002528: Out-of-bounds pointer argument (before start of memory block).
I get the same results for strcpy.
Now, check out my debugger... the errLog array can't be viewed in a Watch window:
Yet in the Variables window, you can clearly see both the correct size of the array (260) and the initialized contents...
What's going on here?
Solved! Go to Solution.
10-14-2016 06:54 PM
If I'm understanding correctly this library is working correclty with any project, until the projected is converted into a DLL, or am I mistaken?
10-17-2016 07:39 AM
That's correct. Sorry for the confusion. The library works as expected with any project as included source. But compile it to a DLL and then attach to any project... GPF land.
02-27-2018 09:55 AM
So, I have a very interesting update on this issue. Since upgrading to CVI 2017, this issue has gone away. I'm now able to change the contents of this character array from outside my DLL and view the contents in the debugger watch window without issues.
So I guess this got resolved in the latest release.