June 26, 2024, 02:07:09 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Calling a Windows API imported function from within a class method

Started by Haim, May 19, 2006, 11:07:32 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Haim

This is probably a stupid questionÂÃ,  ÂÃ, ???
I am trying to call GetDeviceCaps from within an OnCreate method of a Cwindow derived class.
The call works well outside the class, but when I make it from within the class method I getÂÃ,  a "no appropriate conversion exists" error message.
Are there special rules for calling API functions (declared with "DECLARE IMPORT , ....")ÂÃ,  from within a class method?





Mike Stefanik

Did you declare a class member with that name? If you've declared GetDevceCaps, try calling it as ::GetDeviceCaps(n) and see if that makes a difference (i.e.: put two colons before the function name).
Mike Stefanik
www.catalyst.com
Catalyst Development Corporation

Haim

No...
using ::GetDeviceCaps creates the same error as before.

BTW, why should ::GetDeviceCaps work, as it is not declared within a class?
Can it be declared as a class method?

Mike Stefanik

You'd declare GetDeviceCaps as:


declare import,GetDeviceCaps(unsigned int hdc, int nIndex), int;


You should be able to call that anywhere in your code. Note that if you cut-and-pasted that declaration from somwhere where the first argument is "DWORD" then you need to make sure that DWORD is typedefed as an unsigned int, or you'll get that error (in other words, it's not a compiler or class scope issue, just a simple type problem in your code).

Scope resolution rules basically say that if it's called from within a class method, and you don't use the scope operator ( :: ) then it will check if that method is defined in the class; if it is, it will use the class method and if it's not, then it will look for an function (external to the class) with that name.
Mike Stefanik
www.catalyst.com
Catalyst Development Corporation

Haim

Thanks for the explanation!
I forgot that UINT needed to be typedef'd to be recognized.
Now that I added #typedef UINT unsigned int
Everything works just fine.

Thanks again,
Haim

Ionic Wind Support Team

In the next update I will add the common aliases to acommon.inc.  The compiler ignores duplicate typedefs if they resolve to the same type so it won't break anyones current code.  The ones I can think of right this second, being half asleep are:

UINT
DWORD
LONG
BOOL
CHAR

Paul.
Ionic Wind Support Team