The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Translate DLL function into VB (again)

Thank you for all the input in the thread below. I have succesfully translated most functions. It is not difficult, especially for standard COM interface such as IPicture and IFont. You can use stdPicture and stdFont provided by the VB runtime.

On the other side, I have difficulty to translate the following function
get_property2(char* pszProperty)

This function returns the property value through pszProperty.

Both mapping
get_property2(ByRef pszProperty As String)
and
get_property2(ByVal pszPropert as String)

failed miserably.

This lead me to believe that I have to change the C function prototype to
get_property(char** ppszProperty)

Any ideas?
Slave_VB_Programmer
Wednesday, May 17, 2006
 
 
This one is correct:
get_property2(ByVal pszPropert as String)

What does the whole declaration look like?
Almost H. Anonymous Send private email
Wednesday, May 17, 2006
 
 
It's also important to note that strings in VB are Unicode (double-byte).  If your function expects an ASCII string then  it's not going to work right.
Almost H. Anonymous Send private email
Wednesday, May 17, 2006
 
 
Lookup in MSDN for "Hardcore VB".  I believe it's on the CD.  He's got a couple of routines that convert a VB String to a byte array, and back again.  I think you may need a true Byte Array to pass to that routine.
AllanL5
Wednesday, May 17, 2006
 
 
If you control the dll, it might be easier to change it there than to get a string into a byte array.
Almost H. Anonymous Send private email
Thursday, May 18, 2006
 
 
Nope, trivially easy to generate a byte array from a VB String:

Function BytesToStr(ab() As Byte) As String
  BytesToStr = StrConv(ab, vbUnicode)
End Function

Well, ok, the above does the reverse -- but use vbFromUnicode, and you can get the byte array back.  Look it up in MSDN.
AllanL5
Thursday, May 18, 2006
 
 
Thank you guys. I have figured out.

I need to declare the String parameter as ByVal, AND I must pass a fixed length string in VB.

I also discovered that the String passed (to and back) are ASCII string char* (in fact it is like a BSTR but the data part is char*). Not Unicode at all.
Slave_VB_Programmer
Thursday, May 18, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz