I'm a newbie and I'm trying to create a dll that will work in Excel in VC++ 6. One function must take an array. I've got an example, but somehow it doesn't work for me.
This is what I'm trying to do:
#define OLE2ANSI
#include <windows.h>
#include "stdafx.h"
#include "ole2.h"
#include "dispatch.h"
#include "stdlib.h"
#define ChunkSize 65535
char *szBlock;
char *szBlockNew;
#if !defined(WIN32)
typedef char *LPWSTR;
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
int FAR PASCAL WEP (int nArgument)
{
return 1;
}
#endif
double WINAPI Interpolate(long MyDate, SAFEARRAY **psa)
{
long iNumItems;
long aiIndex[2];
long iDate=0;
double iValue=0;
int aTemp=0;
long aDate;
long bDate;
long cDate;
double aValue;
double bValue;
double cValue;
if(FAILED(SafeArrayGetUBound(*psa,1,&iNumItems)))
goto Failure;
for(aiIndex[0]=0;aiIndex[0]<=iNumItems;aiIndex[0]++)
{
cDate=iDate;
cValue=iValue;
aiIndex[1]=0;
if(FAILED(SafeArrayGetElement
(*psad,&aiIndex,&iDate))) goto Failure;
aiIndex[1]=1;
if(FAILED(SafeArrayGetElement
(*psav,&aiIndex,&iValue))) goto Failure;
if(iDate==0,iDate>=MyDate,aTemp==0)
{
aDate=iDate;
bDate=cDate;
aValue=iValue;
bValue=cValue;
}
}
return=bValue+(aValue-bValue)/(aDate-bDate)*(MyDate-bDate);
Failure:;
return=0;
}
As you can see, it's only an interpolate function taking an array from Excel. I've just made some minor alterations to the original example: I've changed the safearray from a one column array to a two column array, and the first column consists of dates. I think it's based on C code, but it compiles perfectly. My modified attempt does, however, not. I get 1 error when building. Please, help.
This is what I'm trying to do:
#define OLE2ANSI
#include <windows.h>
#include "stdafx.h"
#include "ole2.h"
#include "dispatch.h"
#include "stdlib.h"
#define ChunkSize 65535
char *szBlock;
char *szBlockNew;
#if !defined(WIN32)
typedef char *LPWSTR;
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
int FAR PASCAL WEP (int nArgument)
{
return 1;
}
#endif
double WINAPI Interpolate(long MyDate, SAFEARRAY **psa)
{
long iNumItems;
long aiIndex[2];
long iDate=0;
double iValue=0;
int aTemp=0;
long aDate;
long bDate;
long cDate;
double aValue;
double bValue;
double cValue;
if(FAILED(SafeArrayGetUBound(*psa,1,&iNumItems)))
goto Failure;
for(aiIndex[0]=0;aiIndex[0]<=iNumItems;aiIndex[0]++)
{
cDate=iDate;
cValue=iValue;
aiIndex[1]=0;
if(FAILED(SafeArrayGetElement
(*psad,&aiIndex,&iDate))) goto Failure;
aiIndex[1]=1;
if(FAILED(SafeArrayGetElement
(*psav,&aiIndex,&iValue))) goto Failure;
if(iDate==0,iDate>=MyDate,aTemp==0)
{
aDate=iDate;
bDate=cDate;
aValue=iValue;
bValue=cValue;
}
}
return=bValue+(aValue-bValue)/(aDate-bDate)*(MyDate-bDate);
Failure:;
return=0;
}
As you can see, it's only an interpolate function taking an array from Excel. I've just made some minor alterations to the original example: I've changed the safearray from a one column array to a two column array, and the first column consists of dates. I think it's based on C code, but it compiles perfectly. My modified attempt does, however, not. I get 1 error when building. Please, help.