-
February 25th, 2011, 06:31 PM
#1
Problem: pointer (ref to structure) as an argument for a function
Hello Gentlemen,
I am a newbie in programming and apologise in advance if my question is too silly.
My c++ project is compiled as library .xll (DLL for excel), the framework code (program entry point) is coded correct and work stable. Custom functions are separate modules.
// header.h
typedef struct _TMDYDate {
long month;
long day;
long year;
} TMonthDayYear;
the file funcs.c has a function
// funcs.c
#include "header.h"
__declspec(dllexport) long GetDate() {
TMonthDayYear myDate;
myDate.day =1 ;
myDate.month = 1;
myDate.year = 2000;
if (DateToMDY(2004, &myDate) != 1) {
return 0;
}
return myDate.year;
}
where the function DateToMDY is declared in separate file "Dates.c"
// dates.c
int DateToMDY (long tmpyear, TMonthDayYear *mdy) {
mdy->year = tmpyear; // <- Error is here
return 1;
}
I debug a function "GetDate()" and get an error when try to assign by reference (mdy->year = tmpyear; ) the value 2004.
The error is: "Unhandled exception at 0x0e342b84 (alcDates.xll) in EXCEL.EXE: 0xC0000005: Access violation writing location 0x40e3db28".
The funny thing is when i move declaration of "DateToMDY" to the file "funcs.c", the same where the DateToMDY is called - there is no error.
I assume it is to wrong memory usage, but for me is critical to isolate functionality in different modules (ex. dates.c, array.c, sorting.c ...).
I don't know where to look for, may be i have wrong project compilation settings.
Thank you!
Nicholas
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|