Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create DLL taking safearray from Excel

Status
Not open for further replies.

josefl

Programmer
Nov 29, 2002
12
SE
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 &quot;stdafx.h&quot;
#include &quot;ole2.h&quot;
#include &quot;dispatch.h&quot;
#include &quot;stdlib.h&quot;

#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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top