Results 1 to 19 of 19

Thread: Send DLL args

  1. #1

    Thread Starter
    Hyperactive Member Always_Confused's Avatar
    Join Date
    Jun 2006
    Location
    Alabama USA
    Posts
    417

    Send DLL args

    I am trying something new today.

    What I am wanting to do is pass some information from my app to a new DLL project I have created.

    In the DLL I have 2 test forms (frm123, frm456). What I need to do is send 2 parameters over to the DLL, when the DLL recieves the info it would then determine which form to open.

    In the DLL I have in the Main Module ' I will use arg(0) later
    Code:
    Module PSAModMain
        Function Main(ByVal Args() As String) As Integer
            Dim ClientNum As String
            Dim Version As String
    
            ClientNum = Args(0).Trim
            Version = Args(1).Trim
    
            Dim frm As New Form
            frm.Name = "frm" & Version
            frm.Show()
    
        End Function
    
    End Module
    I am wanting to take the second arg and assemble it into the form name then open the form. I think this will work.

    But, on the app side on a button click sub I do not know how to reference it.

    My DLL is called PSA100.dll

    I can load the individual forms e.g
    Code:
    Dim myPSAform As New PSA100.frm123
            myPSAform.Show()
    But that does not help passing args so that the dll can decide which form to load.
    If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.

    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison

    Do illiterate people get the full effect of Alphabet Soup?

    ADO FAQ 2005-2008 Masked Textbox Patch FoxPro Date MZ Tools Great Free Tool

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Send DLL args

    If the values you want to pass to frm123 are MANDATORY values that need to be passed in order for the form to operate correctly, then I would add a constructor and pass the values there.

    So in frm123, you would put

    Code:
    Private _Value1 as string
    Private _Value2 as string
    Public Sub New(Value1 as string, Value2 as string)
        _Value1 = Value1
        _Value2 = Value2
    End Sub
    then when you create an instance of the form, you would do so like this:

    Code:
    Dim myForm as new PSA100.frm123("Hello", "World")
    so _value1 would equal "Hello", and _Value2 would equal "World" for that instance of frm123.

  3. #3

    Thread Starter
    Hyperactive Member Always_Confused's Avatar
    Join Date
    Jun 2006
    Location
    Alabama USA
    Posts
    417

    Re: Send DLL args

    I do not want to pass values to frm123. I want to pass values to the DLL module so that the DLL can determine which form to open.

    Code:
    Function Main(ByVal Args() As String) As Integer
            Dim ClientNum As String
            Dim Version As String
    
            ClientNum = Args(0).Trim
            Version = Args(1).Trim ' 123 or 456 or something
    
            Dim frm As New Form
            frm.Name = "frm" & Version
            frm.Show()
    
        End Function
    If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.

    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison

    Do illiterate people get the full effect of Alphabet Soup?

    ADO FAQ 2005-2008 Masked Textbox Patch FoxPro Date MZ Tools Great Free Tool

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Send DLL args

    Ok, I see what you are trying to do. The problem is you are just declaring your form as the base "Form" datatype, and not actually making it a form of a specific type.

    Just giving the form the name of what form you want it to be does not change the fact that you are doing

    Code:
    Dim frm As New Form
    and not
    Code:
    Dim frm As New frm123
    How many forms will this DLL contain? Unless it is some huge about, or subject to change frequently, I would think the easiest way to go about it would be a select case in the entry point of your DLL to look at the param passed, and create a strongly typed instance of whatever form needs to be created, based on the param.

  5. #5

    Thread Starter
    Hyperactive Member Always_Confused's Avatar
    Join Date
    Jun 2006
    Location
    Alabama USA
    Posts
    417

    Re: Send DLL args

    perhaps several. All a different version based on the version the client answered the survey.

    It will reference the DB to get that so I want to concatenate frm and the version for the form name and load the form.

    I want to pass the version to the DLL and the DLL decide which needs to be loaded.
    If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.

    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison

    Do illiterate people get the full effect of Alphabet Soup?

    ADO FAQ 2005-2008 Masked Textbox Patch FoxPro Date MZ Tools Great Free Tool

  6. #6

    Thread Starter
    Hyperactive Member Always_Confused's Avatar
    Join Date
    Jun 2006
    Location
    Alabama USA
    Posts
    417

    Re: Send DLL args

    Is this possible? Anyone?
    If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.

    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison

    Do illiterate people get the full effect of Alphabet Soup?

    ADO FAQ 2005-2008 Masked Textbox Patch FoxPro Date MZ Tools Great Free Tool

  7. #7
    Addicted Member Smartacus's Avatar
    Join Date
    Oct 2009
    Location
    Deep South, USA
    Posts
    196

    Re: Send DLL args

    OK, so your app takes a survey that has different versions?

    So when you take the survey the version is saved to the DB for the Client. Then when you go back to view it you want to send the client number and version to the DLL. The DLL then sees the clientID and the version and loads the form that matches the version?
    ***************************************************
    Smartacus comes packaged "As Is With No Warranty"

    ************* Useful Links ******************
    FAQs: Index / Database Development / .NET CodeBank /
    Before Posting Here...MSDN

    MZTools (I love this tool when using VB6 - Free) /

  8. #8

    Thread Starter
    Hyperactive Member Always_Confused's Avatar
    Join Date
    Jun 2006
    Location
    Alabama USA
    Posts
    417

    Re: Send DLL args

    Yes! But I can not get the app to recognize the args. When I enter say PSA100. intellisense only shows the form names. How can I get it to see a function in the main module?
    If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.

    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison

    Do illiterate people get the full effect of Alphabet Soup?

    ADO FAQ 2005-2008 Masked Textbox Patch FoxPro Date MZ Tools Great Free Tool

  9. #9
    Addicted Member Smartacus's Avatar
    Join Date
    Oct 2009
    Location
    Deep South, USA
    Posts
    196

    Re: Send DLL args

    I will play around with ot and see if I can help. There are a lot of smart guys on here that most likely know how to get this done. It is an interesting idea that I would also like to learn and put in the knowledge coffer
    ***************************************************
    Smartacus comes packaged "As Is With No Warranty"

    ************* Useful Links ******************
    FAQs: Index / Database Development / .NET CodeBank /
    Before Posting Here...MSDN

    MZTools (I love this tool when using VB6 - Free) /

  10. #10
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Send DLL args

    Quote Originally Posted by Always_Confused View Post
    Yes! But I can not get the app to recognize the args. When I enter say PSA100. intellisense only shows the form names. How can I get it to see a function in the main module?
    Based on the code you posted above, the function "Main" has no access modifer, so its default is private. You can't see private members in a referenced assembly, they are internal only. Try making it public.

  11. #11

    Thread Starter
    Hyperactive Member Always_Confused's Avatar
    Join Date
    Jun 2006
    Location
    Alabama USA
    Posts
    417

    Re: Send DLL args

    I did that last night. No change.
    If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.

    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison

    Do illiterate people get the full effect of Alphabet Soup?

    ADO FAQ 2005-2008 Masked Textbox Patch FoxPro Date MZ Tools Great Free Tool

  12. #12
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Send DLL args

    where is that sub main defined? Is it in a module? what is the access modifier on that?

  13. #13

    Thread Starter
    Hyperactive Member Always_Confused's Avatar
    Join Date
    Jun 2006
    Location
    Alabama USA
    Posts
    417

    Re: Send DLL args

    yes, in the module.
    If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.

    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison

    Do illiterate people get the full effect of Alphabet Soup?

    ADO FAQ 2005-2008 Masked Textbox Patch FoxPro Date MZ Tools Great Free Tool

  14. #14
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Send DLL args

    what is the access modifier on the module?

  15. #15

    Thread Starter
    Hyperactive Member Always_Confused's Avatar
    Join Date
    Jun 2006
    Location
    Alabama USA
    Posts
    417

    Re: Send DLL args

    It is Public

    Code:
    Public Module PSAModMain
        Public Function Main(ByVal Args() As String) As Integer
            Dim ClientNum As String
            Dim Version As String
    
            ClientNum = Args(0).Trim
            Version = Args(1).Trim
    
            Dim frm As New Form
            frm.Name = "frm" & Version
            frm.Show()
    
        End Function
    
    End Module
    If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.

    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison

    Do illiterate people get the full effect of Alphabet Soup?

    ADO FAQ 2005-2008 Masked Textbox Patch FoxPro Date MZ Tools Great Free Tool

  16. #16
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Send DLL args

    Ok, just so we have things straight here you did the following:

    1) Created a standard application (either console or winforms exe)
    2) Added a second project which is a class library (dll)
    3) In the second project, you have a public module with a public Sub Main
    4) You added a reference to the class library DLL in your EXE project
    5) You can not access the Sub Main in the dll project via ClassLibraryName.Main()

    Doing those steps works fine for me.

  17. #17

    Thread Starter
    Hyperactive Member Always_Confused's Avatar
    Join Date
    Jun 2006
    Location
    Alabama USA
    Posts
    417

    Re: Send DLL args

    I had followed each step as you listed and had no reference.

    However, I deleted the reference from the EXE and deleted the DLL project and recreated.

    It works now. This may have been caused by a Properties setting.
    If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.

    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison

    Do illiterate people get the full effect of Alphabet Soup?

    ADO FAQ 2005-2008 Masked Textbox Patch FoxPro Date MZ Tools Great Free Tool

  18. #18

    Thread Starter
    Hyperactive Member Always_Confused's Avatar
    Join Date
    Jun 2006
    Location
    Alabama USA
    Posts
    417

    Re: Send DLL args

    OK, I now have a reference to the DLL from my EXE project.

    What I need to figure out now is concatenating a string into a form name so when I use the NEW it will recognize.

    Code:
    Public Module Module1
        Public Function Main(ByVal ClientNum As Integer, ByVal Version As String) As Integer
    
            Dim strFormName As String
            strFormName = "frm" & Version ' This would give the form a name like frm123
    
            Dim frm As New strFormName 'Type 'strFormName' not defined
            frm.ShowDialog()
    
        End Function
    If you find information helpful from any member, please take a second and rate their post. Its a nice gesture of your appreciation.

    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison

    Do illiterate people get the full effect of Alphabet Soup?

    ADO FAQ 2005-2008 Masked Textbox Patch FoxPro Date MZ Tools Great Free Tool

  19. #19
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Send DLL args

    The problem is you are trying to take something you expect to be strongly typed (your specific different form types) but dynamically create an instance of it and expect to be able to access all its properties and controls that are specific to the given forms you designed.

    Lets illustrate the point here:

    Create a new winforms project, and in addition to the "Form1" that gets created, add a frmTest1 and frmTest2.

    In the form1, add a button and a combobox. In the combobox enter the names of these 2 new forms (frmTest1, and frmTest2)

    In the button click code in form1, add this:

    Code:
            Dim myForm As Form = DirectCast(Activator.CreateInstance(Type.GetType("WindowsApplication1." & ComboBox1.Text)), Form)
            myForm.ShowDialog()
            myForm.Dispose()
    Then run it and you can see that selecting frmTest1 or frmTest2 from the combo, and clicking the button does create whatever instance you specified, and it is doing it entierly from a string variable specifing the type.

    The problem is, the given instance you are creating is being cast to type "form" and not the derived form type of frmTest1 or frmTest2. So while the instance actually is of frmTest1 or frmTest2, the code doesn't know that, because you dynamically created the form.

    So they way you would be able to access specific properties and controls on the dynamicaly created form, would be to cast it to its specific type. This however defeats the purpose of making the forms dynamic in the first place, because you would need a select case with all the form types in order to determine which form you created, so that you could take whatever action is needed for that given form. By that point you would just use a select case to strongly type the forms at creation time anyway.

    That isn't to say you can't do this at all. There are ways to mitigate it and make it work, it just depends on what exactly these forms need to do. For example, you could have an intermediate form class in your inheritence chain that has some common methods to all your dynamic forms, then it would be safe to cast to this intermediate type on any of your dynamic forms, and call methods on it.

    For example, lets say each of these dynamic forms has a "save" method which saves all the data the user enters. Obviously since each form is different, the save routine needs to be coded in each form to save data for that given form.

    So you could create a base form class that inherits from "Form" and have your dynamic forms inherit from this base class. The routines common to all forms can go in this base form class so that you can cast to it and call the shared routines. As long as you override them in the individual forms, those are the routines that will be called.

    Attached is an example project to show this in action
    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