Solved

API Call Requires Null

Posted on 2003-10-30
32
323 Views
Last Modified: 2010-05-01
How do you send a null value to an API call in VB? Its got to be the same as if I were to type null in C++....  whenever I use VBnull it doesn't work, whenever I set a variant value to null that does work either.... Thanks
0
Comment
Question by:sk33v3
32 Comments
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 9655851
try vbNullString ?
0
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 9655855
Hi,

use vbNullPointer for long pointers
define

const NULL_STR_POINTER = &0;
and use for pointer to string that must be null.

-FA
0
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 9655865
Sorry

use vbNullString for string type. define NULL_LNG_PTR = &0 and use for long type.

-FA
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 9

Author Comment

by:sk33v3
ID: 9655890
when I try to declare that null_lng_ptr it adds an O

Public Const NULL_LNG_PTR = &O0
0
 

Expert Comment

by:micask8
ID: 9655933
The O means that the number is octal number. If you need a hexadesimal number write &H0. I'm not sure if it really matters whether you use octal or hexadesimal number...
0
 
LVL 9

Author Comment

by:sk33v3
ID: 9655958
neither of the 2 work right, it doesn't return what the C++ equivalent of Null for a long is.
0
 
LVL 3

Expert Comment

by:gafoorgk
ID: 9655985
u can send api null as &0. like following;

SendMessage(<hwnd>, <message_code>, <wparam>, ByVal 0&)
0
 
LVL 9

Author Comment

by:sk33v3
ID: 9655992
what goes in the hwnd, message_code and wparam?
0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9656065
Normally, we use &0 as null for long.
For example, the SendMessage(me.hwnd, BN_CLICKED, 0&, 0&)
The hwnd can be any window handler for example

dim hwnd as object
hwnd = findwindow("classname", "windowcaption")

If the above cannot work, then try to change long to any like
Declare Function FindClose Lib "kernel32" Alias "FindClose" (ByVal hFindFile As Long) As Long
to
Declare Function FindClose Lib "kernel32" Alias "FindClose" (ByVal hFindFile As any) As Long

For all API reference:
http://www.mentalis.org/

Thanks,
~ fantasy ~
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 9656176
You can also try vbNull
0
 
LVL 1

Expert Comment

by:vkaushik
ID: 9656275
try with the null character ' '. In  VB use the returned value from Chr$(0) to create this null character
0
 
LVL 9

Expert Comment

by:_ys_
ID: 9656676
If your API declaration is for a string parameter and you want to pass null, I'm surprised that vbNullString doesn't do the job.

Another method is to rewrite the declare statement. e.g. FindWindow could be rewritten from

Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

to

Declare Function FindWindow Lib "user32" Alias "FindWindowA" (lpClassName As Long, ByVal lpWindowName As String) As Long

The second would allow for use of the 0& long constant just about everyone else has mentioned.

Dim hWnd As Long
hWnd = FindWindow (0&, "whatever")
0
 
LVL 9

Expert Comment

by:_ys_
ID: 9656677
Sorry, that sould've been ByVal

hWnd = FindWindow (ByVal 0&, "whatever")
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 9656759
Your API function (SendMessage I take it) will work with 0& for long and vbNullString for string, as said. It's probably the message you're sending that's failing. Check the return value of the function to see.
0
 
LVL 1

Expert Comment

by:vkaushik
ID: 9656804
Yes it might be the message is failing
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9657219
sk33v3, what is the api function/declaration that you are using (in first)?
0
 
LVL 9

Author Comment

by:sk33v3
ID: 9659303
Well I can't give you the Actual DLL Call but I can make a mock up of what it looks like.

MyAPICall(LngHandle, TypeOfOption , NULL_LNG_PTR, NULL_LNG_PTR)

Any Ideas?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9659385
I don't want dll, just what declaration are you using.
Is it a standard dll that comes with Microsoft products?, if no, do you know if that dll accept callings from VB?, just remember that for dlls used by VB, they have to follow _stdcall calling convention.

0
 
LVL 9

Author Comment

by:sk33v3
ID: 9659634
Public Declare Function StartCommunication Lib "MyCom" (ByRef lpdwHandle As Long, ByVal dwPortType As Long, ByVal PortAddress As Long, lpbReserved As Long) As Long
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9660322
All parameters appears to just longs, so passing 0& as last parameter should be enought if it doesn't waits for a pointer to a function (like EnumChildWindows api in example)
0
 
LVL 9

Author Comment

by:sk33v3
ID: 9660849
well I was told the error I was getting from it was because I wasn't passing Null to it properly, All the examples they have are for C++ only and they use the null constant....
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 9661131
Could you post the C++ example used? You might need to pass a pointer to a buffered string which is null-terminated. Blind guess, however. Have no clue on how the function is supposed to handle it's parameters.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 9664123
Please maintain your many old open questions:

1 09/19/2003 500 RealBasic  Unlocked Macintosh Programming
2 09/26/2003 500 Power point(PPT) to Quicktime(mov) Conve...  Unlocked Microsoft Office
3 10/12/2003 500 Print Screen  Unlocked Visual Basic
4 01/23/2003 50 Network Trouble shooting utility  Unlocked Networking
5 08/27/2003 250 PHP With IIS?  Unlocked Internet Information Server
6 10/06/2003 500 RB, What is wrong with this?  Unlocked Macintosh Programming
7 10/07/2003 250 Windows App to Mac App. Registry?  Unlocked Macintosh Programming

Thanks,
Anthony
0
 
LVL 9

Author Comment

by:sk33v3
ID: 9805295
Well what we ended up doing was making the Interface into the component in C++ and referencing it from VB.... That fixed it. I am going to request that this question be deleted. Thanks.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 9805944
Thank you for taking care of your open questions.  However, I believe you overlooked this open question:
http://www.experts-exchange.com/Programming/Programming_Platforms/Mac_Prog/Q_20758795.html

In order to close this question, see the following:
Request a refund because you answered your own question (Refund/PAQ) http://www.experts-exchange.com/help/closing.jsp#4
Request a refund because no one answered your question (Delete) http://www.experts-exchange.com/help/closing.jsp#5

Thanks,
Anthony
0
 
LVL 27

Accepted Solution

by:
Ark earned 500 total points
ID: 9970140
MyAPICall(LngHandle, TypeOfOption , ByVal 0&, ByVal 0&)

0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9972645
WOW!, THE BOY is back in town!!
Hi!
:)
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9972655
"Mr. Ark, ...welcome back, we...missed you"
0
 
LVL 27

Expert Comment

by:Ark
ID: 9976132
Hello Richie and all experts! Finally I've defend my PhD degree on wednesday and now I'm back :)
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA color chart bars 12 84
VB6 Compile Compatibility Issue 4 102
Adding to a VBA? 6 69
VB 6 error 5 in windows 10 but not in XP 7 55
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now