| |

VerySource

 Forgot password?
 Register
Search
View: 1840|Reply: 13

A dll call problem, please come to discuss it, it can be used in vb6.0, how to call it in vb.net! Let's take a look!

[Copy link]

1

Threads

7

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-11-30 20:30:01
| Show all posts |Read mode
Recently, they made an interface program, and their hardware manufacturer provided us with a standard dll, which is a function to convert decimal to hexadecimal.
   There is a function strtohex in their dll that converts a decimal to hexadecimal
   Their routines are called as follows in vb6.0:
   dim s(2) as type
   dim str as string
   str="111111"'It is actually a time
   call strtohex(str,s(0),2)
   After calling this function
   s(0)=17
   s(1)=17
   s(2)=17 is to take the two digits of the string into hexadecimal
  And call this function in vb.net
   The result of execution is indeed
   s(0)=0
   s(1)=0
   s(2)=0
I didn't do any operation at all~ I would like to ask everyone, what is the difference between the arrays in vb6.0 and vb.net! How can there be such a result!
Reply

Use magic Report

1

Threads

7

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-11-30 23:00:01
| Show all posts
The function has three parameters, the second one is passed byref by reference
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-12-1 13:00:02
| Show all posts
I have only studied vb.net for two months, and what I said may not be correct. What I read in the book says that most of the arrays in vb.net are passed by address. If you use byref, you can change the position of the array in memory. What you said, I think it may be that the dll file changed the position of the array in the memory, and vb.net automatically set 0 or empty characters or nothing for the uninitialized variables.
Reply

Use magic Report

0

Threads

9

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-12-1 15:30:01
| Show all posts
The declaration of strtohex function is posted
Reply

Use magic Report

1

Threads

7

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-12-1 17:15:01
| Show all posts
public declare function strtohex lib "rfd.dll" alias strtothex(byval temp as object,byref commdhandle as object,wrlen as short)
This is the declaration, the effect of the function can be achieved in vb6.0, but there is a problem when converting to the function of vb.net!
Reply

Use magic Report

0

Threads

9

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-12-1 17:30:01
| Show all posts
What statement did you give? Is it your own statement that you converted to .net?
Declare for vb6 or C++
Reply

Use magic Report

1

Threads

7

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-12-1 17:45:01
| Show all posts
Public Declare Function strtohex Lib "rfdll.dll" (ByRef source As Any, ByRef target As Any, ByVal wrlen As Long) As Long


Public Declare Function wrkey_t5557 Lib "hotel1.dll" (ByVal commhandle As Long, ByRef keyinfo As Any) As Long


Public Type KeyStruc
    cardtype As Byte
    HotelID(2) As Byte 'Hotel code
    AreaID As Byte'Area number
    FloorID As Byte 'Floor number
    roomid As Byte 'room number
    CardID As Byte 'Card serial number
    OffOn As Byte '"Terminate the recovery flag
    SDate(4) As Byte '"Start date
    EDate(4) As Byte '"End date
    STime(1) As Byte '"Service start time
    ETime(1) As Byte '"Service termination time
    FloorCot As Byte'Continue the number of floors
End Type
KeyStruc is a custom mechanism, the above is done in vb. The parameter of the above function is a member of this structure, which is the cardtype.
  as follows:
   dim cinfo as keystruc
   with keystruc
       .cardtype=1
       .sdate(0)=&H18
    ...............
   endwith
   dim strtmp as string ="0701110805"
   'Execute strtohex
   call strtohex(strtmp,cinfo.sdate(0),5)
   After executing the last sentence
   Cinfo.sdate member values ​​are as follows
   cinfo.sdate(0)=&H07
   cinfo.sdate(1)=&H01
   cinfo.sdate(2)=&H11
   By analogy, the first element of the cinfo.sdate array is passed to strtohex to get the above result.
   vb6.0 can be implemented correctly.
However, the above results cannot be achieved in .net, but each array member of cinfo.sdate is 0
   
   strtohex(
Reply

Use magic Report

1

Threads

7

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-12-1 18:00:01
| Show all posts
Experts come and have a look, I just don't understand how they pass it, it is estimated that there is still a problem in parameter passing!
Reply

Use magic Report

1

Threads

7

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-12-1 18:15:01
| Show all posts
Many parameter transfers in vb6.0 and vb.net have been changed!
Reply

Use magic Report

0

Threads

9

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-12-1 18:30:01
| Show all posts
Public Declare Function strtohex Lib "rfdll.dll" (ByVal source As String, ByRef target As Byte, ByVal wrlen As Integer) As Integer
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