| |

VerySource

 Forgot password?
 Register
Search
View: 771|Reply: 5

A value problem in ATL, which I just learned is not clear

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-29 11:20:01
| Show all posts |Read mode
I want to pass in 2 data to enter, and add the results after adding
For example, I pass in 1 and 2 and add 3, I want to get the result of 3.
But I never get the answer, I hope I can get help
....
interface Ifun: IDispatch
{
[id (1), helpstring ("method add1")] HRESULT add1 ([in] int n1, [in] int n2, [out, retval] BSTR * ch);
};
.... // This is the interface

STDMETHODIMP Cfun :: add1 (int n1, int n2, BSTR * ch)
{
// TODO: Add your implementation code here
char * ch1 = _com_util :: ConvertBSTRToString (* ch);

int n3;
n3 = n1 + n2;
ch1 = new char [100];

itoa (n3, ch1, 100);
// delete [] ch1;

return n3;
}

Calling script:
<script language = "javascript">
var myobj = new ActiveXObject ("atltest1.fun");
var i = myobj.add1 (1,2);
alert (i);
</ script>
The result is empty. I don't know if I should improve there. I hope that the passing expert can help.
Reply

Use magic Report

0

Threads

12

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 Poland

Post time: 2020-3-2 13:30:01
| Show all posts
Pointer to pointer
Reply

Use magic Report

0

Threads

21

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-3-6 23:15:02
| Show all posts
the return value should be VARIANT
Reply

Use magic Report

0

Threads

17

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-3-8 08:30:01
| Show all posts
STDMETHODIMP Cfun :: add1 (int n1, int n2, BSTR * ch)
{
// TODO: Add your implementation code here
USES_CONVERSION;

int n3;
char ret [16];

n3 = n1 + n2;
itoa (n3, ret, 10);
if (ch) * ch = A2BSTR (ret);

return S_OK;
}
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-3-10 01:00:01
| Show all posts
kk1370
=====================
Thanks, can be displayed

But I want to ask one more thing, if it is delphi calling this control
Is the returned BSTR acceptable?
Reply

Use magic Report

0

Threads

17

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-3-10 13:00:01
| Show all posts
can
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list