VB6 to VB.NET Replacement for StrPtr and VarPtr

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jake Glines
    New Member
    • Mar 2011
    • 2

    #1

    VB6 to VB.NET Replacement for StrPtr and VarPtr

    I am trying to convert a method from VB6 to VB.NET and having some issues with StrPtr and VarPtr not being supported in VB.NET anymore. Here is the method having a problem. From what I know, I am looking to get the memory location of the objects to pass to the SendMessageCDS( ) method. Any ideas what I can do to fix it? I am a C# developer trying to work in VB and can use all the help I can get! Thanks in advance!

    The reason for me needing to do this is that I was given some OLD VB6 code to send/receive messages via DDE. I am trying to get my new C#.NET application to be able to talk with an application similar to this and am having problems. In trying to emulate this code in C#, I am finding a lot of gaps that I am trying to fill in. Any help is appreciated!

    Code:
    Public Structure COPYDATASTRUCT
    	Dim dwData As Integer
    	Dim cbData As Integer
    	Dim lpData As Integer
    End Structure
    
    Public Declare Function SendMessageCDS Lib "user32"  Alias "SendMessageA"(ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    
    Public Sub SendMsg(ByRef i_sMessage As String)
    	
    	On Error GoTo ErrorHandler
    	
    	Dim cds As COPYDATASTRUCT
    	Dim sMessage As String
    
    	cds.dwData = 0
    	cds.cbData = Len(i_sMessage)
    	sMessage = StrConv(i_sMessage, VbStrConv.None)
    	'UPGRADE_ISSUE: StrPtr function is not supported. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1040"'
    	cds.lpData = StrPtr(sMessage)
    	
    	'UPGRADE_ISSUE: VarPtr function is not supported. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1040"'
    	Call SendMessageCDS(m_lhWndGlue, WM_COPYDATA, m_lhWndMe, VarPtr(cds))
    	
    Exit Sub
    Last edited by Jake Glines; Mar 4 '11, 06:40 PM. Reason: Added reason for this post
  • Kalen Viljoen
    New Member
    • Feb 2011
    • 12

    #2
    Try access the api directly:

    Code:
    Private Declare Function VarPtrAny Lib "msvbvm60.dll" Alias "VarPtr" (lpObject As Any) As Long

    Comment

    • Jake Glines
      New Member
      • Mar 2011
      • 2

      #3
      Thanks for the quick response! I hate to look stupid with this, but what would you think the code would look like if I were to make this call directly?

      When I place that code in my project, I get this error:
      "'As Any' is not supported in 'Declare' statements"

      Comment

      Working...