Results 1 to 9 of 9

Thread: transfer user-defined data types between apps

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2018
    Location
    Germany - Westerwald
    Posts
    22

    Question transfer user-defined data types between apps

    Hello folk,

    is it possible user-defined data types transfer direct between applications without write in a tmp-file?

    A short type example:
    Code:
    Type Artikel
      TeileNR as Long
      Beschreibung As String * 28
      Dichte As Double
      Laenge As Double
      Breite As Double
    End Type
    Type Material
      Lieferant As String * 20
      TypSorte As String * 20
      lLiefMat As Long
      KostenKg As Double
    End Type
    Public Type saaXF
      KopfDaten(0 To 4) As String * 20
      dDatum As Date
      lStand As Long
      Files(0 To 10) As Long
      Art As Artikel
      Mat As Material
      sComment As String * 312
    End Type
    Public saA As saaXF
    I know a little about SendMessage and DDE to transmit strings. But I don't want to transmit each string and value separately because the actual type is much more complex.

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,415

    Re: transfer user-defined data types between apps

    Are both Apps written in VB6?
    1) If yes, you could compile them as ActiveX-EXE's, and reference them to each other. That way you could use Public Objects and their methods
    1b) Write an ActiveX-Dll which is referenced by both apps, which is kind of "man in the middle". Usage as above
    2) You could use Winsock to transfer the UDT as a ByteStream
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  3. #3
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,053

    Re: transfer user-defined data types between apps

    Schmidt Posted a way to serialize udts directly in memory by writing the data to a pipe

    https://www.vbforums.com/showthread....izing-InMemory

    You could probably kill two birds with one stone and have the second process be the one who created and reads the pipe.

    I played with a similar idea hooking readfile/writefile api before someone pointed out his example to me:

    http://sandsprite.com/blogs/index.ph...ite=!serialize

    I would use the pipe sample. Try the remote pipe read or just do a manual data transfer:

    Wm copy data http://sandsprite.com/openSource.php?id=70
    Mem mapped files: http://sandsprite.com/openSource.php?id=87
    Shared memory: http://sandsprite.com/openSource.php?id=89
    Last edited by dz32; Jun 24th, 2022 at 05:19 AM.

  4. #4

  5. #5
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,852

    Re: transfer user-defined data types between apps

    You could also use Far Memory and write the UDT to Far Memory pretty much just like a file.

    Here's a post where I explored doing that with arrays. But search for OpenFileMapping in the CodeBank and there are other examples where people are using this approach to just write typical files to Far Memory. I know Dilettante and The Trick have done similar things.

    Also, a named pipe sounds like a pretty good way to me as well.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  6. #6
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,871

    Re: transfer user-defined data types between apps

    Quote Originally Posted by The trick View Post
    An AxExe is most simpler method. You could also avoid registration issues using the OBJREF moniker and a SxS manifest in Standard EXE project.
    Using an ActiveX Exe without registration? I thought this was not possible!
    Do you have a sample/article/reference for using "the OBJREF moniker"?

  7. #7
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,671

    Re: transfer user-defined data types between apps

    Quote Originally Posted by Arnoutdv View Post
    Using an ActiveX Exe without registration? I thought this was not possible!
    Do you have a sample/article/reference for using "the OBJREF moniker"?
    I meant Standard EXE, not ActiveX EXE. This is an example:

    UDT (inside an AxDll):
    Code:
    Public Type TUserType
        sStr    As String
        bData() As Byte
        cObj    As Object
    End Type
    App1:
    Code:
    Option Explicit
    
    Public Sub Callback( _
               ByRef t As TUserType)
        MsgBox TypeName(t.cObj) & " " & t.sStr
    End Sub
    
    Private Sub Form_Load()
        Dim cMnk    As IMoniker
        Dim cBind   As IBindCtx
        Dim pStrMnk As Long
        Dim sStrMnk As String
        
        Set cMnk = CreateObjrefMoniker(Me)
        Set cBind = CreateBindCtx()
        
        pStrMnk = cMnk.GetDisplayName(cBind, Nothing)
        sStrMnk = SysAllocString(pStrMnk)
        
        CoGetMalloc(1).Free pStrMnk
        
        ' // Create app
        
        Shell "app2.exe """ & sStrMnk & """", vbNormalFocus
        
    End Sub
    App2:
    Code:
    Option Explicit
    
    Private Declare Function PathUnquoteSpaces Lib "shlwapi" _
                             Alias "PathUnquoteSpacesW" ( _
                             ByVal p As Long) As Long
                             
    Private m_cServer   As Object
    
    Private Sub cmdCall_Click()
        Dim t As TUserType
        
        Set t.cObj = Me
        t.sStr = "Hello"
        t.bData = StrConv("12345", vbFromUnicode)
        
        m_cServer.Callback t
        
    End Sub
    
    Private Sub Form_Load()
        Dim pArg    As Long
        
        pArg = StrPtr(Command$)
        PathUnquoteSpaces pArg
        Set m_cServer = GetObject(SysAllocString(pArg))
        
    End Sub
    When we click cmdCall button in App2 it calls Callback method from App1 and passes UDT with the referenced types.
    Attached Files Attached Files

  8. #8
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: transfer user-defined data types between apps

    Quote Originally Posted by Arnoutdv View Post
    Using an ActiveX Exe without registration? I thought this was not possible!
    Do you have a sample/article/reference for using "the OBJREF moniker"?
    It says "Standard EXE project" pretending to be an ActiveX EXE by sharing instances through OBJREF monikers i.e. without registering class factories in registry and ROT like an Ax-EXE does.

    cheers,
    </wqw>

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Jan 2018
    Location
    Germany - Westerwald
    Posts
    22

    Re: transfer user-defined data types between apps

    Thank you for your tips.

    Quote Originally Posted by dz32 View Post
    Schmidt Posted a way to serialize udts directly in memory by writing the data to a pipe ...
    This idee is the answer to my question: https://www.vbforums.com/showthread....stom-data-type :-)

    For my problem here I want to use the idea of Zvoni with the dll as "man in the middle", but I can't quite figure out how to pass the complete dataset (udt) (see the very simplified example).
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width