Using API functions in Windows Forms (C++)

yelp666

Member
Joined
May 29, 2004
Messages
5
Hi all,

When I try to use API functions in Windows Form all I get are compilation errors. MSDN doesnt help at all in this case. Here is my code:
(I test it with very simple one Rectangle since I want to do some 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 in MSDN some info how to do it, but it simply didnt compile. Also by MSDN there is no DllImport, only DllImportAtributes. Anyway, above section compiles, and here is my usage in Picture Box (all very basic and simple ):

Graphics * m = e->Graphics;
APIFunctionality::Rectangle(hdc, 30, 100, 100, 100);
m->ReleaseHdc(hdc);

This also compiles, but doesnt work at all :).
Does anyone know how to do this in C++ or has any idea where I can find good info about it? Appreciate it.
 
Just how exactly did you add this file ( function) into a project. When I add this is to an existing Forms file (and appropriate headers) all hell breaks loose, because compiler complains about such things in Windows.h as: CALLBACK, HANDLEs, and so on. And when I add it to a new header file for new.h i add these headers:

#pragma once
#include <windows.h>

here the function

The problem begins when I try to add this new.h file to an existing forms .h file, by:

#include "new.h"

then I receive some wierd compilation errors, such as
GetObjectA is not a member of "System::Resources::ResourceManager"

and when I comment these line out I get linker error related to my function in
new.h

Any ideas why is it so??
 
Back
Top