how to call a dll

J

Jimmy

Hey

In VS i did apply my Dll under references, but no matter what i do, it seems
like i cant get this thing to work, if i put some UI in my Dll file. I get a
MissingMethodException. I have in the following kode marked the line that
throws the exception.

I call the function in my Dll the following way, even though i have tried
more different ways, but the same thing happens no matter how i do it:

try
{
Upd_Comp upd = new Upd_Comp(this);
}
catch (MissingMethodException g)
{
MessageBox.Show(g.Message.ToString());
}

My Dll consists of 2 .cs files looking like the following:

using System;
using System.Threading;
using System.Diagnostics;
namespace kompDll
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class Upd_Comp
{
public Upd_Comp(System.Windows.Forms.Form mainform)
{
//
// TODO: Add constructor logic here
//
test();
}

private void test()
{
frm_Statusdll frm_Stat = new frm_Statusdll();
frm_Stat.Show();
}
}
}

and the other file looks like this:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace kompDll
{
/// <summary>
/// Summary description for status.
/// </summary>
public class frm_Statusdll : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public frm_Statusdll()
{
//
// Required for Windows Form Designer support
//
InitializeComponent(); //AS SOON AS I PRESS STEP INTO ON THIS
LINE IN THE DEBUGGER, IT THROWS THE MISSINGMETHODEXCEPTION.
//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(56, 72);
this.label1.Name = "label1";
this.label1.TabIndex = 0;
this.label1.Text = "label1";
//
// label2
//
this.label2.Location = new System.Drawing.Point(56, 120);
this.label2.Name = "label2";
this.label2.TabIndex = 1;
this.label2.Text = "label2";
//
// frm_Statusdll
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "frm_Statusdll";
this.Text = "statusdll";
this.ResumeLayout(false);
}
#endregion
}
}

The point of all this is that i have to use the same code from more
different places, so instead of writing this a 100 times, i want it to be in
some kind of component that i can call.

Hope that you can help.
 
S

Steven Licciardi

Did you copy the dll to the same folder as the executable file on the PDA?

Steven
 
J

Jimmy

Steven Licciardi said:
Did you copy the dll to the same folder as the executable file on the PDA?

Yes. Im running the program in the emulator, and it copies the file itself
when its added as a reference, as far as i can see. (actually i just found
out, hehe...). Im not sure that theres something that i might misunderstand
here.

Anyway, i looked in the folder on the emulator PDA and the file is there
together with the executable file and the dll for the .Net CF. All file are
with the correct date, so i think its the right files. The icon is like when
it doesnt recognize the file, but so are the icon for .Net CF file, and that
file seems to work without any problems (OpenNetCF.Dll).

Any other suggesstions i very welcome :)

Thanks for your help so far :)


Jimmy
 
J

Jimmy

This might be it.

Ive created the main application as a Visual C# Projects -> Smart Device
Application. And it runs ok as long as i dont call my .Dll.

Ive created my .Dll file as a Visual C# projects -> Class Library. It seems
to work if i dont use any UI (just returned an integer). But as soon as i
use UI it gives me the exception. I think i might created this project
wrongly.

How can i check how its compiled?
What should i do for this Dll to be compiled against the compact framework?

Thanks for your help so far :)

--


Jimmy
 
P

Peter Foot [MVP]

To create a dll project for Compact Framework select Visual C# Projects >
Smart Device Application, then on the following "wizard" form you can pick
the project type - Class Library, this is perhaps a bit confusing since the
name "Smart Device Application" implies an application rather than a code
library, but this option contains all the Smart Device project types -
Windows Application, Class Library, Console Application etc.

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com

Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
 
J

Jimmy

Man. I had this problem before my holidays, and i sat with it for several
days. It was driving me nuts. Just started working again this monday, and i
have tried 10.000 different things (maybe im exaggerating a little), but you
gave me the answer.

Thanks, youll definitely be in my prayers tonight! :)

--


Jimmy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top