[Dev-C++] Creating SafeArrays in dev-cpp
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Marcelo K. <kit...@md...> - 2003-11-04 12:26:40
|
I am new to c++ and I just started to build a dll that can be used by =
excel. To practice in the building of my dll I would want it to return =
an array to excel, but I have tried hard without success. I can make the =
dll return single values, but not arrays.
I know that arrays have to be exported as SafeArrays but could not =
implement this in Dev-Cpp. There are some examples with the Microsoft =
compiler but when I try to compile them they failed.=20
In the Example below I got the error "[Linker error] undefined =
reference to `SafeArrayCreate@12'"
#include <windows.h>
#include <oleauto.h>
=20
#define DllExport __declspec(dllexport) __stdcall
extern "C" {
short DllExport NewArray(LPSAFEARRAY *ppsa)
{
LPSAFEARRAY psa;
SAFEARRAYBOUND sa;
sa.lLbound =3D 1;
sa.cElements =3D 10;
if (*ppsa =3D=3D NULL) //array not yet initialized
{
if ((psa =3D SafeArrayCreate(VT_I2, 1, &sa)) =3D=3D NULL)
return -2;
*ppsa =3D psa;
}
if ((*ppsa)->cDims !=3D 1) // check array dimensions
return -1;
else return -3;
=20
return 0;
}
}
Does anyone give me some advice in this topic?
Thanks in advance
Marcelo
|