length-counted xltypeStr

I am working on a project to register a c++ xll into Excel via the xlfregister function.

I have successfully registered the c++ xll add-in in Excel 2007.

The xll shows in the add-in inventory, and gives a successful return code on registration.

The function I am attempting to register in this xll does not show at all.

I am able to make this work with VB code.

I have attached the c+ code (70 lines) which does not work, and the VB code (37 lines) which does work.

HINT: I read in Steve Dalton's book that the xlfRegister function expects length-counted xltypeStr strings.

I do not know how to tell whether my xltypeStr strings are length-counted, or how to make them so...

Thank you for any light you can shed on this problem.

Lon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Registration routine
      BOOL __stdcall xlAutoOpen(void) {
         AFX_MANAGE_STATE(AfxGetStaticModuleState( ));

// Get XLL file name

		 XLOPER xDll;
		 int iOutput = Excel4(xlGetName,&xDll,0);

		 XLOPER xInt;

		 xInt.xltype = xltypeInt;
		 xInt.val.w = 1;

		 XLOPER xName;
		 xName.xltype = xltypeStr;
		 xName.val.str = (LPSTR)"CMSUValue";
		 
		 XLOPER xTypes;
		 xTypes.xltype = xltypeStr;
		 xTypes.val.str = (LPSTR)"BBBBBBJJJBRJJJ";
		 
		 XLOPER xArgs;
		 xArgs.xltype = xltypeStr;
		 xArgs.val.str = (LPSTR)"Sbeg, Sval, v, r, q, divprotected, tsrtarget, window, T, paymatrixFP, Payout_Rows, Iterations, Interpolation";
		 
		 XLOPER xCat;
		 xCat.xltype = xltypeStr;
		 xCat.val.str = (LPSTR)"MSUcat";
		 
		 XLOPER xNull;
		 xNull.xltype = xltypeNil;
		 
		 XLOPER xFuncName;
		 xFuncName.xltype = xltypeStr;
		 xFuncName.val.str = (LPSTR)"MSU Function";
		 
 		 unsigned y, z; y=MB_OK; z=0;  // set up for messagebox
		 
		 iOutput = Excel4(
			 xlfRegister,
			 0,
			 10,
			 (LPXLOPER)&xDll,
			 (LPXLOPER)&xName,
			 (LPXLOPER)&xTypes,
			 (LPXLOPER)&xName,
			 (LPXLOPER)&xArgs,
			 &xInt,
			 (LPXLOPER)&xCat,
			 (LPXLOPER)&xNull,
			 (LPXLOPER)&xNull,
			 (LPXLOPER)&xFuncName
			 );  
		 
		 if(iOutput != xlretSuccess) {
		   AfxMessageBox(_T("xlfRegister failed"),y,z);
            }
		 else {
		   AfxMessageBox(_T("xlfRegister succeeded"),y,z);
            }

		 // Free XLL file name from the xlGetName call made earlier
         Excel4(xlFree, 0, 1, (LPXLOPER)&xDll);
		 		 AfxMessageBox(_T("xlFree completed"),y,z);

		 return 1;

}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Declare Function CMSUValue Lib "P:\FWC MSU\release\EMPERFADDIN.dll" _
( _
ByVal Sbeg As Double, _
ByVal Sval As Double, _
ByVal v As Double, _
ByVal r As Double, _
ByVal q As Double, _
ByVal divprotected As Long, _
ByVal tsrtarget As Long, _
ByVal window As Long, _
ByVal T As Double, _
ByRef paymatrixFP() As Double, _
ByVal Payout_Rows As Long, _
ByVal Iterations As Long, _
ByVal Interpolation As Long _
) _
As Double

Public Function CUV(Sbeg As Double, Sval As Double, v As Double, r As Double, q As Double, divprotected As Long, tsrtarget As Long, window As Long, T As Double, paymatrixFP As Range, Payout_Rows As Long, Iterations As Long, Interpolation As Long) As Double
Dim inputArray As Variant
Dim a As Double, b As Double
Dim p() As Double
Dim i As Long, j As Long
 
    inputArray = paymatrixFP.Value
    a = UBound(inputArray, 1)
    b = UBound(inputArray, 2)
    ReDim p(1 To a, 1 To b)
    
    For i = 1 To a
        For j = 1 To b
            p(i, j) = inputArray(i, j)
        Next j
    Next i
    
    CUV = CMSUValue(Sbeg, Sval, v, r, q, divprotected, tsrtarget, window, T, p, Payout_Rows, Iterations, Interpolation)
End Function

Last edited on
Topic archived. No new replies allowed.