XLL Add-In für Excel mit C/C++ programmiert
-
Hallo zusammen,
ich möchte gerne ein XLL für Excel entwickeln. Hab das jetzt mit der Excel2007 XLL SDK gemacht und versucht das XLL dann als Add-In in Excel 2003 hinzuzufügen.
Funktioniert leider nicht. Excel sagt, das wäre kein gültiges Add-In. Hat da jemand vielleicht Erfahrungen damit?
Im Internet findet man irgendwie nur Beschreibungen wie das ganze mit Excel 97 geht. In der SDK ist das ganze dann für Excel 2007 beschrieben. Da ist die C-API dann schon wieder anders. Vielleicht ist aber auch mein Code falsch.
Hier mal kurz der Code:static LPSTR func[1][10] = { {"add", "JJJ", "add", "", "1", "MyCat", "", "", "",""} }; BOOL APIENTRY DllMain( HANDLE hDLL, DWORD dwReason, LPVOID lpReserved ) { switch (dwReason) { case DLL_PROCESS_ATTACH: // The instance handle passed into DllMain is saved // in the global variable g_hInst for later use. break; case DLL_PROCESS_DETACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: default: break; } return TRUE; } __declspec(dllexport) int add(int a, int b) { return a+b; } __declspec(dllexport) int WINAPI xlAutoOpen(void) { // DEBUG output to indicate when called int i, j; int nFuncs=1; // Get XLL file name static XLOPER xDll; Excel12f(xlGetName, &xDll, 0); // Prefix strengths with their length & count items // Note the framework's TempStr() function prefixes the // lengths anyway, but this is for other code that might // use the arrays /*for(nFuncs=0; func[nFuncs][0]; nFuncs++) { for(i=0; i<9; i++) { func[nFuncs][i][0] = (BYTE) strlen(func[nFuncs][i]+1); } }*/ /*for(nMenuItems=0; menu[nMenuItems][0]; nMenuItems++) { for(i=0; i<5; i++) { menu[nMenuItems][i][0] = (BYTE) strlen(menu[nMenuItems][i]+1); } }*/ // Loop through the function list, and register the functions for(i=0; i<nFuncs; i++) { // Register a function Excel12f(xlfRegister, 0, 11, (LPXLOPER12)&xDll, (LPXLOPER12)TempStr(func[i][0]), (LPXLOPER12)TempStr(func[i][1]), (LPXLOPER12)TempStr(func[i][2]), (LPXLOPER12)TempStr(func[i][3]), (LPXLOPER12)TempStr(func[i][4]), (LPXLOPER12)TempStr(func[i][5]), (LPXLOPER12)TempStr(func[i][6]), (LPXLOPER12)TempStr(func[i][7]), (LPXLOPER12)TempStr(func[i][8]), (LPXLOPER12)TempStr(func[i][9]) ); } // Free XLL file name from the xlGetName call made earlier Excel12f(xlFree, 0, 1, (LPXLOPER)&xDll); // // Menu support section // static XLOPER xMenu; // static XLOPER xMenuList[10*5]; // ASSERT(nMenuItems< 10); // // Build menu // xMenu.xltype = xltypeMulti; // xMenu.val.array.lparray = &xMenuList[0]; // xMenu.val.array.rows = nMenuItems; // xMenu.val.array.columns = 5; // for(i=0; i<nMenuItems; i++) { // for(j=0; j<5; j++) { // xMenuList[j+i*5].xltype = xltypeStr; // xMenuList[j+i*5].val.str = menu[i][j]; // } // } // // Add menu //Excel(xlfAddMenu,0,3,TempNum(1),(LPXLOPER)&xMenu,TempStr(" Help")); // Finished return 1; }