Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Common Variables in Main, Dlls, and Functions in .cs

Common Variables in Main, Dlls, and Functions in .cs

Scheduled Pinned Locked Moved C#
helpcsharpcomtutorialquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zequion
    wrote on last edited by
    #1

    I have many functions that employ some global variables that are common to all such functions, such as the language variable, to display error messages in the proper language. I want to make various compiled dlls which in turn employs those functions. If those variables are in a global structure, when I create a main that uses the dll, in the main i have to define that structure or include the same .cs and, in that way, there are two different copies of that structure with the same name. That produces the error CS0433. I can define a structure in the dll and in the Main I can use it, making a copy of the Main variables to the dll structure. But then if on the Main changes one of the variables, The dll does not have the updated value, I have to do it with every dll I use. Now you think the problem is bigger if there is more than one dll. That is impractical. I continue with the problem not solved and raised in: Https://www.codeproject.com/Forums/1649/Csharp.aspx?fid=1649&df=90&mpp=25&sort=Position&spc=Relaxed&view=Normal&fr=51#xx0xx Can anyone make a practical example? Thank you.

    L 1 Reply Last reply
    0
    • Z zequion

      I have many functions that employ some global variables that are common to all such functions, such as the language variable, to display error messages in the proper language. I want to make various compiled dlls which in turn employs those functions. If those variables are in a global structure, when I create a main that uses the dll, in the main i have to define that structure or include the same .cs and, in that way, there are two different copies of that structure with the same name. That produces the error CS0433. I can define a structure in the dll and in the Main I can use it, making a copy of the Main variables to the dll structure. But then if on the Main changes one of the variables, The dll does not have the updated value, I have to do it with every dll I use. Now you think the problem is bigger if there is more than one dll. That is impractical. I continue with the problem not solved and raised in: Https://www.codeproject.com/Forums/1649/Csharp.aspx?fid=1649&df=90&mpp=25&sort=Position&spc=Relaxed&view=Normal&fr=51#xx0xx Can anyone make a practical example? Thank you.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Regequion wrote:

      Can anyone make a practical example

      Most unlikely since what you are trying to do does not make sense. As I told you before in your original question, you need to rethink your design. If a DLL requires special parameters supplied by the main program then you need to add a method to the DLL to receive those parameters and use them to produce whatever customised results are required. There is no reason why you should ever require two versions of the same source module or structure to make this work.

      Z 1 Reply Last reply
      0
      • L Lost User

        Regequion wrote:

        Can anyone make a practical example

        Most unlikely since what you are trying to do does not make sense. As I told you before in your original question, you need to rethink your design. If a DLL requires special parameters supplied by the main program then you need to add a method to the DLL to receive those parameters and use them to produce whatever customised results are required. There is no reason why you should ever require two versions of the same source module or structure to make this work.

        Z Offline
        Z Offline
        zequion
        wrote on last edited by
        #3

        I'm already rethinking my design, what I do not know is how to do it. This matter is not well finished technically. Focusing and exposing this topic is difficult. 1.- I have some functions in .cs files that I use in both Main and functions .cs and DLLs. These functions use a structure with some variables of general use. In order to compile those functions for the Main or if I want to create a dll, the structure must exist for functions such as in a .cs file. Imagine that in the cs the structure is called Name_Common.Cls_Common.StCommon 2.- When using Main, I need to add the definition of that structure of the same .cs That already produces the mentioned error of ambiguity. But if I want with an alias to refer to the structure of the dlls, I have to enter the variables every time from Main in each structure of each dll, being in Main with alias: using Name_Common_Main = Dll.Name_Common for the first dll. But, and for the second dll? I can not add another using or if? And those variables, when they are not global, when they change their value will not be updated. I'm stuck, mentally and by software. How do people do?

        L 1 Reply Last reply
        0
        • Z zequion

          I'm already rethinking my design, what I do not know is how to do it. This matter is not well finished technically. Focusing and exposing this topic is difficult. 1.- I have some functions in .cs files that I use in both Main and functions .cs and DLLs. These functions use a structure with some variables of general use. In order to compile those functions for the Main or if I want to create a dll, the structure must exist for functions such as in a .cs file. Imagine that in the cs the structure is called Name_Common.Cls_Common.StCommon 2.- When using Main, I need to add the definition of that structure of the same .cs That already produces the mentioned error of ambiguity. But if I want with an alias to refer to the structure of the dlls, I have to enter the variables every time from Main in each structure of each dll, being in Main with alias: using Name_Common_Main = Dll.Name_Common for the first dll. But, and for the second dll? I can not add another using or if? And those variables, when they are not global, when they change their value will not be updated. I'm stuck, mentally and by software. How do people do?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          One of the first questions you need to ask is whether you actually need a DLL in the first place. Will this DLL be used by other applications, or is it specific only to this one? If the latter, then you probably do not need to separate out the methods it provides. As to the rest, I still cannot quite grasp what it is that you are trying to achieve. Using a structure to pass data between classes or methods does not need to be over complicated. It is just a matter of providing all the right information in the right place at the right time. As to variables changing during the lifecycle of an application, this can easily be captured by the use of events and delegates.

          Z 1 Reply Last reply
          0
          • L Lost User

            One of the first questions you need to ask is whether you actually need a DLL in the first place. Will this DLL be used by other applications, or is it specific only to this one? If the latter, then you probably do not need to separate out the methods it provides. As to the rest, I still cannot quite grasp what it is that you are trying to achieve. Using a structure to pass data between classes or methods does not need to be over complicated. It is just a matter of providing all the right information in the right place at the right time. As to variables changing during the lifecycle of an application, this can easily be captured by the use of events and delegates.

            Z Offline
            Z Offline
            zequion
            wrote on last edited by
            #5

            Aha, I'll take note. Point number 1, what do I need it for... Already, written !! Item Number 2, it is a question of being at the right time and in the right place to do what is right... It's already written !! It's what I needed!! thank you very much !!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups