This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Excel add-in and cygwin.dll



I am trying to find out if it is possible to build Excel Add-In that is using
Cygwin DLL and is capable of calling Excel functions through
xlcall32 library.
I believe someone on this list mentioned that you can do this only when
'-mno-cygwin' option is used so no cygwin1.dll is linked.

I tried building very simple XLL that can be loaded into Excel using Add-In
manager. When using 'no-cygwin' option
XLL loads fine. When I remove 'no-cygwin' option Excel crashes inside
cygwin1.dll. Even when I remove 'Excel4(...)' call which does not link
xlcall32.dll, add-in still crashes.

Following is the program, makefile, def file and 'cygcheck tst.xll' output in
case someone wants to try it. libxlcall32.a was created using
dlltool and hand-crafted .def file.


--------- tst.cpp
#include <windows.h>
#include <stdlib.h>
#include <xlcall.h>

#define DllImport __declspec(dllimport)
#define DllExport __declspec(dllexport)

/**     XLOPER string object. No virtual functions please.
        */
struct XLOPERString : public XLOPER
{
        /// Construct XLOPER string object
        XLOPERString(const char* txt)
        {
                if (txt)
                {
                        val.str = (char*) malloc(strlen(txt)+1);
                        strncpy(val.str + 1, txt, strlen(txt));
                        val.str[0] = strlen(txt);
                        xltype = xltypeStr;
                }
                else
                {
                        val.str = 0;
                }
        }
        /// Destroy XLOPER string object
        ~XLOPERString()
        {
                if (val.str)
                        free(val.str);
        }
};

/**     XLOPER integer object. No virtual functions please.
        */
struct XLOPERInt : public XLOPER
{
        /// Construct XLOPER integer object
        XLOPERInt(int ival)
        {
                xltype = xltypeInt;
                val.w = ival;
        }
};


#ifdef __cplusplus
extern "C" {
#endif
BOOL APIENTRY DllMain( HANDLE hDLL, DWORD dwReason, LPVOID lpReserved );
int DllExport WINAPI xlAutoOpen (void);
int DllExport WINAPI xlAutoAdd  (void);
#ifdef __cplusplus
}
#endif


BOOL APIENTRY DllMain( HANDLE hDLL, DWORD dwReason, LPVOID lpReserved )
{
        return TRUE;
}

int DllExport WINAPI xlAutoOpen(void)
{
        XLOPERString    ss("addin opened");
        XLOPERInt       ii(2);
        Excel4(xlcAlert, 0, 2, (LPXLOPER) &ss, (LPXLOPER) &ii);
        return 1;
}

int DllExport WINAPI xlAutoAdd(void)
{
        XLOPERString    ss("addin added");
        XLOPERInt       ii(2);
        Excel4(xlcAlert, 0, 2, (LPXLOPER) &ss, (LPXLOPER) &ii);
        return 1;
}


---------- makefile
C       = gcc
CC      = g++
CFLAGS  = -I. -g -mno-cygwin
CCFLAGS = -I. -g -mno-cygwin

LEX     = flex++
LFLAGS  = -Sflex_std.skl

LD      = dllwrap
LDFLAGS = -verbose --def tst.def -mno-cygwin -s -dll -mwindows -L../xlsdk -e
_DllMain@12

LIBS    = -lxlcall32

TARGET  = tst.xll

.SUFFIXES : .o .c .cpp .l


.c.o :
        ${C} ${CFLAGS} -c $<

.cpp.o :
        ${CC} ${CCFLAGS} -c $<

.l.cpp :
        ${LEX} ${LEXFLAGS} $<

OBJS    = \
        tst.o

${TARGET} : ${OBJS}
        ${LD} ${LDFLAGS} -s --dll -o $@ ${OBJS} ${LIBS}

clean :
        rm -rf *.o *~ doc ${TARGET}


----------- tst.def file
EXPORTS
        xlAutoOpen
        xlAutoAdd

----------- cygcheck output
Found: .\tst.xll
.\tst.xll
  c:/ct2/xlcall32.dll
    C:\WINNT\System32\KERNEL32.dll
      C:\WINNT\System32\ntdll.dll
  C:\WINNT\System32\msvcrt.dll

Use -h to see help about each section

----------- cygcheck output (with cygwin)
Found: .\tst.xll
.\tst.xll
  c:/ct2/xlcall32.dll
    C:\WINNT\System32\KERNEL32.dll
      C:\WINNT\System32\ntdll.dll
  C:\WINNT\System32\cygwin1.dll

Use -h to see help about each section







This communication is for informational purposes only.  It is not intended as
an offer or solicitation for the purchase or sale of any financial instrument
or as an official confirmation of any transaction. All market prices, data
and other information are not warranted as to completeness or accuracy and
are subject to change without notice. Any comments or statements made herein
do not necessarily reflect those of J.P. Morgan Chase & Co., its
subsidiaries and affiliates.


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]