Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / COM / December 2004



Tip: Looking for answers? Try searching our database.

how to convert from char * to string.help needed

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sree - 29 Dec 2004 10:17 GMT
hi all,

  i am trying to use a vc++ dll i made in vb. i am not much familiar to
vb.i just want to check if my dll will work in vb also. the function from dll
returns char *.i decalare a string in vb 'Dim str As String ' and try to get
the returned value in str. str=func()
. but when i print it ;here i use MsgBox(str) i am getting only junk value.
So guys anybody knows how to solve this problem.any method to convert char *
to string? or a method to convert StrPtr(str) to string will also be fine.

                                  Thanks and regards,sree
alpine - 29 Dec 2004 16:42 GMT
>hi all,
>
[quoted text clipped - 7 lines]
>
>                                   Thanks and regards,sree

You may find these useful (don't remember who wrote them.  Brad
Martinez, maybe?)

 Public Declare Function lstrlenA Lib "kernel32" (ByVal lpString As
Long) As Long
 Public Declare Function lstrlenW Lib "kernel32" (ByVal lpString As
Long) As Long
 Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory"
(lpDest As Any, lpSource As Any, ByVal cBytes&)

Public Function PointerToStringA(ByVal lpStringA As Long) As String
  Dim Buffer() As Byte
  Dim nLen As Long
 
  If lpStringA Then
     nLen = lstrlenA(ByVal lpStringA)
     If nLen Then
        ReDim Buffer(0 To (nLen - 1)) As Byte
        CopyMemory Buffer(0), ByVal lpStringA, nLen
        PointerToStringA = StrConv(Buffer, vbUnicode)
     End If
  End If
End Function

Public Function PointerToStringW(ByVal lpStringW As Long) As String
  Dim Buffer() As Byte
  Dim nLen As Long

  If lpStringW Then
     nLen = lstrlenW(lpStringW) * 2
     If nLen Then
        ReDim Buffer(0 To (nLen - 1)) As Byte
        CopyMemory Buffer(0), ByVal lpStringW, nLen
        PointerToStringW = Buffer
     End If
  End If
End Function

HTH,
Bryan
____________________________________________________________
New Vision Software                   "When the going gets weird,"
Bryan Stafford                     "the weird turn pro."
alpine_don'tsendspam@mvps.org     Hunter S. Thompson -  
Microsoft MVP-Visual Basic     Fear and Loathing in LasVegas
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.