Question Dll vs windows form

Nmjshaw

Member
Joined
Mar 31, 2014
Messages
6
Programming Experience
1-3
Hi

I am new here and fairly new to vb.net. I'm from a vba background and I am building addin tools for autodesk inventor. I have built my addins in visual studio 13 express and I'm experiencing a few problems.

Problem 1
When the addin is in windows form, it works great. When I change it to a class and build it, I get errors on ALL of my select case statements. Is there a difference?

Problem 2
I get an error to declare the form as an object. When I declare the object in a function, I don't get the error but I get a fail at the function.... What is the best way to declare the form as an object?

I will ask all other questions independently but these 2 are hot my list.


Any help greatly appreciated :)



Thanks

Nigel
 
Problem 1
When the addin is in windows form, it works great. When I change it to a class and build it, I get errors on ALL of my select case statements. Is there a difference?
A form is a class so, by definition, there is no difference. If there's something in your code that relies on it being in a form then obviously there will be issues if it's not in a form. We can only guess at what the issue might be from so little information. Show us the code, tell us where the error(s) occurs and exactly where in the code.
Problem 2
I get an error to declare the form as an object. When I declare the object in a function, I don't get the error but I get a fail at the function.... What is the best way to declare the form as an object?
That makes no sense at all I'm afraid. Please provide a FULL and CLEAR description of the problem. Explain what it is that you're trying to achieve. Explain how you're trying to achieve it, including relevant code. Explain what happens when you try, including error messages.
 
A form is a class so, by definition, there is no difference. If there's something in your code that relies on it being in a form then obviously there will be issues if it's not in a form. We can only guess at what the issue might be from so little information. Show us the code, tell us where the error(s) occurs and exactly where in the code.

That makes no sense at all I'm afraid. Please provide a FULL and CLEAR description of the problem. Explain what it is that you're trying to achieve. Explain how you're trying to achieve it, including relevant code. Explain what happens when you try, including error messages.

hi

thanks for the reply. I can post some code and screenshots tomorrow but in the meantime..

When my application is a windows form, it works great. When I change it to a class, all of the select case statements get a wavy line underneath. I also get errors on these codes only when it's a class. They do not error as a windows form


VB.NET:
Dim a As String = mainform.cboViewScale.Text

and also

VB.NET:
oDrawDoc = InvApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, sTemplateFile)

as as for problem 2, it works just fine as a windows form but when I change it to a class, I get an error telling me that the form object needs to be declared. I added this

VB.NET:
Public Function mainform() As Object
        Throw New NotImplementedException
    End Function


i get an error at

and the error goes away for the build but then errors on the 'Throw New NotImplementedException' line

its difficultvtovexplaon exactly what I'm trying to achieve. I have made a form with controls that interacts with autodesk inventor. It has buttons, text fields, a progress bar and it carries out drawing functions through the api. Like I said, the form and everything works perfectly as a windows form but fails as a dll. It's like windows forms functions don't work

thanks

nigel
 
A form is a class so, by definition, there is no difference. If there's something in your code that relies on it being in a form then obviously there will be issues if it's not in a form. We can only guess at what the issue might be from so little information. Show us the code, tell us where the error(s) occurs and exactly where in the code.

That makes no sense at all I'm afraid. Please provide a FULL and CLEAR description of the problem. Explain what it is that you're trying to achieve. Explain how you're trying to achieve it, including relevant code. Explain what happens when you try, including error messages.

Hi

im back on my PC today. here is the error code i get when i save run from DLL-

System.NotImplementedException: The method or operation is not implemented.
at MegaTools_V1.mod_ShawTools.mainform() in C:\Users\NigelShaw\Documents\Visual Studio 2013\Projects\MegaTools\MegaTools V1\MegaTools V1\mod_ShawTools.vb:line 18
at MegaTools_V1.mod_ShawTools.CreateViews(String sPath, String sAssembly) in C:\Users\NigelShaw\Documents\Visual Studio 2013\Projects\MegaTools\MegaTools V1\MegaTools V1\mod_ShawTools.vb:line 184
at MegaTools_V1.MainForm.Button2_Click(Object sender, EventArgs e) in C:\Users\NigelShaw\Documents\Visual Studio 2013\Projects\MegaTools\MegaTools V1\MegaTools V1\MainForm.vb:line 157
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

ok. line 18 is here
VB.NET:
Public Shared Function mainform() As Object[COLOR=#ff0000]        
Throw New NotImplementedException[/COLOR]
    End Function

line 184 is here
VB.NET:
[COLOR=#0000ff]Dim a As String = mainform.cboViewScale.Text[/COLOR]

line 157 is here
VB.NET:
[COLOR=#b22222]Call CreateViews(lstPartsList.Items(0).SubItems(1).Text, Me.lblAssemblyName.Text)[/COLOR]
the passing arguments example would be-
VB.NET:
Call CreateViews("C:MyPath/MyPartFile.ipt", "C:/MyPath/MyAssemblyFile.iam")

it seems that i get an error every time i reference something on my form which i guess leads back to line 18. Am i doing this right? if i comment out the Public shared function at line 17-19, i get this error as i build and the build fails
dll issue.JPG

Im hoping that if i can resolve the shared object error, it will fix the other reference errors i am getting :-/

as a final point. this line-
VB.NET:
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
is referencing a code that is completely commented out. Why would it do this?

When i build this project as a Windows Form, i dont get any errors. i ONLY get the errors when i build as a dll.



Hope you can help :)




thanks

Nigel
 
What you have posted is not the issue. It's another issue that you have created in an attempt to solve the actual issue. It should be fairly obvious that 'mainform' refers to the main form in an application. If there is no main form, or any form at all for that matter, then it should be fairly obvious that you can't refer to it. Writing a method named 'mainform' that does nothing but throw a NotImplementedException doesn't magically mean that you can refer to a main form that does exist. If you want to write code that doesn't use forms then write code that doesn't use forms. If you write code that refers to a ComboBox on a main form then obvious there has to be a main form and a ComboBox on it to refer to.

How about we go back to what I said in my very first reply: what EXACTLY are you actually trying to achieve? If you expect us to help you write code to achieve something then it would help if we knew what that something is. It seems that you're trying to write code that does something specific with a specific form so why are you trying to write without that form existing in the first place?
 
What you have posted is not the issue. It's another issue that you have created in an attempt to solve the actual issue. It should be fairly obvious that 'mainform' refers to the main form in an application. If there is no main form, or any form at all for that matter, then it should be fairly obvious that you can't refer to it. Writing a method named 'mainform' that does nothing but throw a NotImplementedException doesn't magically mean that you can refer to a main form that does exist. If you want to write code that doesn't use forms then write code that doesn't use forms. If you write code that refers to a ComboBox on a main form then obvious there has to be a main form and a ComboBox on it to refer to.

How about we go back to what I said in my very first reply: what EXACTLY are you actually trying to achieve? If you expect us to help you write code to achieve something then it would help if we knew what that something is. It seems that you're trying to write code that does something specific with a specific form so why are you trying to write without that form existing in the first place?

Hi

Thanks for the reply.

it is not another issue that i have created, this was my first issue. Like i said and keep saying, everything works perfectly as a windows form but doesnt work as a class. when i change from a windows form to a class, i get errors that i described above.

so, to start from scratch-

i have created a FORM that has objects as shown here
form.JPG
the form is displayed when called from the application 'Inventor'. (Inventor can ONLY call a DLL so the form and code needs to be inside the DLL). this was created when i highlighted the error provided by VS and selected the option to create the function

i am not trying to write without the form existing, i am trying to show the form.

FORM WORKING AS WINDOWS FORM
WORKING - YouTube


FORM NOT WORKING AS DLL (NOTE THE RED ERRORS)
FORM NOT WORKING - YouTube

In DLL format, i get lots of errors all mainly related to the form not being shared.

i hope this describes more :)



thanks for the help so far





Nigel
 
Back
Top