| |

VerySource

 Forgot password?
 Register
Search
View: 1015|Reply: 7

How does the function of the dll written by vc pass the string to vb?

[Copy link]

2

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-10-13 11:00:01
| Show all posts |Read mode
vc writes dll, I can only write int type functions:

__stdcall int CALLBACK CalcSum(int a,int b);

You can declare in vb:
Private Declare Function MySum Lib "d:\MyDLL.dll" (ByVal S As Integer, ByVal D As Integer) As Integer


This can be used in vb, but now I want to write a function in dll that can return a string, and use the label control of vb to display the string returned by the function. How do I write it in dll? How do I declare it in vb? How does the label control call it? Please help!
Reply

Use magic Report

0

Threads

8

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-10-13 11:15:01
| Show all posts
__stdcall int CALLBACK CalcSum(int a,int b,char *c);

You can declare in vb:
Private Declare Function MySum Lib "d:\MyDLL.dll" (ByVal S As Integer, ByVal D As Integer, ByRef c as string) As Integer
Reply

Use magic Report

0

Threads

22

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-10-13 11:45:01
| Show all posts
BSTR/VARANT
Reply

Use magic Report

0

Threads

10

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-10-13 12:00:01
| Show all posts
Use BSTR

CString::AllocSysString
BSTR AllocSysString () const;
throw( CMemoryException );

Return Value

Points to the newly allocated string.


or
SysAllocString
BSTR SysAllocString(
  OLECHAR FAR* sz
);
Reply

Use magic Report

0

Threads

10

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-10-13 12:15:01
| Show all posts
__stdcall char * CALLBACK CalcSum(int a,int b);

The return value of the function defined in vb is just a string type or a character pointer. . .
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-10-13 15:15:01
| Show all posts
vc write dll, vb call, interesting.
Reply

Use magic Report

0

Threads

30

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-10-13 16:30:01
| Show all posts
BSTR, RETVAL, ByRef
Reply

Use magic Report

2

Threads

16

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-10-13 17:30:01
| Show all posts
Try:
Convert String in VB to BSTR in VC, just change the parameter type, but pay attention to using ByRef
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