handlex behaving in a strange way with xloper12

Sep 5, 2012 at 9:17 PM

Hi Keith,

 

 may i seek your help regarding the following issue.

I wrote my code (I give below) using xloper (i am using excel 2007 and visula studio 2008) and got the desired results. But when i changed to xloper12 my handlex function does not work properly.

the code is as follows:

first i create a set of arguments:

AddInArg12 arg[3] = {
 AddInArg12(L"K%",_T("Arg1"),    _T("Argument 1")),
 AddInArg12(L"K%",_T("Arg2"),    _T("Argument 2")),
 AddInArg12(L"K%",_T("Arg3"),    _T("Argument 3")),
};

then i create the AddIn12 object

 static AddIn12 xai_create_handl(
 XLL_HANDLEX,L"?xll_create_handle",
 L"qv.createH", 3, arg,
 L"Example", L"creates object with 3 arguments"
);

then i create the handle

HANDLEX WINAPI
xll_create_handle(
      const _FPX arg1
     ,const _FPX arg2
     ,const _FPX arg3
      )
{
#pragma XLLEXPORT
 HANDLEX h;
 
 try
 {

   handle<OBJ> h_(new OBJ(
          arg1
         ,arg2
         ,arg3

       ));
   ensure(h_);

   h = h_.get();
 }
 catch (const std::exception& ex)
 {
  XLL_ERROR(ex.what());

  return 0;
 }

 return h;
};

the object files are as follows:

 

// OBJ.h
class OBJ
{
 public:


  OBJ(
      xll::FPX arg1
    , xll::FPX arg2
    , xll::FPX arg3
                   )

 private:


  xll::FPX m_arg1;
  xll::FPX m_arg2;
  xll::FPX m_arg3;

}

// OBJ.cpp
OBJ::OBJ(
      xll::FPX arg1
    , xll::FPX arg2
    , xll::FPX arg3

      ):
 m_arg1(arg1)
,m_arg1(arg2)
,m_arg1(arg3)
{
};

 the code works fine when i replace AddinArg12 with AddinArg, L"K%",_with "K" and Addin12 with Addin.

But the way I give above it compiles okay. but when i try to use the function in excel it creates a circular refernce error. And then i get back "0" in the function call cell. It would be very kind if you can provide any pointers as to what is going wrong.

 

Best

 

Coordinator
Sep 5, 2012 at 11:08 PM

Functions that construct new objects must be uncalced. I see a lot of problems with your code. Maybe you should use the named argument idiom for AddIn objects. It is clearer and easier to maintain.

static AddIn12 xai_create_handle(
 Function12(XLL_HANDLEX, L"?xll_create_handle", L"qv.createH")
 .Arg(XLL_FP12, L"Arg1", L"is the first arg.")
 .Arg(XLL_FP12, L"Arg2", L"is the second arg.")
 .Arg(XLL_FP12, L"Arg3", L"is the third arg. ")
 .Uncalced() // <-- don't forget this
 .Category(L"Example")
 .FunctionHelp(L"creates object with 3 arguments")
);
Sep 5, 2012 at 11:30 PM

Hi Keith,

 

 thank you very much for your prompt reply. I see the problem but does Function12() exist in your addin from here:  http://kalx.net/xll.  If it does I will have a easy way to put the "Uncalced()" otherwise I will have to figure out what how to put in that old version.

Since I am using visual studio 2008 you recommended the above addin. 

 

Best

 

Sep 6, 2012 at 4:23 PM

hi Keith,

 

 after your suggestion, i moved over to your latest addin (i had to download visaul studio 2010 express edition).

i tried to use the  

.Uncalced() // <-- don't forget this

but what i get now is an error like :

error C2039: 'Uncalced' : is not a member of 'xll::XArgs<X>'

2> with

2> [

2> X=XLOPER12

2> ]

Best

 

Sep 6, 2012 at 5:43 PM
Edited Sep 6, 2012 at 9:11 PM

i see the issue now. .Uncalced() was not there in the version of xll20120116.zip file. After i updated arg.h from the trunk the above error went away. but i am back to the original problem that i faced. when i do as you suggested the code complies fine. i open up excel in the debug mode and then open up the function popup box which allows me to enter the function argument in excel. i keep entering values to the argument and then as i reach the last argument i get an access violation error.

note that this issue was not there when i was using xloper (for which the handle was getting created).

when i changed over to xloper12 this problem with the handle and the function started.

Seems like a xloper issue. Please help.

 

---------------

what i observe is, it is some issue with the _FP12 datastructure. in the debug mode what i see is

xll_create_handle(
      const _FPX arg1
     ,const _FPX arg2
     ,const _FPX arg3
      )
{
#pragma XLLEXPORT
 HANDLEX h;
 
 try
 {

   handle<OBJ> h_(new OBJ(
          arg1
         ,arg2
         ,arg3

       ));

...

}

arg1, arg2 and arg3 is not properly instanciated resulting in objects like

arg1 {rows=1242820 columns=2014606148 array=0x0012f6ac } _FP12

this was not the case when i was using xloper instead of xloper12.

-------------

the example i gave above is kind of simple with 3 arguments. what i actually have is a function with 11 arguments. and i observe that the _FPX arg6 goes bad with undefined row and columns. Is there any limit that i do not know about.

 

Coordinator
Sep 7, 2012 at 2:16 AM

Now that you are using Visual Studio 2010, why not click on the links on the main page to install the latest version?

Sep 7, 2012 at 1:32 PM

yes i am using the the latest version of yours. May I please seek your help with the issues with FPX. I have this function with 11 arguments and after the 5th argument the FP's are becoming corrupt with something like {rows=1242820 columns=2014606148 array=0x0012f6ac } _FP12. What can be causing this ?

 

Best

  

Coordinator
Sep 7, 2012 at 2:12 PM

When the arguments you specify in AddIn don't agree with the arguments of the C function, you might see this.

Sep 7, 2012 at 7:10 PM

Hi Keith,

 

 the issue that you suggest cannot be the case. i give below my code exactly. the number of argument i specify in the addin is 3 and the number of argument in the c function is also 3. i still see the problem.

static AddInX xai_create_ENV(
 Function12(XLL_HANDLEX, L"?xll_create_env", L"qv.createEnv")
 .Arg(XLL_FPX, L"dynLap", L"is the first arg.")
 .Arg(XLL_FPX, L"dynWith", L"is the second arg.")
 .Arg(XLL_FPX, L"resPar", L"is the third arg. ")
 .Uncalced()
 .Category(L"Example")
 .FunctionHelp(L"creates env with market data")
);

HANDLEX WINAPI
xll_create_env(
					 FPX dynamicLapse
					,FPX dynamicWithdrawl
					,FPX resetParameters
					
				  )
{
#pragma XLLEXPORT
	HANDLEX h;
	
	try 
		{

		
			handle<ENV> h_(new ENV(
									 dynamicLapse
									,dynamicWithdrawl
									,resetParameters

							));
			ensure(h_);

			h = h_.get();
	}
	catch (const std::exception& ex) 
	{
		XLL_ERROR(ex.what());

		return 0;
	}

	return h;
};
Coordinator
Sep 7, 2012 at 7:43 PM

It is exactly the case. You are specifying the arguments of the C function as FPX. They should be _FPX*. Note the underscore and asterisk.

See http://xll.codeplex.com/wikipage?title=FP for an example of the correct way to use FP data types.

Sep 7, 2012 at 8:41 PM

you are exactly correct. Thank you very much. I guess I completely confused myself with the FPX structure. Cannot thank  you enough for the beautiful addin that you built.

Coordinator
Sep 7, 2012 at 8:52 PM

Glad you like it. Don't forget about XLL.DOC for creating integrated help files. The video on the home page shows how to do that.