Hi all,
When I try to use API functions in Windows Form all I get ar
compilation errors. MSDN doesn't help at all in this case. Here is m
code:
(I test it with very simple one Rectangle since I want to do som
drawing)
public __gc class APIFunctionality
{
public:
[System::Runtime::InteropServices:DllImport("GDI32.dll")]
static bool Rectangle(IntPtr hdc, int t, int l , int r, int b);
};
This is the only form of the code that actually compiles . I found i
MSDN some info how to do it, but it simply didn't compile. Also by MSD
there is no DllImport, only DllImportAtributes. Anyway, above sectio
compiles, and here is my usage in Picture Box (all very basic an
simple ):
Graphics * m = e->Graphics;
APIFunctionality::Rectangle(hdc, 30, 100, 100, 100);
m->ReleaseHdc(hdc);
This also compiles, but doesn't work at all .
Does anyone know how to do this in C++ or has any idea where I can fin
good info about it? Appreciate it
Jesse McGrew - 29 May 2004 23:41 GMT
> Hi all,
>
[quoted text clipped - 14 lines]
> This is the only form of the code that actually compiles . I found in
> MSDN some info how to do it, but it simply didn't compile.
What code were you using, and what error messages did you get? You
*should* be able to use API functions simply by #including the correct
headers, and possibly adding the import library to your project's linker
settings.
> Also by MSDN
> there is no DllImport, only DllImportAtributes.
[DllImport] is a shortcut for [DllImportAttribute], just like
Serializable vs. SerializableAttribute, etc.
Jesse
yelp666 - 30 May 2004 15:56 GMT
OK, I managed to get past the begining part, in that I can Cal
functions such as BitBlt, but this error confuses me with thi
declaration:
[System::Runtime::InteropServices::DllImport("User32.dll")]
extern IntPtr GetDesktopWindow();
Error:
A function that has a DllImport Custom Attribute cannot return a
instance of a class.
What does this mean?
Jesse McGrew - 30 May 2004 23:55 GMT
> OK, I managed to get past the begining part, in that I can Call
> functions such as BitBlt, but this error confuses me with this
[quoted text clipped - 9 lines]
>
> What does this mean??
Apparently, you can only use DllImport with functions that return void
or a primitive type. I would declare GetDesktopWindow to return an int,
instead of an IntPtr.
But you don't need to use DllImport at all. You can just #include
<windows.h> and then call GetDesktopWindow(), and it'll return an HWND.
If you get any errors doing that, it would help if you can post exactly
what they are.
Jesse
Jochen Kalmbach - 30 May 2004 17:54 GMT
> [System::Runtime::InteropServices:DllImport("GDI32.dll")]
> static bool Rectangle(IntPtr hdc, int t, int l , int r, int b);
Why are you using so complicated stuff (DllImport) in managed C++ !?
You can simply call the method...
Why not just
<code>
#include <windows.h>
::Rectangle(...)
</code>

Signature
Greetings
Jochen
Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp
Do you need daily reports from your server?
http://sourceforge.net/projects/srvreport/