PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
In Visual Basic program, the issues of Activex EXE data sharing-VBForums
Results 1 to 10 of 10

Thread: In Visual Basic program, the issues of Activex EXE data sharing

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2009
    Posts
    8

    Unhappy In Visual Basic program, the issues of Activex EXE data sharing

    I am in the main process using Activex EXE to create a sub-process, Activex EXE project inside a class module, class module which there are two instances of the event the equivalent of two threads, I defined the standard module module1.bas as public variable a, in two instances running at the same time, how the definition of public variables are not used, such as a private variable, each carrying out their respective variables of the same name! For example the implementation of a = a +1 statement, let the first instance of a run, a steady increase from 1; when executed when an instance of 2, a should be an instance of a value when the two began to increase, but also from two examples of 1,2 , ... began to increase.

    I hope that two instances can be ever-changing variable values, and normal global variables, hope to give suggestions and good methods! Grateful!
    (the time is a bit anxious, i hope to help, very grateful!!)
    Attached Files Attached Files
    Last edited by fhwsmith; Nov 12th, 2009 at 09:29 PM. Reason: upload test_program

  2. #2

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2009
    Posts
    8

    Re: In Visual Basic program, the issues of Activex EXE data sharing

    can you leave your e_mail,I contact with you and send my testing program to you!thanks a lot !

  4. #4
    Hyperactive Member
    Join Date
    Sep 2009
    Location
    Lost in thought
    Posts
    349

    Re: In Visual Basic program, the issues of Activex EXE data sharing

    Quote Originally Posted by fhwsmith View Post
    can you leave your e_mail,I contact with you and send my testing program to you!thanks a lot !
    If you zip it and upload it we can help.
    have a look at your SAMPLES.

    C:\Program Files\Microsoft Visual Studio\MSDN98\98VSa\1033\SAMPLES\VB98
    .

    The answer to your question is Here
    And here
    C:\Program Files\Microsoft Visual Studio\MSDN98\98VSa\1033\SAMPLES\VB98

    Please go to the "Thread Tools" menu at the top of this Thread, and click "Mark Thread Resolved" when you have your answer.
    So I can fine the answer when I need it.

    how to stop the playsound when it is in loop..Play more than 1 sound at a time..
    ini file Check if IP changed Strings 'Split', 'Left' and 'Right'
    Save And Load an Array of list-boxes, to and from a file......list-box and CommonDialog
    Quote Originally Posted by RobDog888

    So please install VB6 service pack 6 as its the latest and last supported service pack MS will ever make.
    http://support.microsoft.com/kb/q198880/ I'm sure this will fix your issue
    The only reason some people get lost in thought is because it’s unfamiliar territory. —Paul Fix

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2009
    Posts
    8

    Re: In Visual Basic program, the issues of Activex EXE data sharing

    thanks a lot ! i have uploaded the testing program! wish you help me !
    Last edited by fhwsmith; Nov 12th, 2009 at 09:33 PM.

  6. #6
    Hyperactive Member
    Join Date
    Sep 2009
    Location
    Lost in thought
    Posts
    349

    Re: In Visual Basic program, the issues of Activex EXE data sharing

    Quote Originally Posted by fhwsmith View Post
    thanks a lot ! i have uploaded the testing program! wish you help me !
    fhwsmith,
    It's better if you upload a .zip, some Members don't like .rar, so thay don't look.

    RhinoBull, I did have a look, it's a bit beyond me.

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,677

    Re: In Visual Basic program, the issues of Activex EXE data sharing

    fhw - If I read through it correctly.... the answer is that it doesn't work like that. Each instance of the application is going to load its variables into it's own place in memory. Think about it... it makes sense to keep them apart. Imagine, if you will that you open two DIFFERENT Word documents. If the two instances of Word uses the same memory mapping, then as soon as you make a change in one, it would overwrite your other document! That clearly wouldn't be good.


    @everyone else - what the OP wanted to happen is that when the first instance ran, it would do a= a + 1 .... since a starts at 0, it would get set to 1. Fair enough. But then when he runs a SECOND instance of the app, he's expecting a to already be set to 1 (from the FIRST instance) ... and so would then increment the variable to 2. But it doesn't work that way for reasons I explained above. At least not easily.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913

    Re: In Visual Basic program, the issues of Activex EXE data sharing

    Ok I am going to try to explain this as best I can. It is from some code I wrote many years ago and I haven't used VB6 in a long time. But here it goes:

    Firt off you will need to keep those variable you want to share in its own class. Now in that class you will need the following code

    vb Code:
    1. Option Explicit
    2.  
    3. Private Type GUIDs
    4.     Data1 As Long
    5.     Data2 As Integer
    6.     Data3 As Integer
    7.     Data4(0 To 7) As Byte
    8. End Type
    9.  
    10. ' Declares needed to register object in the ROT
    11. Private Const ACTIVEOBJECT_STRONG = 0
    12. Private Const ACTIVEOBJECT_WEAK = 1
    13. Private Declare Function CLSIDFromProgID Lib "ole32.dll" (ByVal ProgID As Long, rclsid As GUIDs) As Long
    14. Private Declare Function CoDisconnectObject Lib "ole32.dll" (ByVal pUnk As IUnknown, pvReserved As Long) As Long
    15. Private Declare Function RegisterActiveObject Lib "oleaut32.dll" (ByVal pUnk As IUnknown, rclsid As GUIDs, ByVal dwFlags As Long, pdwRegister As Long) As Long
    16. Private Declare Function RevokeActiveObject Lib "oleaut32.dll" (ByVal dwRegister As Long, ByVal pvReserved As Long) As Long
    17.  
    18. Private OLEInstance As Long
    19.  
    20. Private Sub Class_Initialize()
    21. Dim typGUID As GUIDs
    22. Dim lp As Long
    23.  
    24. OLEInstance = 0
    25. ' This code is responsible for creating the entry in the rot
    26. lp = CLSIDFromProgID(StrPtr("VegaCOMM.clsSocket"), typGUID)
    27. If lp = 0 Then
    28.     lp = RegisterActiveObject(Me, typGUID, ACTIVEOBJECT_WEAK, OLEInstance)
    29. End If
    30.  
    31. End Sub
    32.  
    33.  
    34. Private Sub Class_Terminate()
    35. ' Once we are done with the main program, lets clean up the rot
    36. ' by removing the entry for our ActiveX Server
    37.  
    38. If OLEInstance <> 0 Then
    39.     RevokeActiveObject OLEInstance, 0
    40. End If
    41.  
    42. CoDisconnectObject Me, 0
    43.  
    44. End Sub

    Change VegaCOMM.clsSocket to your_app_name.class_name

    This will register the class to the ROT if it isnt already. If it is in the ROT the already existing class instance will be pulled from the ROT.

    Now when you createobject on 'your_app_name.class_name' you will be sharing that class instance between your two apps.

    vb Code:
    1. Set VSock = CreateObject("VegaCOMM.clsSocket")

    At least that is how I remember it working. It has been like 8 years since I did this.
    Last edited by Cander; Nov 13th, 2009 at 02:11 PM.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  9. #9

    Thread Starter
    New Member
    Join Date
    Nov 2009
    Posts
    8

    Re: In Visual Basic program, the issues of Activex EXE data sharing

    thanks for all my friends,Problem has been resolved!

  10. #10

    Thread Starter
    New Member
    Join Date
    Nov 2009
    Posts
    8

    Thumbs up Re: In Visual Basic program, the issues of Activex EXE data sharing

    Quote Originally Posted by Cander View Post
    Ok I am going to try to explain this as best I can. It is from some code I wrote many years ago and I haven't used VB6 in a long time. But here it goes:

    Firt off you will need to keep those variable you want to share in its own class. Now in that class you will need the following code

    vb Code:
    1. Option Explicit
    2.  
    3. Private Type GUIDs
    4.     Data1 As Long
    5.     Data2 As Integer
    6.     Data3 As Integer
    7.     Data4(0 To 7) As Byte
    8. End Type
    9.  
    10. ' Declares needed to register object in the ROT
    11. Private Const ACTIVEOBJECT_STRONG = 0
    12. Private Const ACTIVEOBJECT_WEAK = 1
    13. Private Declare Function CLSIDFromProgID Lib "ole32.dll" (ByVal ProgID As Long, rclsid As GUIDs) As Long
    14. Private Declare Function CoDisconnectObject Lib "ole32.dll" (ByVal pUnk As IUnknown, pvReserved As Long) As Long
    15. Private Declare Function RegisterActiveObject Lib "oleaut32.dll" (ByVal pUnk As IUnknown, rclsid As GUIDs, ByVal dwFlags As Long, pdwRegister As Long) As Long
    16. Private Declare Function RevokeActiveObject Lib "oleaut32.dll" (ByVal dwRegister As Long, ByVal pvReserved As Long) As Long
    17.  
    18. Private OLEInstance As Long
    19.  
    20. Private Sub Class_Initialize()
    21. Dim typGUID As GUIDs
    22. Dim lp As Long
    23.  
    24. OLEInstance = 0
    25. ' This code is responsible for creating the entry in the rot
    26. lp = CLSIDFromProgID(StrPtr("VegaCOMM.clsSocket"), typGUID)
    27. If lp = 0 Then
    28.     lp = RegisterActiveObject(Me, typGUID, ACTIVEOBJECT_WEAK, OLEInstance)
    29. End If
    30.  
    31. End Sub
    32.  
    33.  
    34. Private Sub Class_Terminate()
    35. ' Once we are done with the main program, lets clean up the rot
    36. ' by removing the entry for our ActiveX Server
    37.  
    38. If OLEInstance <> 0 Then
    39.     RevokeActiveObject OLEInstance, 0
    40. End If
    41.  
    42. CoDisconnectObject Me, 0
    43.  
    44. End Sub

    Change VegaCOMM.clsSocket to your_app_name.class_name

    This will register the class to the ROT if it isnt already. If it is in the ROT the already existing class instance will be pulled from the ROT.

    Now when you createobject on 'your_app_name.class_name' you will be sharing that class instance between your two apps.

    vb Code:
    1. Set VSock = CreateObject("VegaCOMM.clsSocket")

    At least that is how I remember it working. It has been like 8 years since I did this.
    thank you,my friend!I Learned a lot from you and solved the problem!

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width