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.
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
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
Re: transfer user-defined data types between apps
An AxExe is most simpler method. You could also avoid registration issues using the OBJREF moniker and a SxS manifest in Standard EXE project.
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.
Re: transfer user-defined data types between apps
Quote:
Originally Posted by
The trick
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"?
1 Attachment(s)
Re: transfer user-defined data types between apps
Quote:
Originally Posted by
Arnoutdv
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.
Re: transfer user-defined data types between apps
Quote:
Originally Posted by
Arnoutdv
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>
1 Attachment(s)
Re: transfer user-defined data types between apps
Thank you for your tips.
Quote:
Originally Posted by
dz32
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).