Custom ActiveX Control in C++

W

Wolfgang

Hello,

i managed to go through the hands-on-lab-6 for infopath dealing with
the creation of custom activex controls for infopath. the lab shows
how a control can be created that returns a variable of type long to
infopath.

I tried to modify the activex control from the lab to return a string,
but it doesn't work. I don't know which data type i have to use
therefore and how to define the appropriate methods using the MIDL
file of the control.

Can anybody help me and show how this can be done ?

Greetings,
Wolfgang
 
A

Andrew Ma [MSFT]

What return types have you tried when returning a string?

--
Andrew J. Ma
Software Test Engineer
Microsoft Office InfoPath
http://blogs.msdn.com/ajma
---------------------------------------
This posting is provided "As Is" with no warranties, and confers no rights.
Use of any included script sample are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
Please do not send email directly to this alias. This alias is for
newsgroup purposes only.
 
W

Wolfgang

Hallo again,
What return types have you tried when returning a string?

i first used the control from the hands-on-lab6 with a long. that
worked fine.
then i changed the code of the lab to transfer a single char. this
also worked.

the next thing i thought about was to modify this example to transfer
a string to infopath.

i know that i have to specify a get-Method for the string that
infopath should insert into its xml-tree. My problem is that I do not
know ..

1.) which datatype is the correct one for a string (char, char[],
byte[], ...) ?

2.) how to edit the get-Method in the IDL-file for the control in a
way that an array of a specified datatype (if array is needed) can be
used ?

Greetings,
Wolfgang
 
A

Andrew Ma [MSFT]

BSTR is what you want to use for strings.

--
Andrew J. Ma
Software Test Engineer
Microsoft Office InfoPath
http://blogs.msdn.com/ajma
---------------------------------------
This posting is provided "As Is" with no warranties, and confers no rights.
Use of any included script sample are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
Please do not send email directly to this alias. This alias is for
newsgroup purposes only.


Wolfgang said:
Hallo again,
What return types have you tried when returning a string?

i first used the control from the hands-on-lab6 with a long. that
worked fine.
then i changed the code of the lab to transfer a single char. this
also worked.

the next thing i thought about was to modify this example to transfer
a string to infopath.

i know that i have to specify a get-Method for the string that
infopath should insert into its xml-tree. My problem is that I do not
know ..

1.) which datatype is the correct one for a string (char, char[],
byte[], ...) ?

2.) how to edit the get-Method in the IDL-file for the control in a
way that an array of a specified datatype (if array is needed) can be
used ?

Greetings,
Wolfgang
 
W

Wolfgang

Hello,

i tried with BSTR but it does not work. My hardcoded string value
wasn't saved into the xml-file when saving the form in Fill-Out-Mode.

This is how I implemented it:

1. Generated IDL-Definitions using VS.NET 2003-Wizard.

[propget, id(2), helpstring("property BValue")] HRESULT BValue([out,
retval] BSTR* pVal);
[propput, id(2), helpstring("property BValue")] HRESULT BValue([in]
BSTR newVal);

2. Implemented the get-Method with the following code.

STDMETHODIMP CTestControl::get_BValue(BSTR* pVal)
{
BSTR testValue = new WCHAR[11];
swprintf(testValue,L"TestString");
pVal = &testValue;
return S_OK;
}

Can you help me ?

Greetings,
Wolfgang
 
Top