Failing to read the underlying object from the handle

Sep 10, 2012 at 4:47 PM

Hi Keith,

 

 may i seek your help some more regarding another issue that i am facing.

like befor i create a handle which gets created okay in excel

static AddInX xai_create_ENV(
Function12(XLL_HANDLEX, L"?xll_create_env", L"qv.createEnv")
 .Arg(XLL_FPX, L"dynLap", L"arg1")
 .Arg(XLL_FPX, L"dynWith", L"arg2")
 .Arg(XLL_FPX, L"resPar", L"arg3")
 .Uncalced()
 .Category(L"Example")
 .FunctionHelp(L"creates env handle ")
);

HANDLEX WINAPI
xll_create_env(
					 const _FPX* dynamicLapse
					,const _FPX* dynamicWithdrawl
					,const _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;
};
the object env is defined as 

 

	class ENV
	{

	public:

		ENV(
				  xll::FPX dynamicLapse
				, xll::FPX dynamicWithdrawl
				, xll::FPX resetParameters

			);
	private:


		xll::FPX	m_dynamicLapse;
		xll::FPX	m_dynamicWithdrawl;
		xll::FPX	m_resetParameters;
       }
and when i try to read the object from the handle i see that the object is not created properly.
static AddInX xai_qval_evaluate(
Function12(XLL_LONGX , L"?xll_qval_ev", L"qv.Evaluate")
 .Arg(XLL_HANDLEX, L"Env", L"environment handle")
 .Category(L"Example")
 .FunctionHelp(L"computation")
 );

LONG WINAPI
xll_qval_ev(
			 HANDLEX envHandle

			)
{
#pragma XLLEXPORT
	int value;
	try 
	{
		// read the env handle
		handle envh(envHandle);
		value=2;
	}
	catch (const std::exception& ex) 
	{
		XLL_ERROR(ex.what());

		return 0;
	}

	return value;

};

i observe in the debug that all the members of the env object is null.

i cannot figure out what i am doing wrong.

 

 

Coordinator
Sep 10, 2012 at 6:46 PM

If you use handle<ENV> h_(new ENV ...); in the 'constructor' you have to use handle<ENV> h_(envHandle) in the 'member'. Handles are type safe.

Also, if you pass _FPX* to ENV which is expecting xll::FPX you're not going to have a good time.

Sep 10, 2012 at 6:56 PM

actually i take back the question.

it works fine.

The function which was breaking down for me was slightly more complicated.

It had two handles getting passed and i had a bug in the program which was causing the error.

But you deserve the complete credit for this issue because i tracked down the bug based on one of your earlier comment.

If you want I can delete this discussion thread as it does not provide any useful information for other users.

 

Best