473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

DllImport problem

Hi!

On a form I have a monthCalendar which display all months of year. Now,
as a training case here at school in C#, I'm trying to print the
calendar.

I've found, I think a good example how to print graphics, but it
doesn't work quite as I would expect.

Here's the code I found ("kalle" is the monthCalendar):

[DllImport("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
System.Int32 dwRop // raster operation code
);

private const Int32 SRCCOPY = 0xCC0020;

private Bitmap memImage;

private void PrepareImage()
{
Graphics graphic = kalle.CreateGraphics();
Size s = this.Size;
memImage = new Bitmap(s.Width, s.Height, graphic);
Graphics memGraphic = Graphics.FromImage(memImage);
IntPtr dc1 = graphic.GetHdc();
IntPtr dc2 = memGraphic.GetHdc();
BitBlt(dc2, 0, 0, kalle.ClientRectangle.Width,
kalle.ClientRectangle.Height, dc1, 0, 0, SRCCOPY);
graphic.ReleaseHdc(dc1);
memGraphic.ReleaseHdc(dc2);
}

However, at loading the form I get a debugwindow loading, saying:

"The type or namespace 'DllImport' could not be found"

What do I need to add in the header?

Me.Name
(Just took the MCP-cert. on SQL-Server 2000)

Jan 13 '06 #1
2 8569
gs***@hotmail.com wrote:
On a form I have a monthCalendar which display all months of year. Now,
as a training case here at school in C#, I'm trying to print the
calendar.

I've found, I think a good example how to print graphics, but it
doesn't work quite as I would expect.

Here's the code I found ("kalle" is the monthCalendar):

[DllImport("gdi32.dll")]
<snip>
However, at loading the form I get a debugwindow loading, saying:

"The type or namespace 'DllImport' could not be found"

What do I need to add in the header?


You need to add:

using System.Runtime.InteropServices;

to your class. I haven't looked at the rest of your code though.

Jon

Jan 13 '06 #2
Yes, thank you. Now it works like :-)
Jon Skeet [C# MVP] skrev:
gs***@hotmail.com wrote:
On a form I have a monthCalendar which display all months of year. Now,
as a training case here at school in C#, I'm trying to print the
calendar.

I've found, I think a good example how to print graphics, but it
doesn't work quite as I would expect.

Here's the code I found ("kalle" is the monthCalendar):

[DllImport("gdi32.dll")]


<snip>
However, at loading the form I get a debugwindow loading, saying:

"The type or namespace 'DllImport' could not be found"

What do I need to add in the header?


You need to add:

using System.Runtime.InteropServices;

to your class. I haven't looked at the rest of your code though.

Jon


Jan 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: caviar | last post by:
Hi, i'm having a problem with a native w32 dll. Everything is working fine except for one parameter which is defined as: --------------------------------------header file--- // short PASFIX...
15
by: Jim | last post by:
I am extremely frustrated. I am building c# application for a call center and am using a third party API to access some hardware. When develop and test my class using the windows console the...
2
by: Kurt Ng | last post by:
Hi, y'all. Can anyone help me on this problem? I'm working with a third-party C dll, and I'm having trouble importing into C# the dll's methods that return one of the dll's defined types,...
1
by: Whidbey Wave | last post by:
Hi , Of course sometimes, some of us have these weird DLLImport issues. I am using Net-snmp library from http://www.net-snmp.org. While creating a prototype as console application it worked fine,...
2
by: Brian Anderson | last post by:
Hello, is it possible to use DllImport to call a DLL in ASP.NET ? Or is it necessarry that my DLL has to be copied into \System32 ? My DLL is a native C++ 7.1 DLL (not managed, no COM, no...
1
by: Seth Gecko | last post by:
Hi I am developing a complex VB.Net Windows application for an engineering firm (don't ask me why they prefer VB.Net...). All the engineering calculations are done in FORTRAN which is compiled...
1
by: kardon33 | last post by:
Let me explain my problem, Im currently trying to use a Perl module that was built for a Windows OS that uses a .dll and .lib file. I have obtained the c header files that the modules were built...
1
by: JohnCox | last post by:
I have a simple Win32 DLL I wrote named "SimpleLib" that exports two functions. It is written in C++ and compiled with __stdcall (/Gz) and with the preprocessor definition _MBCS (not Unicode). ...
1
by: elke | last post by:
Hi, I want to use an unmanaged dll in C# .net and I'm having some troubles witch a function that should return an array. I'm new at this, so I don't know what I'm doing wrong. Here is some...
1
by: mrssuper | last post by:
Hey All, How do I declare a following types: char** unsigned char** in C# DllImport function?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.