LNString and DLL Return +++++ URGENT +++++ ;o)

Hi everyoneWe have a problem returning the value of an LNString from a DLL (c++). Is any guru able to help us?

We are trying to create a DLL in C++ to return a list of Subforms embedded in a form.

We do manage to do this from an EXE but we need a DLL. Our problem is with adding the various subformnames to somekind of string and returning a result from the DLL.

We tried in everyway we could think. Some examples are still remmed out. What we get is “<%ŒÌ B;SubForm2;” which should be “SubForm1; SubForm2;”. If the form has 3 embedded subforms, the dll crashes the Notes instance!

Here is the code from the DLL (C++)

Thanks in advance to anyone reading.

// Get Embedded Subforms

char * DSGetEmbeddedSubforms(char *DbFilename, char *DBServer, char *FormName)

{

LNNotesSession Session;

Session.Init ();

try

{

	LNDatabase			Db;

	LNForm				form;

	LNSubform			subform;

	LNRTSubform			rtSubform;

	LNRichText			FormBodyItem;

	LNString			SubFormList;

	LNString			SubFormName;



	Session.GetDatabase(DbFilename, &Db, DBServer);

	Db.Open();



	// Get Passed Form

	Db.GetForm(FormName, &form);

	form.Open();



	form.GetFormBody(&FormBodyItem);



	LNRTCursor cursor;

	FormBodyItem.GetCursor(&cursor);



	// Get list of subforms in the form



	// Get the first subform in the form

	if (LNWARN_NOT_FOUND != cursor.GotoFirst(LNRTTYPE_SUBFORM, &rtSubform))

	{

	do

		{

		//char *	Buff;

		rtSubform.GetSubform(&subform);

		subform.Open();

		

		SubFormName = subform.GetName();

		

		SubFormList.Append(SubFormName);

		SubFormList.Append(";");



		/* This is all of the various trials we did -- PLEASE IGNORE



		Buff = const_cast<char *>(static_cast<const char *>(SubFormName.GetTextPtr()));

		SubFormList.Append(const_cast<char *>(static_cast<const char *>(Buff)));

		strcat(SubFormList, const_cast<char *>(static_cast<const char *>(SubFormName.GetBuf())));

		const_cast<char *>(static_cast<const char *>(SubFormList);

		strcat(SubFormList, "; ");*/



		} while (cursor.GotoNext(LNRTTYPE_SUBFORM, &rtSubform) != LNWARN_NOT_FOUND);

	}

//return SubFormList;

	return const_cast<char *>(static_cast<const char *>(SubFormList));

	subform.Close();



	// close the database

	Db.Close();

}

// Error handler.  If an error occurred, get the text of the error

// message and display it.

catch (LNSTATUS lnerror)

{

	char ErrorBuf[256];

	LNGetErrorMessage(lnerror, ErrorBuf, 256);

	return ("1");

}

Session.Term();

}

Subject: LNString and DLL Return +++++ URGENT +++++ ;o)

It appears that you are getting corruption because the SubFormList destructor is run before the routine exits. This invalidates any ptr retrieved from the buffer. You might want to allocate a buffer from the heap of the correct size and append to it and then return a pointer to it, freeing the buffer when you are done.