473,806 Members | 2,929 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Questions about Declare with Windows API functions

I saw the following in an example

Public Overloads Declare Auto Function CreateDC Lib "gdi32" (ByV...As
Integer...

Public Overloads Declare Auto Function CreateDC Lib "gdi32" (ByV...As
String...

I know what Overloads means in relation to a function in the base class.

But does it make sense to use Overloads with a Windows API function?

=============== =============== =========

Second question.

If a Windows API function returns a BOOL I've Declared it as returning an
Integer and check for zero (as a FALSE return).

If I Declare the return a Boolean will FALSE be marshaled to False and TRUE
to True?

Will TRUE be marshaled to -1?



Thanks


Dec 29 '05 #1
4 1230
But does it make sense to use Overloads with a Windows API function?
Sometimes it does. There are plenty of functions where parameter types
can vary. But In the case of CreateDC, I don't see why any of the
parameters ever would be declared as Integer.

If a Windows API function returns a BOOL I've Declared it as returning an
Integer and check for zero (as a FALSE return).

If I Declare the return a Boolean will FALSE be marshaled to False and TRUE
to True?
Yes, so I'd recommend changing the return type to Boolean.

Will TRUE be marshaled to -1?


Not sure what you mean by that. The value of TRUE is 1 on the native
side.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Dec 29 '05 #2
" **Developer**" <RE************ *@a-znet.com> schrieb:
Public Overloads Declare Auto Function CreateDC Lib "gdi32" (ByV...As
Integer...

Public Overloads Declare Auto Function CreateDC Lib "gdi32" (ByV...As
String...

I know what Overloads means in relation to a function in the base class.
Overloads simply indicates that there is more than one "version" of a
function. In some cases it is mandatory, in some not (as in the sample
shown above).

BTW: I believe the sample above is nonsense because 'Auto' and the return
type 'String' are not valid for this function.
If a Windows API function returns a BOOL I've Declared it as returning an
Integer and check for zero (as a FALSE return).

If I Declare the return a Boolean will FALSE be marshaled to False and
TRUE to True?


Yes, simply use 'Boolean' as return type. The reason why people used 'Long'
as return type for these functions in VB6 was that 'Integer' in VB6 was a
16-bit data type.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 29 '05 #3
Errata + addendum:

'Auto' makes sense for the function. Sample function declaration:

\\\
Private Delcare Auto Function CreateDC Lib "user32.dll " ( _
ByVal lpszDriver As String, _
ByVal lpszDevice As String, _
ByVal lpszOutput As String, _
ByRef lpInitData As DEVMODE _
) As IntPtr
///

Sample Call:

\\\
Dim hDC As IntPtr = CreateDC(..., ..., vbNullString, ...)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Dec 29 '05 #4
Thanks again to Mattias and Herfried
VB would be a lot less fun without you
Dec 29 '05 #5

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

Similar topics

7
1427
by: David Brewster | last post by:
Hi everyone. I've been working with VB6 for a while now, I'm feeling pretty damn confortable with it, but find myself wondering about VB.NET and web applications. So I thought I'd get my feet wet. Well - let me tell ya - there's a whole lotta stuff that I need to teach myself. I have a whole slew of questions - to many and propbably just too basic to go into here - so I am hoping that someone out there can suggest a book that I can pick...
7
1833
by: Victor S. | last post by:
1. What is System.Windows.Forms.VisualStyles.TextMetricsCharacterSet good for? 2. Are the Indic scripts supported? Are all supported scripts fully supported? (for printing and fine measuring) Is the printing done by GDI++ without using Unicribe? 3. Is the Text.Encoder/Decoder provided by the OS or by the Framework?
1
1593
by: E.T. Grey | last post by:
Hi All, Despite spending the past six to seven hours perusing the docs on the mySQl site, I still have questions unanswered, and have been unable to get any help. I am familiar with Sybase, some Oracle and PostgreSQL - but the mySQL SQL seems a bit "non-standard". I would be very grateful for any help I get in answering these questions: Stored procedures
7
1764
by: alternativa | last post by:
Hello, I have a few questions concerning classes. 1) Why some people use default constructos, i.e constructors with no parameters? To me it doesn't make any sense, is there something I should know? For example, I'd declare a class in a following way: class Sample { int number; string title;
14
4117
by: shamirza | last post by:
Question Do ActiveX DLLs made in VB still need the VB runtimes on the machine? ________________________________________ Answer In a word, Yes. Visual Basic does not support what is known as "Static
17
3555
by: Jess | last post by:
Hello, If I have a class that has virtual but non-pure declarations, like class A{ virtual void f(); }; Then is A still an abstract class? Do I have to have "virtual void f() = 0;" instead? I think declaring a function as "=0" is the same
5
6762
by: jcolino | last post by:
Hi, I usually get stuck with one of two questions that keep coming up. Perhaps some of you brilliant people can shed some light... 1. How to do use if statements in load commands (I usually need this in the task center): if (select count(*) from mytable 1000) then load from file
0
2991
by: copx | last post by:
Restrict keyword questions How far does the guarantee that an object is not accessed through another pointer go? I mean, all examples I have seen are simple stuff like: int f (int *restrict x, int *restrict y) { *x = 0; *y = 1; return *x;
5
1753
by: Saeed Amrollahi | last post by:
Dear all Hi I am Saeed Amrollahi. I write C++ programs using VC++ 2005 CLR/CLI. I have two problems: 1. How to declare/define and use global ref class objects? For example for database connection/communication, I usually define a class called DBBroker, When I used MFC, DBBrk wraped the Recordset/ODBC facilities and now it wraps the ADO.Net facilities:
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9597
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10620
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10369
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10372
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5682
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3851
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.