LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

DLL and exported character array ... "Out-of-bounds pointer argument (before start of array)"

Solved!
Go to solution

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:

 

2016-10-13 09_57_03-Watch.png

 

Yet in the Variables window, you can clearly see both the correct size of the array (260) and the initialized contents...

 

2016-10-13 09_56_50-Variables and Call Stack.png

 

What's going on here?

0 Kudos
Message 1 of 4
(3,810 Views)

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?

Message 2 of 4
(3,774 Views)

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.

0 Kudos
Message 3 of 4
(3,749 Views)
Solution
Accepted by topic author ElectroLund

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.

0 Kudos
Message 4 of 4
(3,044 Views)