Help PLease

  • Thread starter Thread starter Dmension
  • Start date Start date
D

Dmension

Hello Folks,
Newbie here needs a little help.
Here is my issue.
I want to place all my dll import data into class called testdllimport.cs
Then I want to call, reference, or instantiate the class in my form1.cs!!
Is this possible.

Thanks in advance.
 
DLLImport statements are all static extern anyway so just go ahead and do
what you suggest.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Thanks for the reply Bob,
But my issue is, I dont know how to instantiate that class I created in
my form1.cs and where should I do this. If possible could you give me a
small piece of code to get me started. I already placed the dll imports in a
class.
 
you haven't to instatniate th class at all, since the methods are static.

class Inports
{
[DllImport("user32.dll", EntryPoint = ............]
public static extern int SomeImportedFunction(.........);
}

class MyClass
{
int MyMethod()
{
.....
int x = Imports.SomeImportFunction(.......);
.......
}
}

That's all.
 
Methods that are static do not require an instance of a class. Look at the
Math class for example. It's methods are all static and can be callled using
Math.Atan2(...) etc.

When you create your class as a placeholder for your interop imports you can
just invoke them using the name of the class followed by the method. For
example...

class MyNativeMethods
{
[DllImport(""user32.dll")]
public static extern IntPtr GetDC(intPtr hWnd);

}



// in your code....

IntPtr hDC=MyNativeMethods.GetDC(this.hWnd);

Hope this helps.


--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Back
Top