Jump to content

VB ,DLL and what Between them

- - - - -

  • Please log in to reply
6 replies to this topic

#1
PogBender

PogBender

    Newbie

  • Members
  • Pip
  • 5 posts
i made vb coded DLL .
i made Two Programs
The first changes variable value in the DLL
The Second Read This variable
So:
Two programs that use one DLL.

it dont works

ty :P

#2
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Umm do you have some code we can look at, to try and find the error? Or the problem your getting?
~ Committed.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#3
PogBender

PogBender

    Newbie

  • Members
  • Pip
  • 5 posts
here is the simplest Code:


Imports System.IO

Public Class GetSetData

    Dim Num As Integer = 6

    Function GetD()

        Dim Ans As Integer

        Ans = Num

        Return Ans

    End Function

    Public Sub SetD(ByVal Num1 As Integer)

        Num = Num1

    End Sub

End Class


abd ther is one App that use the SetD
and other use the GetD

after i use the SetD and change the value of Num
when i call the GetD Function the number is still 6

ty :P

#4
PogBender

PogBender

    Newbie

  • Members
  • Pip
  • 5 posts
BUMP

#5
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200

PogBender said:

BUMP

From an outside perspective (it has been somewhat a decade since I had touched visual basic) it looks like you will need to use the property statement, and not the sub for a function:


Class Class1    ' Define a local variable to store the property value.
    Private propertyValue As String
    ' Define the property.
    Public Property prop1() As String
        Get
            ' The Get property procedure is called when the value
            ' of a property is retrieved.
            Return propertyValue
        End Get
        Set(ByVal value As String)
            ' The Set property procedure is called when the value 
            ' of a property is modified.  The value to be assigned
            ' is passed in the argument to Set.
            propertyValue = value
        End Set
    End Property
End Class

This can allow prop1() to return "propertyValue" and prop1("something") to set "propertyValue" (from what I gather)

Resource from: http://msdn.microsof...y/zzh9ha57.aspx

----

As a side note, you should decide on the scope of the variable created. "dim" may be public, when you wish for "private" (only available to the class)
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#6
LuthfiHakim

LuthfiHakim

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 765 posts
Without special treatment, no matter what programming language is, you will always get this problem. And this is actually by design. Any memory allocated by a dll will be done in the memory space allocated to the application that load the dll. So your dll variable for application #1 will be different with dll variable for application #1. Yes, each application get their own copy of dll variable.

One of the solution for your problem is by using memory mapped files. With this, each application can share the same variable. See example of how the memory mapping is done in this tutorial (see under Dynamic-Link Library). It was in Delphi, but I hope you can see how it's done, and to implement it in vb.

#7
PogBender

PogBender

    Newbie

  • Members
  • Pip
  • 5 posts
TY very much,both of you.
i'll try it.
:P




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users